Modify coordinate variables (if arrow keys are pressed)
Listing 4 uses four numeric symbolic constants to check the state of each of the arrow keys once during each iteration of the while loop.
Listing 4. Modify coordinate variables if arrow keys are pressed.
if (key[KEY_UP]) --y; else if (key[KEY_DOWN]) ++y; else if (key[KEY_RIGHT]) ++x; else if (key[KEY_LEFT]) --x; |