6B – MORE EXAMPLES OF ANIMATION
(ADVANCED) EXAMPLE 1 - ASTEROIDS In
this example, we animate a circle to move diagonally upwards and to the right. However, if the circle reaches the top it
instantly appears at the bottom. If it
reaches the right, it instantly appear on the left. This creates the affect used by Asteroids
in the famous game called Asteroids! The
implementation used is interesting. Both the x and y coordinate of the circle
follow this logic:
This
is what a CircularCounter class does. So, we implemented this using a CircularCounter object for each coordinate.
EXAMPLE 2 – BOUNCING BALL In this example, we will make a circle
bounce around the screen. Moving
either horizontally or vertically involves the same logic: ·
Move
in the current direction until we are at the end, then move into the opposite
direction until we reach the end and then move in the initial direction … We can implement this effect using a BounceCounter class.
A BounceCounter is simply a counter that
holds a value. Instead of incrementing
and decrementing the counter, we simply tell it to go to the next value. It knows if that means to increase or to
decrease.
|
||||||
|
||||||
|