We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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:
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
Answers
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()
andkeyReleased()
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?