CPSC170A Assignment 3
Sprites

February 22nd, 2013

Sprites are the two dimensional images that are combined to make video games. In a previous assignment both the ball and the paddle were sprites. In this assignment you will create a game that uses classes that represent sprites to create a simple platform game.

Details

The game should consist of a user controlled sprite and one stationary goal sprite. The player's sprite can move laterally and jump. If the player hits the the goal sprite, the program should should display a congratulatory message. You can use the images in the tar file sprites.zip. You can also use a clean version of the UpdatingWindow class, but you are not required to.

You will have to register your sprites using turtles registershape method, which takes as a parameter a string that is the filename of the image you want to use. You can then set your turtle's shape using the shape method, which takes the same string you passed to register shape.

The sprite class will need an instance variable for the for the sprite's shape (stored as a string). The sprite class should also have a function that returns whether two sprites are intersecting. You should use bounding boxes to determine whether two shapes are intersecting. You will have to store the sizes of the images somewhere within your code.

The player class should extend the sprite class and have an instance variable to represent the direction it is facing. In order to animate the player moving left and right the player class will need two attributes for the shapes, one for facing each direction, so it will also need a second shape instance variable.

The player class should also have an update function that is called every frame of animation. The update function should have parameters for specifying keyboard input and for the canvas. The function should update both the player's state instance variable and the canvas based on the keyboard input. For example, if the left arrow key is pressed and the player is facing right, the player's image in the canvas should be removed and an image of the player facing left should be added. Also the location of the player's image in the canvas should be moved to the left and the player's direction instance variable should be changed to reflect that the player is facing left.

To make the player jump when the up arrow key is pressed, the player will need a y velocity instance variable. When the player is not jumping the y velocity variable should be zero. When the player begins a jump, the y velocity should be set to to a negative amount (so the player moves up). Every subsequent time that the update function is called and the player is still jumping, the upward velocity should be increased by a small fixed amount. This will cause the player sprite to slow until it reaches the apex of it's jump and then speed up until it hits the ground. When the player reaches the ground it's y velocity should be set to zero.

Submission: Submit your code as a zip file with your name as the zip file name on the course Inquire site by Friday, Feb. 22nd 2013.

Class Structure

On paper, write down your class hierarchy. It should include the classes you intend to create, the attributes of those classes, and the methods those classes will implement.

For each attribute, write what data types you are storing in them, and why you are doing so. For each method, write the Pre and Post conditions for the method.

Submission: Submit on paper, at the beginning of class on Wednesday, Feb. 13th 2013.

Extra

Multiple Goals: Create a list of goal sprites. When a player reaches a goal it disappears and when they are all gone, the player wins.

Movable Goals: Create a subclass of the sprite class for a moving goal. The goal subclass will need instance data for the direction it is moving, that changes periodically so that the goal doesn't move off of the window.

Enemies: Create a subclass of the sprite class for an enemy. The enemy should move in a regular pattern. If the player hits the top of the enemy the enemy disappears. If the player hits the enemy anywhere else, the player loses.

Level Editor: Write a separate program that will act as a level editor/creator. The level editor should allow the user to click on the playable area, and add some sort of platform the sprite can interact with. This program should write this level to a file, and your main program should be able to read that file in and display the level.