Download the following files:
Make the balloon move around inside the game window and bounce off the edges.
Idea: Every run through the game loop puts a new picture onto the screen. To give a viewer the impression that the balloon is moving, its position needs to change a tiny little bit each time we run through the game loop.
Define two variables called balloon_vx and balloon_vy to refer to the balloon's speed along the x axis and the balloon's speed along the y axis respectively. Assign values to these variables. The values stand for how many pixels the balloon will move in each run through the game loop. What are good values? How fast will the balloon move if you assign the value 10 to them? How about the value 0.1?
Now add code that changes the balloon's position by adding balloon_vx to balloon_x (and balloon_vy to balloon_y) in each run through the game loop.
Your balloon should now move across the game window. When it reaches the edge of the window it disappears.
Idea: Whenever the balloon's position gets to be outside of the game window, we want to do two things: 1) Place it back in the game window and 2) switch the direction it is moving into.
Add code that checks in each run through the game loop whether the balloon's position is outside of the game window. (Hint: there are four ways in which the balloon can leave the game window.)
If you find that the balloon has left the game window, assign a new value to its position variable such that it is back inside the game window. Also change the direction of its movement. (Hint: this can be done by multiplying balloon_vx or balloon_vy - whichever is appropriate - with -1.)