Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+13 votes
asked in CSC211_Winter2018 by (1 point)

1 Answer

+6 votes

Did you look at the slides?

If you are using a PC and your DrawingPanel for the game is named gamePanel,
gamePanel.isKeyDown("Left") returns true if the left arrow key was pressed. So

if (gamePanel.isKeyDown("Left") {
      xPursuer = xPursuer - 5;
}

would change the x coordinate of the pursuer (if that is your variable's name) 5 smaller so the next time the pursuer is drawn, it would be 5 pixels farther to the left.

It is similar for the other arrow keys.

On a Mac, use four lettered keys for the directions instead. So, if you use a for left

if (gamePanel.isKeyDown("a") {
      xPursuer = xPursuer - 5;
}
answered by (1 point)
edited by
...