CS.Pacman

= Pacman = **Team Pacman** **Orbin and Cory**

Mr. Bujak
insert more recent updates here in a reverse chronological order

5/31/2011 update: -

IDEAS: image 1:
 * 1) Shapes – closed, openRight, openLeft, openUp, openDown
 * 2) creating a Pacman mouth can be tough - use an image adn we can rotate it! See @http://processing.org/reference/PShape.html
 * 3) Pacman has a contant speed in one direction
 * 4) Determine grid size from the diameter of a pacman and walls, say d=40
 * 5) Grid – ‘*’ is wall, ‘ ‘ is where pacman can travel, ‘.’ is points
 * 6) Write read gridRead function into 2D array
 * 7) As game is played, colliding into a ‘.’ add points and plays a sound.
 * 8) Get sound effects – we can record it if necessary

movie 1: media type="custom" key="9613778" URL: @http://screenr.com/0eI

code: code /* Pacman * Team Pacman * Orbin - Cory * Computer Science - Hope Charter High School * 2011 Spring Semester * Mr. Bujak * http://www.play-pacman-online.com */

// direction constants for pacman user-controlled character and the 4 autonomous ghost characters: int directionNONE = 0; int directionUP = 1; int directionDOWN = 2; int directionLEFT = 3; int directionRIGHT = 4;

Pacman pacman = new Pacman(250, 250, 3, directionNONE);

void setup { size(500,500); noCursor; noStroke; smooth; println ("Welcome to Pacman!"); println("Hit the cursor keys to move pacman."); println("Hit s to pause, ESC to quit."); } // setup

void draw { background(0); fill(color(255,255,255));

pacman.move;

pacman.display; } // draw

// ======================

class Pacman { int x; int y;  int speed = 1; int direction = directionNONE; // NONE, UP, DOWN, LEFT, RIGHT

Pacman(int xx, int yy, int sp, int dir) { x = xx; y = yy; speed = sp; direction = dir; }

void display { String directionString = "";

ellipse(x, y, 20, 20);

fill(color(255,0,0)); // pacman direction indicator ... where mouth should be

if (direction == directionNONE) { ellipse(x, y, 6, 6); directionString = "NONE"; }   else if (direction == directionUP) { ellipse(x, y-10+3, 6, 6); directionString = "UP"; }   else if (direction == directionDOWN) { ellipse(x, y+10-3, 6, 6); directionString = "DOWN"; }   else if (pacman.direction == directionLEFT) { ellipse(x-10+3, y, 6, 6); directionString = "LEFT"; }   else if (direction == directionRIGHT) { ellipse(x+10-3, y, 6, 6); directionString = "RIGHT"; }   else { fill(color(255,255,0)); ellipse(x, y, 6, 6); directionString = "ERROR!"; }

fill(255); // white diagnostics text(directionString, 28, 75); text("(x,y)=("+ x + "," + y + ")", 28, 90);

} //display

void move { if (direction == directionNONE) { // do nothing }   else if (direction == directionUP) { y -= speed; if (y < 0) {   // wrap around y = height; }   }    else if (direction == directionDOWN) { y += speed; if (y > height) {   // wrap around y = 0; }   }    else if (direction == directionLEFT) { x -= speed; if (x < 0) {   // wrap around x = width; }   }    else if (direction == directionRIGHT) { x += speed; if (x > width) {   // wrap around x = 0; }   }    else { // fill(color(255,255,0)); // ellipse(pacman.x, pacman.y, 6, 6); } }  // move } //class Pacman

class Ghost { int x; int y;  int speed = 1; int direction = directionNONE; // NONE, UP, DOWN, LEFT, RIGHT } //class Ghost

void keyPressed { if (keyPressed == true) { if ((key >= 32) && (key <= 126)) { println("ASCII char " + key); text(key,28,75); if (key == 's') { pacman.direction = directionNONE; }   }    else if (key == CODED) { //print("ASCII control char "); if (keyCode == UP) { //println("UP"); //text("UP",28,75); pacman.direction = directionUP; pacman.y--; //ellipse (x, y, 20, 20); }     else if (keyCode == DOWN) { //println("DOWN"); //text("DOWN",28,75); pacman.direction = directionDOWN; pacman.y++; //ellipse (x, y, 20, 20); }     else if (keyCode == LEFT) { //println("LEFT"); //text("LEFT",28,75); pacman.direction = directionLEFT; pacman.x--; //ellipse (x, y, 20, 20); }     else if (keyCode == RIGHT) { //println("RIGHT"); //text("RIGHT",28,75); pacman.direction = directionRIGHT; pacman.x++; //ellipse (x, y, 20, 20); }     else if (keyCode == ENTER) { println("ENTER"); text("ENTER",28,75); }     else if (keyCode == CONTROL) { println("CONTROL"); text("CONTROL",28,75); }     else if (keyCode == ALT) { println("ALT"); text("ALT",28,75); }     else if (keyCode == SHIFT) { println("SHIFT"); text("SHIFT",28,75); }     else { println("not trappped"); text("____",28,75); }   }  // key == CODED } // keyPressed } // keyPressed event handler code