INQ241A
Mobile Apps

Activity 7

Sprites

  1. Create a random sprite animation. The sprite should start in a random location anywhere in the window. Run the script multiple times to verify that the sprite can start anywhere on the screen. The sprite should move in a random direction with a random speed. Run the script multiple times to verify that the sprite can move in any direction.

  2. The sprite only moves for a little bit before it moves off of the screen forever. Modify the random sprite animation so that the sprite bounces off all of the edges of the screen and therefore never leaves the screen. Note, the sprite should not have a new random velocity every time it bounces.

    To create the bounce animation, change the velocity of the sprite, so it looks like it bounced, if the sprite has reached the edge of the screen. The sprite’s velocity after it hits the edge of screen should be calculated so that the direction, but not the speed of the sprite changes. The calculation is different for each edge of the screen. For example, if the sprite hits the bottom of the screen:

    bounce_illustration
    The sprite’s x speed before hitting the edge and after hitting the edge are the same. The sprite’s y speed changes, but note that the absolute value of the sprite’s y speed before and after hitting the edge are the same.

Submission

Please show your source code and run your scripts for the instructor or lab assistant.