SpaceInvadersRemake

I am having difficulty determining the correct method to figure out whether or not the character is moving and which direction. I would like to move the ship left or right based upon the key that they press, but without stopping or pausing the loop/game.
[
int main()
{
int startChoice;
int difficulty = 1;
//1=easy, 2=medium, 3=hard


//Welcome and prompt
cout << "Welcome to my remake of the classic arcade game Space Invaders!" << endl;
cout << "Please choose an option below!" << endl;

//Choices
cout << "1. Start Game" << endl;
cout << "2. Difficulty" << endl;
cout << "3. Quit" << endl;
cin >> startChoice;

switch (startChoice)
{
case 1:
//The Game

break;
case 2:
//Difficulty options
system("cls");
cout << "Which difficulty would you like to play on? The default difficulty is easy." << endl;
cout << "1. Easy" << endl;
cout << "2. Medium" << endl;
cout << "3. Hard" << endl;
break;
case 3:
//Exit
return 0;
break;
}

}
]
Last edited on
just track it. Wherever you check for user input, if you get some, update a variable. When your game processes the input, do the move and clear it (to the not-moving input code, whatever that is). If your code is instead event driven, you process immediately upon input, but you don't seem to be doing that here.

If your game is pausing for input, you have 2 choices. You can thread the input, so that the wait for input is distinct from the game loop, or you can use a nonstandard tool like 'keypressed' or whatever it is in windows API to see if there has been a hardware keyboard press and if so, handle it, if not, do nothing. I think you can also do this approach with some sort of peek @ cin buffer, and then if data on it read the buffer type logic.

Last edited on
Registered users can post here. Sign in or register to post.