Hello
I got problem with my main game loop. My game is a puzzle game which look like bejeweled, just change diamond to the number. My problem is that I cannot move the number down to the board when the game start. I know my problem is because of the while (LoopGDK()). It could not update the motion. The sprite just appear and move a little then stop. When I try to not use the game() function and call the spriteDown() function directly in the while (LoopGDK()), it works perfectly. However, if I choose that way, I cannot create the game menu and control the game state. Someone please help me
Here is my code
#include "DarkGDK.h"
#include <vector>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include "Board.h"
enum eMode { eGameMenu , eGameReset, eGamePlay , eGameWin , eGameOver };
eMode g_eGameMode = eGameMenu;
void ButtonHandle();
void spriteDown();
void game ( Board &b);
void gameMenu ( );
void gameReset( void);
void gamePlay ( Board &b);
void gameWin( void );
void gameOver ( void );
// the main entry point for the application is this function
void DarkGDK ( )
{
dbSyncOn();
dbSyncRate(60);
dbDisableEscapeKey ( );
dbRandomize ( dbTimer ( ) );
Board b;
dbLoadImage("buttonPlay.png",1);
dbLoadImage("buttonQuit.png",2);
dbLoadImage("buttonPlayRollOver.png", 3);
dbLoadImage("buttonQuitRollOver.png", 4);
while ( LoopGDK ( ) )
{
game(b);
dbSync ( );
}
return;
}
void game ( Board &b)
{
switch ( g_eGameMode )
{
case eGameMenu:
gameMenu(); break;
case eGameReset:
gameReset(); break;
case eGamePlay:
gamePlay(b); break;
case eGameWin:
gameWin(); break;
case eGameOver:
gameOver(); break;
}
}
void gameMenu ( )
{
dbSyncOn();
dbSprite(1,225,225, 1);
dbSprite(2,225,325, 2);
ButtonHandle();
dbSync();
}
void gameReset ( void)
{}
void gamePlay ( Board &b)
{
dbSyncOn();
bool check = b.checkExist();
if (check == true)
{
b.printBoard();
spriteDown();
}
while (check == false)
{
b.createNewBoard();
check = b.checkExist();
b.printBoard();
spriteDown();
}
dbLoadBitmap("game_frame2.png");
dbSync();
}
void gameWin ( void)
{}
void gameOver ( void)
{}
void ButtonHandle()
{
if ((dbMouseX() > 230) && (dbMouseX() < 220 + dbSpriteWidth(2)) && (dbMouseY() > 230) && (dbMouseY() < 230 + dbSpriteHeight(2)))
{
dbSprite(3,225,225, 3);
if (dbMouseClick() == 1)
{
g_eGameMode = eGamePlay;
for (int i = 1; i < 5; i++)
{
dbDeleteSprite(i);
dbDeleteImage(i);
}
}
}
else dbDeleteSprite(3);
if ((dbMouseX() > 230) && (dbMouseX() < 220 + dbSpriteWidth(3)) && (dbMouseY() > 330) && (dbMouseY() < 330 + dbSpriteHeight(3)))
{
dbSprite(4,225,325,4);
if (dbMouseClick() == 1)
{
for (int i = 1; i < 5; i++)
{
dbDeleteSprite(i);
dbDeleteImage(i);
}
exit(1);
}
}
else dbDeleteSprite(4);
}
void spriteDown()
{
for ( int i = 36; i >= 1; i-- )
{
if ((i >= 1) && (i <= 6))
{
dbMoveSprite ( i, -12.5 );
if ( dbSpriteY ( i ) > 10)
{
dbMoveSprite(i,15);
dbMoveSprite(i,-2.5);
}
}
else if ((i >= 7) && (i <= 12))
{
dbMoveSprite ( i, -12.5 );
if ( dbSpriteY ( i ) > 80 )
{
dbMoveSprite(i,15);
dbMoveSprite(i,-2.5);
}
}
else if ((i >= 13) && (i <= 18))
{
dbMoveSprite ( i, -12.5 );
if ( dbSpriteY ( i ) > 150 )
{
dbMoveSprite(i,15);
dbMoveSprite(i,-2.5);
}
}
else if ((i >= 19) && (i <= 24))
{
dbMoveSprite ( i, -12.5 );
if ( dbSpriteY ( i ) > 220 )
{
dbMoveSprite(i,15);
dbMoveSprite(i,-2.5);
}
}
else if ((i >= 25) && (i <= 30))
{
dbMoveSprite ( i, -12.5 );
if ( dbSpriteY ( i ) > 290 )
{
dbMoveSprite(i,15);
dbMoveSprite(i,-2.5);
}
}
else if ((i >= 31) && (i <= 36))
{
dbMoveSprite ( i, -12.5 );
if ( dbSpriteY ( i ) > 360 )
{
dbMoveSprite(i,15);
dbMoveSprite(i,-2.5);
}
}
}
}
Here is my problem
And here is what I want
Please help me. Thanks a lot