CIT 591 Assignment 8: Write a Game
Fall 2014, David Matuszek

Purposes of this assignment

General idea of the assignment

Write a game.


This is a very open-ended assignment. I'll just put down a few rules.

1. Try to be original.

Please don't write yet another Tetris or Breakout clone.

If being original is not your thing, here's a simple trick that might help. Pick a game, preferably something simple, and just try to make some changes to it. Tic-tac-toe? Maybe a bigger grid, with four in a row, would work. Breakout? Maybe put the bricks somewhere other than at the top?

Brainstorming with your partner is almost certainly a good idea. After all, you have to at least agree on what to do. (And if you find it hard to agree, settle on the simpler alternative!)

2. KISS (Keep It Simple, Stupid)

Programmers are always optimistic, and programming is always harder and takes longer than expected. More "real life" projects fail due to overly ambitious goals than to any other single factor.

Decide and write down (1) what you want your game to be like, and (2) the absolute minimum you can do toward making a playable version of your desired game. Put this in a readme.txt file. Then get the absolute minimum to work. Then, if there is any time left, work on adding all those missing features to your game--but be sure to keep a working copy of your game at every step.

3. Don't make the computer think.

In games like tic-tac-toe or checkers, the computer has to decide the next move. Don't go there, the water is too deep and the currents are strong. Stick with games where you control the movement of something, and the computer just reacts (or doesn't react) to those movements.

Stuff you need to know

You will need a void setup() method. Here's where you set the size of the window, call frameRate, and do any other necessary initializations.

You will need a void draw() method. This method will be automatically called some number of times a second, as set by the frame rate. All drawing must be done in the draw method, or in methods called (directly or indirectly) from the draw method--drawing commands anywhere else probably won't do anything. Start with a call to background, otherwise your drawings will "pile up" on top of one another.

You can tell where the mouse (pointer) is by accessing the predefined mouseX and mouseY integer variables.

You can tell if a key has been pressed by checking the keyPressed boolean variable; the key variable holds the most recently pressed key. If key == CODED, it's a special key, like an arrow key, and the keyCode variable holds the numeric code for it.

You can write a function void keyPressed() that will be automatically called each time a key is pressed. Remember that keys repeat if you hold them down for too long.

Processing isn't going to automatically remember what you did. Anything you want to keep from one frame to the next, you have to explicitly save in something that will be redrawn next time.

The following code has samples of everything you are likely to need.

import java.awt.Point;
import java.util.ArrayList;

ArrayList points = new ArrayList();
String keys = "";

void setup() {
  size(300, 300);

void draw() {
  background(255 - mouseX, 127, 255 - mouseY);
  if (mousePressed) {
  if (keyPressed && key == CODED) {

void keyPressed() {
  if (key != CODED) {
    keys += key;

void putTextAtTop() {
  text("mouseX = " + mouseX + ", mouseY = " + mouseY, 20, 20);
  text(keys, 20, 35);
  fill(100, 200, 255);

void drawAllTheOldPoints() {
  for (Point p : points) {
    ellipse(p.x, p.y, 10, 10);

void makeAnotherPoint() {
  fill(255, 0, 0);
  ellipse(mouseX, mouseY, 10, 10);
  points.add(new Point(mouseX, mouseY));

void drawATemporaryLine() {
  if (keyCode == LEFT) {
      line (mouseX - 100, mouseY, mouseX, mouseY);
    } else if (keyCode == RIGHT) {
      line (mouseX, mouseY, mouseX + 100, mouseY);
    } else if (keyCode == UP) {
      line (mouseX, mouseY, mouseX, mouseY - 100);
    } else if (keyCode == DOWN) {
      line (mouseX, mouseY, mouseX, mouseY + 100);
    } else {
      text(keyCode, mouseX, mouseY);
My DodgeEm game is a simple example you might also get some ideas from. Movement of my ball uses "easing," and if you want to do that, here's how.


Your program should work. Zip your file or files together with a readme.txt file for your description of the minimum and desired game features, and anything else you want to say about the program.

Due date

Turn your assignment in to Canvas before 6am Friday, October 31.