University of Calgary

centipede

A Centipede Game
source: Katrin Becker 2002
But hey, how often are you going to get an assignment that starts off with:
Go Play.
I really mean it too. The best way to get a feel for what your program is supposed to do and how it's supposed to work is to actually play the game for a while. On-line versions are linked below.

CONTENTS of THIS PAGE...
Introduction & Background (just below)
Description of Our Version  
The OBJECTS  
GameClass  ThingClass  GunClass  BugsClass  MissileClass
Summary of "Things on the Screen"  
Minimal Solution & A-B-C Requirements  
Testing and Marking  Bonuses
 
The Original Centipede (info)
A Java-Version you can play
See the Lab Notes for background information.
 

The following files will be available in the course directory:
~becker/Courses/233/A5
Centipede.Play (Documentation: game options)
easyCurses.help (Documentation: easycurses )
myRand.java
GameVal.java (constants, all static)
Point.java ( X and Y coordinates together in one object )
Thing.java ( the base class for the guys on the screen )
play (maybe: sample to run )
play.java (a sample main)
the easyCurses Classes:(window stuff)
easyCurses.class
trackerUtil.class
ucAnswer.class
ucError.class

Problem Statement:

Write a program to play a simple version of the old classic arcade game, "Centipede".
 
Background & History
Centipede, completed in 1981, was an Atari coin-operated game that swiftly won a wide following in the arcades. Apart from its smooth game play, Centipede was praised for its refreshing approach to screen colors and for its whimsical mushroom world.

The Creation of Centipede
Centipede was written by veteran Atari designer Ed Logg, who has become something of a legend in the world of video games, and a young game programmer who was credited with bringing a gentler touch to the world of video games with the enchanted mushroom patch.
Steve Calfee: "Ed Logg is the world's greatest games designer. He's done the most, the best games. His line up starts with Asteroids, which probably still is the biggest run we ever did. He's in [a long line of games]. He's kind of like Pete Rose; he has the most hits and he's also probably got the most strike outs. He just goes up to bat."
Remembrances from the Video Game Masters
The mushroom patch with its tenacious, never-say-die centipedes, bouncing Bugs, mushroom-laying fleas and transforming scorpions provided an imaginative leap for players, just as did the hoards of aliens in Tempest, the outer space adventures of Asteroids, the eerie battlefields of Battlezone and even the frightful scenarios of Missile Command. Of these times, and the games that emerged from Atari, Rich Adam said: "We were a young group of fun people who were sort of treading on untrodden territory. We were out exploring what technology could do to entertain adolescent minds, and we were adolescent minds."
In the early days of personal computers, before they became commonplace, and before sophisticated gaming programs were available for them, the arcades (and wherever else the coin-operated games were located) were the portals into these new fantasy worlds. And a river of quarters carried players into the electronic realms. Dan Pliskin described the coin-operated video game business as follows:"It was a wacky, extremely competitive business. I was there when coin-operated games were earning $8 billion in quarters a year. These games were outgrossing the record industry and the movie industry combined, in quarters! And when you looked at who was manufacturing these games, it was just a couple of Japanese companies and a few American companies. . . . There was incredible competition, all for kids' lunch and church money!
The quarters are still rolling in. Dan Plishkin continued: "People say that video games have already seen their heyday and business has definitely gone downhill. Maybe it has gone downhill. Maybe it's only $4 billion worth of quarters now. It's still one heck of an industry."
Popular from the Start
The prototype games were hand-built, wire-wrapped, one-of-a kinds that were created by the development team prior to ordering the circuit boards for the mass-produced versions. With just a single machine, people would come in at all hours of the night to play a new game. Dan Plishkin: "One of the things that kind of allowed everybody at Atari to have kind of a loose and enjoyable relationship was that management was kind of loose, too. An example of that happened with one of Howard Delman's games. I can't remember which one it was, but we sent the one and only prototype wire-wrapped version of Howie's game off to the AMOA (Amusement and Music Operators Association) show with strict orders not to sell it."
Of course the game was sold anyway, and a new prototype had to be assembled back at the labs. Dan Plishkin continued:"Several months later Howie gets a call from the person who bought this game. It had stopped collecting money and he wanted to know how to change the settings to make it play longer, or something, to see if it would earn more money. Howie had to tell the guy that if it ever collected any money at all, it was a miracle because it didn't have any coin routines at all. It had none, because we had wired it for free-play when we sent it to the AMOA show!"
The Great 25-Cent Escape
Especially in the early 1980s a great many newspaper and magazine articles were written about the meaning of and possible consequences of the wave of video games that seemed to allure so many kids, and adults, to the arcades. But at the heart of it might have been the promise of a quick escape into another world. Rich Adam: "I kind of figured out, maybe years after the fact, what I think the lure of video games is. It's because people have so little control over their lives. This is especially true with kids, but even adults often have little controlover the day-to-day part of their lives. You have to go to work. You don't get to control that much of your life. But for a quarter you can control this very complex machine. You can command it. For a quarter that's quite a bargain, to be able to do that for five minutes. . . . When you're good at a game it gives you an incredible sense of power over the whole environment."

