So basically im trying to work on a single player pong game ...
What im struggling with the logic behind the movement of the paddle..
If i just keep pressing the one direction, say a ... that moves fine, though the issue arises when i than press z, rather than moving down just one space, it moves far more than that...
Code:
/* a = up, z = down */
int c, temp, moveA, moveZ;
temp = 1;
moveA, moveZ = 5;
set_up();
while ( ( c = getchar()) != 'q' ){
if ( c == 'a' ){
clear();
attron(A_REVERSE);
move(0,LEFT_EDGE+20);
addstr(" Single Player Pong ");
move(2,LEFT_EDGE+2);
addstr(" INSTRUCTIONS: (move paddle) A - up, Z - down (quit) - q ");
move(TOP_ROW-1,LEFT_EDGE-1);
hline(' ', LEFT_EDGE + 53); /* Top Border */
vline(' ', TOP_ROW + 13); /* Left Side */
move(BOT_ROW+1,LEFT_EDGE); /* Bottom Border */
hline(' ', LEFT_EDGE + 52);
moveA = (TOP_ROW + 5)-temp;
move(moveA,RIGHT_EDGE+1);
vline(' ', (BOT_ROW-TOP_ROW)/3);
attroff(A_REVERSE);
getch();
if ( c == 'a' ) {
temp++;
}
else {
moveA = moveA +1;
}
}
else if ( c == 'z' ){
clear();
attron(A_REVERSE);
move(0,LEFT_EDGE+20);
addstr(" Single Player Pong ");
move(2,LEFT_EDGE+2);
addstr(" INSTRUCTIONS: (move paddle) A - up, Z - down (quit) - q ");
move(TOP_ROW-1,LEFT_EDGE-1);
hline(' ', LEFT_EDGE + 53); /* Top Border */
vline(' ', TOP_ROW + 13); /* Left Side */
move(BOT_ROW+1,LEFT_EDGE); /* Bottom Border */
hline(' ', LEFT_EDGE + 52);
moveZ = (TOP_ROW + 5)+ temp;
move(moveZ,RIGHT_EDGE+1);
vline(' ', (BOT_ROW-TOP_ROW)/3);
attroff(A_REVERSE);
getch();
if ( c == 'z' ){
temp++;
}
else{
moveZ = moveZ -1;
}
}