CS 0447 – Project 2: Centipede

Due: Sunday, March 31, 2013

Description

Many video games of the past were programmed directly in assembly language. In this project, we’ll be taking an early Atari video game, Centipede, and making a version in MIPS under MARS.

If you are unfamiliar with the game, you might want to look at the Wikipedia article, http://en.wikipedia.org/wiki/Centipede_%28video_game%29  or find a modern adaptation (or emulated old version) to try it.

The basics are that a many-segmented centipede starts at the top of the screen and marches back and forth, dropping lower over time. Your character is at the bottom of the screen, firing bullets upwards. In between you and the centipede are mushrooms that block your shots. Mushrooms are destroyed when shot.

When your shot hits the centipede, if you shot it in the head or tail (first or last segment), the segment turns into a mushroom and the now shorter centipede continues on. If you shoot it in the middle, the hit segment turns into a mushroom. The centipede now becomes two segments, and the game continues.

If the centipede makes it to the bottom of the screen, the game is over.

Tools

After your first project, you might be wondering how to get MARS to make something as awesome as a video game. For this, we can thank several graduate students and Dr. Childers for a modified version of MARS that contains a LED display which we can control. The display is an array of pixels (64 x 64) and each LED can be one of 4 colors: off (black), red, green, or yellow/orange.

In later courses, we’ll discuss two strategies for talking to I/O devices from machine instructions. In this case, the pixel display is memory-mapped. This means that a byte in our address space is reserved for each pixel, and that the content of that array is reflected in the output of our display. Learning about the memory-mapped I/O is not the core of the project and so we provide get and set methods for manipulating a pixel at a specified location.

Additionally, the LED display has support for a key pad. It can handle either button presses on the dialog box or you can use the keys on your keyboard (WASD).

You will need to download this special modified version of MARS from the class webpage in order to do this project.

When you wish to use it, go into the tools menu and select “Keypad and LED Display Simulator”. In the window that appears, click “Connect to MIPS”. Then run the program in MARS using the green play button.

Game Requirements

  1. A centipede is initially 10 red LEDs. It starts at the upper left corner (0,0) of the LED display, heading right.
  2. Initially, 10 mushrooms will be randomly placed (not overlapping the centipede). A mushroom will be a single green LED.
  3. When the progress of a centipede is blocked by the edge of the screen or a mushroom, it will drop down a row and reverse direction.
    1. This means that rows 0, 2, 4, … have a centipede moving right and 1, 3, 5, … have a centipede moving left.
  4. To animate movement, you will turn on an LED in front of the head and turn off an LED (set its color to black) at the tail.
  5. You will update the position of the centipede and a fired shot every 200 milliseconds. The game should speed up by 20 milliseconds each round.
    1. You can use syscall 32 in MARS to sleep for a specified number of milliseconds.
  6. Each destroyed mushroom counts for one point.
  7. Each destroyed centipede segment counts for five points.
  8. If you destroy each every section of the original 10 segment centipede, award 100 points and spawn a new centipede at (0,0). A new round begins with the existing mushroom positions, plus 5 new randomly placed mushrooms.
  9. Your character is shown below. Each keypress moves it one space left or right and stops when either side hits a wall. Pressing Up shoots a shot. Only two shots may be on the screen at a time.
  10. If the centipede makes it to row 60, the game is over.
  11. When the game ends, the score is printed using the print string syscall.
  12. You must use functions in this project. At minimum you need a function that updates the centipedes’ positions, one that updates the shot positions, and one that updates the player position. You may use others, but those three are required.
  13. Functions must follow the MIPS calling convention. Use the stack for spills. Use the $a0-$a3 registers for arguments and $v0-$v1 for return values.

Centipede Motion Example

A centipede of length 4 heading right, hits a mushroom and must drop a row and reverse direction:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Frame 1: Heading right

 

Frame 2: dropping down

 

Frame 3: left and right

 

Frame 4

Your character

Your character is a yellow triangle as shown below. Each shot comes from the center upwards and advances 1 row each time step. A shot is a single yellow LED.

 

 

 

 

 

 

Hints

Keeping track of all of this data is part of the challenge. One approach is to borrow a design pattern called Model/View/Controller (MVC). A model of the game is held in memory, most likely as an array. Each position gives you information about what the state of the game is, for instance, a mushroom might be represented by the number 1 being at that coordinate. You can then check the model each time something happens. This is the controller’s job. It’s some code that updates the model with the changes of the game. It also updates the view: the picture on the screen. For example, when a shot has moved, you change its color to black and draw it in the new place.

You may notice that the state of the game is already in the LEDs that are on or off. You can reuse them, but if you do, I’d suggest making a queue for each centipede (there can’t be more than 6 on the screen since a shot piece turns into a mushroom). Remove the position of the tail and add it in front of the head each time step.

Submission

Create a zip file of your source code and a README.txt text file that has your name, your Pitt username and any notes for the TA to help with grading.

Name the file USERNAME-project2.zip

You will upload the zip file to the directory specified below using a program like FileZilla or WinSCP:

Server: unixs.cis.pitt.edu

Login: Your Pitt username (email before @)/Your password

For the Monday section:

Directory: /afs/pitt.edu/home/j/r/jrmst106/submit/447/monday/

For the Tuesday section:

Directory: /afs/pitt.edu/home/j/r/jrmst106/submit/447/tuesday/