CIT 590 Assignment 8: Write a Game
  Fall 2016, David Matuszek

Purposes of this assignment

General idea of the assignment

Write a game in which animation is used.

Details

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?

2. Follow the KISS rule (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 if you wish, 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 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.

If you write a function void keyPressed(), it will be automatically called each time a key is pressed. Remember that keys repeat if you hold them down for too long. If you write a function void mousePressed(), it will be automatically called each time a mouse button is pressed.You can tell where the mouse (pointer) is by accessing the predefined mouseX and mouseY integer variables.

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 many of the things you are likely to need. See the Processing reference for anything more.

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

ArrayList<Point> points = new ArrayList<Point>();
String keys = ""; void setup() { size(300, 300); } void draw() { background(255 - mouseX, 127, 255 - mouseY); putTextAtTop(); drawAllTheOldPoints(); if (mousePressed) { makeAnotherPoint(); } if (keyPressed && key == CODED) { drawATemporaryLine(); } } void keyPressed() { if (key != CODED) { keys += key; } } void putTextAtTop() { fill(0); 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, meaning that the ball "chases" the mouse pointer rather than exactly tracking it. If you want to use easing in your game, here's how.

Grading

Your program should work. Zip your file or files together with a readme.txt file. The readme.txt file should describe:

Due date

Turn your assignment in  to Canvas by 11:59pm Tuesday, November 1.