Im working on my first game (pong :d), and i was wondering if this code for movement of my paddle is written good.
The movement works great in the game but i'm using alot of non-standard functions like kbhit etc, is there a way to make it more portable?
Code:
int control;
do{
draw_paddle(px,py,20);
control=getch();
while(px>73 && control == '4' ){
draw_paddle(px,py,20);
wait_for_retrace();
draw_paddle(px,py,0);
px--;
if(kbhit () ){
control = getch();
while(px<247 && control =='6' && !kbhit() ){
draw_paddle(px,py,20);
wait_for_retrace();
draw_paddle(px,py,0);
px++;
}
}
}
while(px<247 && control =='6'){
draw_paddle(px,py,20);
wait_for_retrace();
draw_paddle(px,py,0);
px++;
if(kbhit () ){
control = getch();
while(px>73 && control == '4' && !kbhit() ){
draw_paddle(px,py,20);
wait_for_retrace();
draw_paddle(px,py,0);
px--;
}
}
}
}
while( control != '7' );
I hope indentations are well, becaus i just changed all my tabs to spaces to post here (since tabs turn out very long on this board :s).
note: borders of gae are for x=60 and x=260, but as the draw_paddle function takes the middle of the paddle and starts drawing from there you have to do 160-(length_of_paddle)=247, same counts for the x=60 (just that you know ).