CS112
Assignment #13
Due: Friday May 1st
This assignment requires creating a new class called "sprite". The goal
is to have sprite objects, similar to the ones in Scratch, that move around
the screen and that the user can control using the arrow keys or the mouse.
It may be helpful to look back at the simple ball code on the course schedule
to get an idea for how the sprite should be coded.
The sprite class should have the following data members:
- An x and a y to store the location of the sprite. These should both
be floats.
- An x velocity and a y velocity that make the sprite move around
the screen.
The sprite class should also have the following functions (methods):
- A constructor that sets the initial position and velocity of the sprite.
- A function called display() that draws the sprite on the screen.
How the sprite looks is up to you. It's probably easiest to start with an
ellipse and make it fancier later.
- A function called update() that changes the position of the sprite based
on its velocity. If the sprite reaches a side of the window it should
either bounce off the side or "wrap" around to the other side of the window.
Which one it does is up to you, but this movement should be handled by the
update() function.
- A function called adjust_velocity() that takes two inputs and
changes the velocity of the sprite according to those two inputs.
The main program should do the following:
- Create a sprite object.
- In the draw() function repeatedly display() and update() the sprite
so that it moves around the screen.
- Use the keyPressed() function to get user input and control the sprite.
When the user presses a key use the adjust_velocity() function to change
the sprites velocity.
- How you handle erasing the window if up to you. You could use the
background() function to completely erase it or the rect() function
with a fill with an alpha value to partially erase it and have the sprite
leave a trail.
Extra Credit
- Create several sprites, only one of which is controlled by the user.
In this case the other sprites should have random starting postions
and/or random initial velocities.
- Use an image for the background and for the sprite.
- Create two different sprites that are controlled by different sets of keys.
Turn in: Save your project with the name [scratchname]Assignment13.
E.g. my project would be saved as
tsoule89Assignment13 (without the []'s). Zip up the entire
project folder - you can find it in your processing folder. Email the
zipped project as an
attachment to both TAs
Allen, Craig (alle7522@vandals.uidaho.edu); MacPhereson, Serendel (macp6269@vandals.uidaho.edu).
Make the subject of the email CS112Assignment13.