Description of Our Version:
- no sound
- ASCII graphics
our game will consist of a WINDOW defined using "easycurses" and marks displayed in the window will be standard ASCII characters (size: 80W X 24H)
- graphics done using easycurses
- our "universe" is two dimensional
 
Since we do not yet have the experience to create a full-blown event-driven system our game will run as "snapshots in time". This is similar to the approach used in BATTLESHIP last term.
Game Basics:
The game consists of a screen, on which we 'draw' numerous Things. Some Things can move and others not. One of the Things is controllable by user input (we can make it move and shoot).

We will create an initial configuration at the start of the game consisting of a number of different Bugs. When we have destroyed them all, we win. If we get destroyed first, we loose.

 
- just as in BATTLESHIP each object will respond to the conditions as they were at the end of the previous time interval.
 
At each time interval:
- each object will make a move based on the screen as it was last
- Bugs continue to move
- we retrieve input from the user to tell us what the "Gun" (that's the player) should do (which could be null meaning don't move the Gun)
 
Running the Game:
- ( optional ) can have command line arguments for game "parameters":
- level of difficulty (affects # of "Mushrooms", Bugs, Gun's range, etc.)
- or could allow user to specify range, etc.
- with no arguments, it would be run like:
java Play
- can have a restart option or can simply require the user to quit and start again
 
(suggested) user input: (everyone but Gun moves EACH "turn")
q

= Quit

s

= Shoot

<blank>
= move everyone but Gun
o

= mOve and shoot

z

= move Gun left

.

= move right and shoot

/

= move Gun right

x

= move left and shoot

j
= make Gun Jump
(like hyperspace i.e. move
several squares at once)
u

= jUmp and shoot

The "names" of these commands need not be as specified - can use others (single-character Highly Recommended). Check the keyboard for conveniently located keys.
 
I would suggest implementing them in the above order (roughly). Do <blank> and 'q' first with just the Mushrooms to make sure they behave as they are supposed to. Do this before your Gun even exists.

The Objects:
The core of the program consists of a Game Class (known as the "AI" in games-writing circles) and a hierarchy of "things". You must use inheritance in this assignment. The "things" (Mushrooms, Bugs, Gun) are all derived from the same base class (Thing or some-such).
 
The Game Class
The Game Class will keep track of who is on the "board". This is "the AI". It is the part of the program that enforces the rules, keeps score, and acts as the go-between (between the user/main program and the "things" on the screen). The main program is a simple go-till-quit loop, and any time something needs to happen in the game, it's the "AI" that gets called to do it. There are many ways to implement this and the following description outlines only one. Different approaches will require different data and methods.
 
The Game Class needs to keep track of the following things:
DATA: some kind of list of the objects (Mushrooms, Bugs, me)
- this could be: Thing[] list = new Thing[100]; // an array containing pointers to the objects
- may need a count of things (a count for Mushrooms, Bugs, and maybe a total)
- may want to keep a pointer to the Gun (seperately)
- may want to keep a pointer to the "current shooter"
 
It needs to be able to get the following information:
- calculate the distance between two points
- determine if two objects have collided
- check for collisions with the Gun or Mushrooms (in this game, Bugs that collide with each other need not interfere with each other)
- move all objects to their next spot
- given a point the AI should be able to say "who's there" (a pointer to the object would do it; if there's no-one there it can return NULL)
 
Possible access functions:
return a pointer to the Gun
return a pointer to the Shooter
 
Possible forwarding functions:
- make the Gun move left
- make the Gun move right
- make the Gun jump
- make the Gun shoot
 
 
The Objects:The ThingClass
 
This is the base class for the major objects: Mushrooms, Bugs, Gun, (Missiles?)
 
It contains all the parts common to all:
DATA: Point origin (the centre or head of the object)
int status (whether it's alive, or dead, or what)
-in the guide status may have one of these values: ALIVE, EXPLODING, DYING, DEAD
- the usual "image" is printed when the thing is ALIVE
- when a thing is ALIVE and someone hits it - it is directed to explode
- when exploding there is a different "image" that gets drawn and the thing's status is changed to EXPLODING
- if it's status is EXPLODING then it gets changed to DYING
- if it's status is DYING it will be erased from the screen and its status changed to DEAD
- The effect seen on the screen as a result of this is that objects appear to explode and then will stay that way until the next "turn", when they disappear
int orientation (what direction is it headed? - one of: N, S, E, W, NW, SW, NE, SE)
int size (how many 'squares' across is it?)
int radius (an object of size 3 would probably have a radius 2)
 
There are 4 Utility Routines:
nextX, nextY, prevX, prevY
- these give the next value (row or column) but takes into account the current edges of the screen as well as the size of the object so we don't "draw outside the window"
- they also do wrap-around so if you are at the right edge and say nextX you get a point on the far left
- can base these on the "nextX" and "nextY" methods in cursWindow
 
Public Routines:
- some are abstract so they MUST be defined in the derived class.
 
- constructor and access functions are already defined and don't need to be redefined in the derived class (remember we still need to do the constructor for the derived class)
- base class constructor does nothing so you'll probably want to look after things in the derived class.
 
Others:
Move() - abstract move in current direction
- usually the thing will first be erased, then re-drawn depending on it's current status
Draw() - abstract draw a picture of me on the screen
Erase() - abstract get rid of the picture of me on the screen
Explode() - draw a picture of me exploding on the screen
  
The GunClass
origin : middle of screen at bottom
status : alive
orientation: facing north
size: 2?
radius : 1?
 
Note: if you have your image made of only one or two characters (a 'head' and a 'body') drawing it is simpler. Its orientation will not change.
 
- can move one square at a time
- can change direction
- can shoot in direction it's pointing ONLY (which is pretty much always North)
- can move E,W ONLY
 
Also need:
Jump (move 5-10 - you pick)
Move (LEFT or RIGHT)
Shoot() - BANG, BANG!
The Bugs Class (there are actually several kinds of Bugs)
origin : random, mostly
status : alive
orientation: varies
size: 2?
radius : 1?
 
- can move one square at a time initially.
- some can change direction.
- the direction it moves depends on which Bug it is (start with just one kind)
 
A Missile Class?
Some of the "things" can shoot, others leave mushroom (droppings?). There are many ways to handle this. To handle shooting, most include "plotting" some sort of missile path and then checking to see if there is anyone at any of the locations along the missile path (only the closest thing will get blown up unless your missile/laser is reeely strong). The missile path can easily be stored as an array of Points. It gets created when as thing shoots: the path is "plotted" and drawn, and then on the next 'turn' it can be erased. It too could be a thing. Once fired, it can look after plotting its own path: the thing that shot it keeps a pointer to a missile; if not NULL there is an active missile
A new missile would need to 'know':
- its range (set in constructor)
- its origin(set in constructor)
- its orientation (which direction it's going)(set in constructor)
- the endpath (the actual length of the path as opposed to the range - the actual path 'ends' when it hits something) - this value is calculated
- a flag that remembers if it hit something
- a pointer to the thing it hit
It needs to be able to:
plot the missile path
erase the missile path
say whether or not it hit something (access function)
say who it hit (access function)
 
If the missile is a proper sub-class of thing which is created by the Gun, then it basically has a life of it's own: it moves, maybe hits something, and dies. Once fired, the shooter no longer cares about it so it needn't keep track of it. This would make it behave more like a proper missile, whereas the other description above (which includes a path) is perhaps more like a laser.
Summary of "Things" on the Screen:
--
asst level
move?
direction
action
when shot
Mushrooms
C
no
---
obstacle
disappear
Gun
C
yes
E-W
move, and shoot
--
Bug: Scorpion
B
yes
E-W
mushrooms encountered are changed to poison mushrooms (which make the centipede drop)
disappear
Bug: Flea
B
yes
S
when < X mushrooms, it drops and leaves mushrooms behind
disappear
Bug: Spider
A
yes
diagonal
collisions w/ mushrooms make the mushrooms disappear AND make spider change direction
disappear
Bug: Centipede
A (simple version)
yes
'serpentine', changes direction when it encounters something
eats other bugs, but not mushrooms, still changes direction [moves E-W but when it changes, it moves one row down too]
[A] disappear /or/ [Bonus] splits into 2 centipedes [Bonus] drop when it encounters a poison mushroom
Missiles
C
yes
N
when they encounter an obstacle, that obstacle is destroyed
n/a

Minimal Solution & A-B-C Requirements:
Get some graph paper so you can draw your window and objects. Calculating x,y coordinates is easier if you have a picture of what your are doing.
The minimal passable solution will have only a Gun that moves correctly on the screen, can shoot, and a few Mushrooms. This solution is worth a maximum mark of C+
 
The midrange solution will have the Mushrooms, two kinds of bug and a working Gun who can move and shoot stuff.
This solution is worth a maximum mark of B+
 
The best solution will have Mushrooms, the Gun, AND sereval kinds of Bugs all working correctly. It is worth up to an A It will also have a simple version of the centipede. It needs to move correctly but need not react to "poison" mushrooms, and can be destroyed with a single shot.
The "full-function" centipede is Bonus. It moves quite differently from other bugs.
 
HINT: (!!!!) Get the game working in this order: (TEST AFTER EACH STEP!!!!!)
1. the main program that sets up the window
(start by drawing a specific 'picture' in a specific location)
and runs the main game (switch on user input)
2. the Mushrooms ( get them placed )
3. the AI (who will be in charge of all Things)
4. the Gun (move, then do shoot last)
5. the Bugs (move, do other stuff last)

Testing and Marking:
Needs external documentation that user can refer to while playing the game.
 
Sample Mark Guide Here
 
Notes on Marking:
We will be looking for the usual good, clean design; documentation, etc. as always.
In order to pass it must work. (Some marks will be given to all *reasonable* attempts, working or not)
Specifics we will be looking for when marking:
  • Initial Configuration
    • is everyone inside the lines?
  • Mushrooms
      • drawn correctly?
      • do they explode when shot or hit?
  • Gun
      • initial position correct?
      • can the player move him?
      • can the player make him shoot?
      • does he explode when hit?
      • is it possible to win?
  • Bugs
  • How to submit your assignment:
    This assignment SHOULD be 'demo'ed for your TA. Be sure to arrange a time IN LAB (or when your TA is scheduled in CT or MS218) with your TA.
    This assignment can be submitted electronically using submit.
    Include:
    - all '.java' files
    - all '.class' files
    - javadoc documentation
    - your external documentation, including a diagramatical form of your classes

  • BONUSES:
    1. [up to 10 points] Make a "full-function" centipede
    2. [2-3 points] Detect "Game Over": when Gun dead; or when all Bugs gone.
    3. [2 points] Keep score. (one point per thing or allow a certain number of points for certain kinds of things).
    4. [2-5 points, per level] Allow different levels of difficulty (different #'s of things, different ranges, etc.)
    5. [2 points] Set up "key bindings" so player can use the arrow keys, etc.
    6. [4-? points] Make it Interrupt Driven

    CHALLENGE:
    1. [4-? points] Add sound.
    2. [4-? points] Create a full GUI
    3. [5-? points] Do it in colour
    4. [5-? points] 3-D



    Updated: December 20, 2005 05:12 PM