   First Game, C, Allegro, Pong, Help!
  Okay, so I'm working on my first game using the Allegro library and I'm really liking it so far, its pretty easy. What my problem is however, is once my paddles start moving, I can't get them to stop. Let me toss in a few functions and maybe someone can help me out. I'd like more of a hint to how to solve it rather than the exact source, thanks.EDIT: To be more specific, if I hit the left arrowkey one time and release it the paddle will continue to move left. I was working on using readkey() to check  if the key was still pressed but I failed at that.-Stephenvoid movepaddle(int num){int speed = paddles[num].speed;if (paddles[num].speed < 0){    paddles[num].x += speed;}if (paddles[num].speed > 0)    paddles[num].x += speed;//Setup Screen Boundaryif (paddles[num].x > SCREENW - 35){paddles[num].x = SCREENW - 35;paddles[num].speed = 0;}if (paddles[num].x < 35){paddles[num].x = 35;paddles[num].speed = 0;}}void getinput(){//Quitif (key[KEY_ESC]){gameover = 1;}    //Moveif (key[KEY_LEFT]){moveleft(0);}if (key[KEY_RIGHT]){    moveright(0);}rest(10);}void moveleft(int num){ paddles[num].speed--;    if (paddles[num].speed < -MAXSPEED)    {    paddles[num].speed = -MAXSPEED;    }}void moveright(int num){paddles[num].speed++;if (paddles[num].speed > MAXSPEED){paddles[num].speed = MAXSPEED;}}
  You change the speed of the paddle if the left(or right) arrow key is pressed, but you don't reset it to zero if they're not. No wonder it just keeps moving.   ;Quote:Original post by mikemanYou change the speed of the paddle if the left(or right) arrow key is pressed, but you don't reset it to zero if they're not. No wonder it just keeps moving.Yea, I figured that much out. However I just can't figure out how to check if the key is not pressed.Something like.. if (key[!KEY_LEFT]) { paddles[num].speed = 0; } wasn't working for me.   ;Quote:Original post by LempfaceQuote:Original post by mikemanYou change the speed of the paddle if the left(or right) arrow key is pressed, but you don't reset it to zero if they're not. No wonder it just keeps moving.Yea, I figured that much out. However I just can't figure out how to check if the key is not pressed.Something like.. if (key[!KEY_LEFT]) { paddles[num].speed = 0; } wasn't working for me.That doesn't check if the key with the value KEY_LEFT is not pressed. It checks if the key with the value (!KEY_LEFT) is pressed, which is nonsensical. What you mean to do was: if(!key[KEY_LEFT]). The best to do though would be just:if (key[KEY_LEFT]) moveleft(0);else if (key[KEY_RIGHT])moveright(0);else paddles[0].speed=0;   ;Quote:Original post by mikemanQuote:Original post by LempfaceQuote:Original post by mikemanYou change the speed of the paddle if the left(or right) arrow key is pressed, but you don't reset it to zero if they're not. No wonder it just keeps moving.Yea, I figured that much out. However I just can't figure out how to check if the key is not pressed.Something like.. if (key[!KEY_LEFT]) { paddles[num].speed = 0; } wasn't working for me.That doesn't check if the key with the value KEY_LEFT is not pressed. It checks if the key with the value (!KEY_LEFT) is pressed, which is nonsensical. What you mean to do was: if(!key[KEY_LEFT]). The best to do though would be just:if (key[KEY_LEFT]) moveleft(0);else if (key[KEY_RIGHT])moveright(0);else paddles[0].speed=0;*Smacks forehead* that is so much more simple than what I was trying to do. Bleh, thank you for your help.   ;  I ended up combining them all into one function, seemed more sensical.If anyone is interested.void getinput(int num){ //Pause if (key[KEY_SPACE]) { gamestart = 0; gametoggle = 0; } if (key[KEY_ESC])    {  gameover = 1;    }  //Start if (key[KEY_ENTER]) {if (gametoggle == 0){    gametoggle = 1;    gamestart = 1;} }  //Move if (key[KEY_LEFT]) {   paddles[num].dir = 1;   }  else if (key[KEY_RIGHT]) {  paddles[num].dir = 2;} else //Decel {  if (paddles[num].speed > 0)    { int n; for (n = paddles[num].speed; n > 0; n--)   {paddles[num].speed--;rest(5);   }   if (paddles[num].speed == 0)paddles[num].dir = 0;    } if (paddles[num].speed < 0)  {   int n;   for (n = paddles[num].speed; n < 0; n++)   {paddles[num].speed++;  }   if (paddles[num].speed == 0)paddles[num].dir = 0;  }} rest(5);}