Hi guys,
Working a dragon warrior type clone where the character is essentially in two states. The first one is a 2d world exploration state, and the other is a battle state.
When you enter the battle state, you turn the game into a turn based system, where the player presses a button, and you attack or use an item or whatever. Here is where my problem comes in. I am having a world of trouble dealing with the timer running at 30 fps and waiting for the player to make an input.
Here's the cleaned up main loop.
int main(int,char**){
while(running){
time_start=SDL_GetTicks();
state->handleInput();
state->handleLogic();
state->handleRender();
SDL_Flip(screen);
if(1000/FPS>(SDL_GetTicks()-time_start))
SDL_Delay(1000/FPS-(SDL_GetTicks()-time_start));
}
cleanResources();
return 0;
}
and here are the internals of my "handleLogic();" function in my "Battle" state.
int player_initiative=getRandom(1,10);
int monster_initiative=getRandom(1,10);
if(player_inititive>monster_initiative)
playerAttacks();
else
monsterAttacks();
It seems no matter how many booleans I set up, it either get's too ugly and I lose track of what's going on, or I can't stop the main loop.
Could someone please let me know how to solve this problem? That is turn the Battle state into a turn based system where the player has a chance to make an input.
Thanks,
Mike