Assignment 2 - Transformations, Loops, Logic
Due at 11.59pm, Sunday, October 9th.
- You are graded on the completeness, neatness, comments, and visual style of your final assignment
- All assignments are individual
- ZIP ALL SKETCH FOLDERS (not individual files) INTO ONE ZIP FILE
- Submit to WebCT before the deadline
There is no late policy for this course!
If you do not complete the assignment by the deadline, you will receive 0
You will be excused pending discussion with your TA
Create a separate sketch for each part of the assignment.
In this assignment, you will give life to your character by animating it. Then you will give your character the ability to move around screen.
Part 1 - Animation
Create a new character or use your character from Assignment 1.
Separate your character code and scene code into two methods.
Draw your character in at least two different states.
Add a parameter to your character method to keep track of which state it should display.
- Character method with parameter to control which state is displayed
- If / Else logic inside character method to display correct state
- Call the method with appropriate argument to animate the character from main draw method
- Example: drawMe( (frameCount / 10) % 2 ); //calls drawMe with argument 0 or 1, switches every 10 frames
Part 2 - Animation and Movement
Declare global variables to store: x, y, and velocity x, y for your character.
- float xPos, yPos, xVel, yVel;
- float xPosition, yPosition, xVelocity, yVelocity;
Initialize your character movement variables inside the setup method.
Choose your own starting location.
- xPos = random(width); //random x position inside the window
- xVel = random(-4, 4); //random velocity, moving either left or right
Move your character based on their given velocity.
Reverse direction when your character hits a wall.
- A character method with x, y position parameters
- 4 global variables to store character position and movement
- Position variables updated in the draw method
- Logic to handle a wall collision and reverse direction
- A call to the character method from the draw method using the updated position variables as arguments
Part 3 - Looping it up with Arrays
Choose a reasonable amount of characters for your scene (8-12).
Each character will have movement, wall collision, and animation.
- A global int to control the number of characters you will display
- Each character variable (xPos, yPos, ...) is an array of the same size
- Loop in setup to initialize all arrays with values
- Loop in draw to update all array values (update positions, wall collisions, ...)
- Call character draw method from inside the loop in the main draw method.
Tips and Tricks
- Look at the lecture notes (Arrays, Methods)
- Style counts! Make your animation look nice and choose appropriate velocities.
- Start next week after your lab! You will have most of what is necessary to complete the assignment.