Need help - Directions!

So I currently have code for a little uni project that I'm working on - a face moving down from the top middle of the screen and once it hits the bottom, it resets to the top. I need to alter the code to do the following:

  • If the face hits a wall, it will bounce back in the opposite direction. The face also needs to point in the direction the it is travelling in.
  • I need to be able to use W,A,S,D to control movement. Also when these key are pressed, the face will also change in the appropriate direction.

This is my code. If someone can please help me out, that would be highly appreciated.

Link to my code - https://pastebin.com/GC6CYeVC

Thanks, David

Tagged:

Answers

  • edited May 2017 Answer ✓

    A few hints:

    • How are you remembering which direction the face is moving?

    • Draw your face twice, once at its position and once height above its position. Move it back up by height when it y-position passes one and a half times the height.

    • What can you say about the position of the face when it hits a wall? Using that as a condition, what effect should happen then? How does the velocity change?

    • When it bounces, be sure to set the position to the boundary value too! This way your face won't get stuck.

    • Have you explored the keyPressed() and keyReleased() functions? Look them up in the reference! Using those, can you teach your sketch to know when certain keys are held down?

    • What changes when certain keys are held down?

    • How can you change how the face is drawn based on which way it is moving?

Sign In or Register to comment.