With a partner, I develop a simple two player game. The game can ask each player to participate at the same time (head-to-head) or one at a time (contest) or the player can collaborate and cooperate to achieve the goal. The game does not need to involve scores or levels, but should focus more on the human-to-human interaction between the players and how the game encourages a playful experience between them. For our game, one player uses the left and right arrow keys to control a mechanical claw, and the down button to pick up the guinea pigs. The other player uses the mouse to draw bricks to crush the undesireable monsters. Both players have to work together to save as many as they can.
PROCESSING
float circleX=0;
float circleY=0;
PImage dumpstertop4;
PImage dumpsterbottom4;
PImage animal1;
PImage animal2;
PImage animal3;
PImage animal4;
PImage animal5;
PImage animal6;
PImage animal7;
PImage arrow;
PImage claw2;
PImage ugly;
PImage titlepg;
PImage titleanimals;
PImage yes;
PImage no;
Claw claw;
int pigCounter=0;
int createspeed = 6; // Seconds to create a pig
boolean clawInUse = false;
PFont title;
PFont font;
int button1X = 210;
int button1Y = 230;
int button1Width = 180;
int button1Height = 65;
int button2X = 210;
int button2Y = 300;
int button2Width = 170;
int button2Height = 65;
int button3X = 210;
int button3Y = 300;
int button3Width = 170;
int button3Height = 65;
int button5X = 210;
int button5Y = 240;
int button5Width = 180;
int button5Height = 65;
int state = 1;
class Box
{
float x;
float y;
float widthbox;
float heightbox;
float speed;
float r;
float g;
float b;
boolean pickedUp = false;
Box (float xstart, float ystart, float w, float h)
{
x=xstart;
y=ystart;
widthbox=w;
heightbox=h;
speed=0;
r= random (100, 250);
g= random (100, 250);
b= random (100, 250);
}
void fall ()
{
if (((y+heightbox>=265)&& (x+widthbox>116))||((y+heightbox>800)||(x+widthbox<0)))
{
speed=0;
}
else
{
speed+=9.8/frameRate;
y+=speed;
}
}
void draw ()
{
noStroke ();
fill (r, g, b);
rect (x, y, widthbox, heightbox);
fall();
if (speed==0)
x-=1;
}
}
///////////BOX ARRAY!!!!!!//////////////
int maxBoxes = 1000;
int numberOfBoxes = 0;
Box [] boxArray = new Box [maxBoxes];
////////////////////////////////////////
class Pig
{
float x;
float y;
float fatness;
float stoutness;
float speed;
float pickupOffset;
int pigtype;
// float a = floor(random(1,6.9));
boolean pickedUp = false;
boolean isSquished= false;
Pig (float xstart, float ystart)
{
x=xstart;
y=ystart;
speed=0;
fatness=65;
stoutness=50;
pickupOffset = 0;
pigtype = floor(random(1,7.9));
}
void fall ()
{
if (((y+stoutness>=265)&& (x+fatness>116))||((y+stoutness>800)||(x+fatness<0)))
{
speed=0;
}
else
{
speed+=9.8/frameRate;
y+=speed;
}
}
void draw ()
{
noStroke ();
fill (255);
if (pickedUp) {
// pig attached to claw
if(claw.y > 0)
{
if(pigtype ==1){
image(animal1, claw.x-pickupOffset,claw.y+20);
}
else if(pigtype == 2){
image (animal2,claw.x-pickupOffset,claw.y+20);
}
else if(pigtype == 3){
image(animal3,claw.x-pickupOffset,claw.y+20);
}
else if (pigtype == 4){
image(animal4,claw.x-pickupOffset,claw.y+20);
}
else if (pigtype == 5){
image(animal5,claw.x-pickupOffset,claw.y+20);
}
else if (pigtype ==6){
image(animal6,claw.x-pickupOffset,claw.y+20);
state=5;
}
else if (pigtype ==7){
image(animal6,claw.x-pickupOffset,claw.y+20);
state=5;
}
}
else // pig explodes when too high
{
y=1000;
clawInUse=false;
pickedUp=false;
// y=-1000;
}
}
else if (isSquished==false)
{
if(pigtype ==1)
{
image(animal1, x,y);
fall();
if (speed==0)
x-=1;
if (y>265&&y<1000)
state=5;
}
if(pigtype == 2){
{
image(animal2, x,y);
fall();
if (speed==0)
x-=1;
if (y>265&&y<1000)
state=5;
}
}
if(pigtype == 3){
{
image(animal3, x,y);
fall();
if (speed==0)
x-=1;
if (y>265&&y<1000)
state=5;
}
}
if(pigtype == 4){
{
image(animal4, x,y);
fall();
if (speed==0)
x-=1;
if (y>265&&y<1000)
state=5;
}
}
if(pigtype == 5){
{
image(animal5, x,y);
fall();
if (speed==0)
x-=1 ;
if (y>265&&y<1000)
state=5;
}
}
if((pigtype == 6)||(pigtype==7)){
{
image(animal6, x,y);
fall();
if (speed==0)
x-=1;
}
}
}
else
{
noStroke ();
fill (255, 0, 0);
ellipse (x, y+52, 65, 10);
ellipse (x+37, y+55, 10, 5);
ellipse (x-38, y+57, 13, 5);
fall ();
if (speed==0)
x-=1;
}
}
}
///////////PIG ARRAY!!!!!!//////////////
int maxPigs = 10000;
int numberOfPigs = 0;
Pig [] pigArray = new Pig [maxPigs];
////////////////////////////////////////
void setup () {
size (600, 400);
background (255);
smooth ();
dumpstertop4 = loadImage("dumpstertop4.png");
dumpsterbottom4 = loadImage("dumpsterbottom4.png");
animal1 = loadImage("lulu1.12.png");
animal2 = loadImage("lulu2.12.png");
animal3 = loadImage("lulu3.12.png");
animal4 = loadImage("lulu4.12.png");
animal5 = loadImage("lulu5.12.png");
animal6 = loadImage("monster12.png");
animal7= loadImage("monster12.png");
claw2 = loadImage("clawforintro.png");
titlepg = loadImage("title.png");
titleanimals = loadImage("titleanimals.png");
ugly = loadImage("ugly.png");
yes = loadImage("yes.png");
no = loadImage("no.png");
arrow = loadImage("arrow.png");
title = loadFont ("Arial-BoldMT-48.vlw");
font = loadFont ("Arial-BoldMT-20.vlw");
noStroke ();
claw=new Claw (0, 0, 20, 300);
}
void draw () //////////////////////////////////////////////////
{
smooth();
background (195,80,55);
if (state==1)
stateOne ();
else if (state==2)
stateTwo ();
else if (state ==3)
stateThree();
else if (state ==4)
stateFour ();
else if (state ==5)
stateFive();
}
class Claw
{
float x=0;
float y=0;
float clawWidth=20;
float clawHeight=300;
boolean clawDown=false;
Claw (float xpos, float ypos, float cwidth, float cheight)
{
x=xpos;
y=ypos;
clawWidth=cwidth;
clawHeight=cheight;
}
void clawFall ()
{
if (clawDown==true&&y<250)
{
y=constrain (y+8, 0, 250);
}
else if (clawDown==false&& y>0)
y=constrain(y-8, 0, 250);
else
clawDown=false;
}
void draw ()
{
fill (200);
noStroke();
strokeWeight (2);
rect (x, y-280, clawWidth, clawHeight);
clawFall ();
}
}
void collision ()
{
int testY=(int)(claw.y+claw.clawHeight+1-280);
for (int i=0; i<claw.clawWidth; i++)
{
//set((int)claw.x+i, testY, color(255, 0, 0));
color c= get ((int)claw.x+i, testY);
if (clawInUse == false && (c!=color (195,80,55))&&(c!=color (127))&&(c!=color (50))&&(c!=color (100))&&(c!=color(0)) && claw.clawDown == true)
{
println("i hit the color " + red(c) + "," + green(c) + "," + blue(c));
claw.clawDown=false;
for (int j=0; j<numberOfBoxes; j++)
{
if((int)red(c)==(int)boxArray[j].r && (int)green(c)==(int)boxArray[j].g && (int)blue(c)==(int)boxArray[j].b)
{
boxArray[j].y=1000;
println("i got box " + j);
}
}
for (int j=0; j<numberOfPigs; j++)
{
if (claw.x+i > pigArray[j].x && claw.x+i < pigArray[j].x + pigArray[j].fatness &&
testY >= pigArray[j].y) {
pigArray[j].pickedUp = true;
clawInUse = true;
pigArray[j].pickupOffset = claw.x-pigArray[j].x;
pigArray[j].y=1000;
println("i got pig " + j);
}
}
}
}
}
void smush ()
{
for (int i=0; i<numberOfBoxes; i++)
{
for (int j=0; j<numberOfPigs; j++)
{
if (boxArray[i].x < pigArray[j].x && boxArray[i].widthbox >= pigArray[j].fatness&& boxArray[i].x+boxArray[i].widthbox>pigArray[j].x+pigArray[j].fatness && boxArray[i].y+boxArray[i].heightbox>=pigArray[j].y)
{
pigArray[j].isSquished=true;
println("i squished pig"+j);
if (pigArray[j].pigtype<6)
state=5;
}
}
}
}
void belt ()
{
noStroke ();
fill (50);
quad (120, 294, 600, 292, 600, 230, 150, 230);
stroke (0);
strokeWeight(1);
fill (30);
quad (130,290,600,290,600,316,130,316);
fill (50);
line (150, 230, 600, 230); //backline
line (130, 290, 600, 290); //frontline
line (150, 230, 118, 296); //ending line
line (130, 290, 130, 316); //height of blah
line (130, 316, 600, 316); // bottom conveyor line
pushMatrix ();
translate (130, 303);
rotate (radians(frameCount*4.5 % 360*-1));
ellipse (circleX, circleY, 26, 26);
// ellipse (160, 303, 26, 26);
// ellipse (190, 303, 26, 26);
// ellipse (220, 303, 26, 26);
// ellipse (250, 303, 26, 26);
// ellipse (280, 303, 26, 26);
strokeWeight (3);
stroke (255);
point (circleX+5, circleY+5);
popMatrix ();
// stroke (150);
// line (135, 265, 600, 265); //midline!!!
//MOVING LINES ON BELT//
}
void conveyor()
{
stroke (100);
strokeWeight (1);
line (moveX-372, 230, moveX-400, 290);
line (moveX-292, 230, moveX-320, 290);
line (moveX-212, 230, moveX-240, 290);
line (moveX-132, 230, moveX-160, 290);
line (moveX-52, 230, moveX-80, 290);
line (moveX+28, 230, moveX, 290);
moveX-=1;
if (moveX<522)
moveX=600;
}
void stateOne() {
background (195,80,55);
background (195,80,55);
image(titlepg,10,10,580,380);
fill(0,140);
rect(10,10,580,380);
image(titleanimals,10,10,580,380);
strokeWeight(3);
stroke(54,85,182);
rect(button1X,button1Y,button1Width,button1Height);
fill(245,210,50);
textFont (title,40);
text("The Guinea Pig Game!",300,150);
textFont(font,20);
fill(40,200,30);
textAlign (CENTER);
text("Next", 300,270);
}
void stateTwo() {
background (195,80,55);
strokeWeight(3);
stroke(54,85,182);
fill(0);
rect(10,10,580,380);
stroke(54,85,182);
rect(button2X,button2Y,button2Width,button2Height);
textFont(font,20);
fill(245,210,50);
textFont (title,26);
text("About",300,50);
textFont(font,18);
text("YOU ARE GUINEA PIG BREEDERS.",300,90);
text("You have been trying to perfect the rare hairless breed",300,115);
text("but you are still working out some kinks in your formula.",300,135);
text("(occasionally you get some weird-looking green things...)",300,155);
text("Unfortunately the green ones try to eat your good ones",300,175);
text("so you have to rescue all of the good breeds and squish", 300,195);
text("the bad ones with cinder blocks.",300,215);
image (yes, 60,245, 98,130);
image (no,453,262,75,95);
stroke(255,0,0);
strokeWeight(8);
line (460,358,540,278);
noFill();
ellipse(495,310,100,100);
//fill(40,200,30);
textAlign (CENTER);
text("Next", 300,342);
}
void stateThree() {
background (195,80,55);
strokeWeight(3);
stroke(54,85,182);
fill(0);
rect(10,10,580,380);
stroke(54,85,182);
rect(button3X,button3Y,button3Width,button3Height);
image (arrow, 139,175);
image(claw2,0,10);
//image(yes,480,400);
//image(no,530,450);
textFont(font,20);
fill(245,210,50);
textFont (title,26);
text("How To Play",300,50);
textFont(font,11);
text("click and drage the mouse to",100,215);
text("make big bricks to drop on the",100,230);
text("undesirable monsters. let them",100,245);
text("fall into the dumpster.",100,260);
text("use the left and right arrow",300,215);
text("keys to position the machine", 300,230);
text("arm and use the down key to",300,245);
text("make it pick up the good",300,260);
text("guinea pigs.",300,275);
text("save the good guinea pigs",500,215);
text("and squish the bad monsters.",500,230);
text("do not throw away any of the",500,245);
text("good ones or accidentally",500,260);
text("pick up the wrong ones!",500,275);
//text("",500,290);
stroke(54,85,182);
textFont(font,18);
textAlign (CENTER);
text("Click to Begin!", 300,342);
stroke(255,90);
strokeWeight(.25);
fill(255,20);
rect(50,120,100,60);
image(ugly,450,90,100,100);
}
void stateFour () {
background (195,80,55);
image (dumpstertop4, -12,310);
if(pigCounter%(24*createspeed)==0)
{
pigArray[numberOfPigs]=new Pig (500, 100);
numberOfPigs++;
}
if(pigCounter <2400)
pigCounter++;
else if(pigCounter < 3600)
pigCounter+=1.5;
else if(pigCounter < 4800)
pigCounter+=2;
else
pigCounter+=2.5;
belt ();
conveyor ();
claw.draw ();
for (int i=0; i<numberOfBoxes; i++)
{
boxArray [i].draw();
}
for (int i=0; i<numberOfPigs; i++)
{
pigArray [i].draw();
}
collision ();
smush ();
image (dumpsterbottom4, -12,330);
}
///////// END OF STATE FOUR/////////////////////
void stateFive ()
{
background (195,80,55);
fill(0);
rect(10,10,580,380);
strokeWeight(3);
stroke(54,85,182);
rect(button5X,button5Y,button5Width,button5Height);
textFont(font,20);
fill(40,200,30);
textAlign (CENTER);
text("Try Again?", 300,280);
fill(245,210,50);
textFont (title,40);
text("Game Over.",300,150);
boxArray = new Box [maxBoxes];
pigArray = new Pig [maxPigs];
numberOfBoxes = 0;
numberOfPigs = 0;
}
float tempX;
float tempY;
void mousePressed ()
{
tempX=mouseX;
tempY=mouseY;
}
void keyPressed ()
{
if (key == CODED)
{
if (keyCode == RIGHT)
claw.x+=5;
else if (keyCode == LEFT)
claw.x-=5;
else if (keyCode == DOWN)
claw.clawDown=true;
if (claw.y>265)
{
claw.y-=5;
if (claw.y<20)
claw.y=20;
}
}
}
void mouseDragged ()
{
stroke (0, 80);
noFill();
if (numberOfBoxes<maxBoxes)
{
if (mouseX<tempX)
{
if (mouseY<tempY)
{
rect (mouseX, mouseY, tempX-mouseX, tempY-mouseY);
}
else
{
rect(mouseX, tempY, tempX-mouseX, mouseY-tempY);
}
}
else
{
if (mouseY<tempY)
{
rect(tempX, mouseY, mouseX-tempX, tempY-mouseY);
}
else
{
rect(tempX, tempY, mouseX-tempX, mouseY-tempY);
}
}
}
}
void mouseReleased ()
{
if (state ==4)
{
if (numberOfBoxes<maxBoxes)
{
if (mouseX<tempX)
{
if (mouseY<tempY)
{
boxArray [numberOfBoxes] = new Box (mouseX, mouseY, tempX-mouseX, tempY-mouseY);
}
else
{
boxArray [numberOfBoxes] = new Box (mouseX, tempY, tempX-mouseX, mouseY-tempY);
}
}
else
{
if (mouseY<tempY)
{
boxArray [numberOfBoxes] = new Box (tempX, mouseY, mouseX-tempX, tempY-mouseY);
}
else
{
boxArray [numberOfBoxes] = new Box (tempX, tempY, mouseX-tempX, mouseY-tempY);
}
}
numberOfBoxes++;
}
}
else if (state==5)
button5Clicked ();
else
{
button3Clicked();
button2Clicked();
button1Clicked();
}
}
void button1Clicked(){
if (state == 1 && mouseX > button1X &&
mouseX < (button1X + button1Width) &&
mouseY > button1Y &&
mouseY < (button1Y + button1Height)) {
state = 2;
}
}
void button2Clicked(){
if (state == 2 && mouseX > button2X &&
mouseX < (button2X + button2Width) &&
mouseY > button2Y &&
mouseY < (button2Y + button2Height)) {
state = 3;
}
}
void button3Clicked(){
if (state == 3 && mouseX > button3X &&
mouseX < (button3X + button3Width) &&
mouseY > button3Y &&
mouseY < (button3Y + button3Height)) {
state = 4;
}
}
void button5Clicked(){
if (state == 5 && mouseX > button5X &&
mouseX < (button5X + button5Width) &&
mouseY > button5Y &&
mouseY < (button5Y + button5Height)) {
state = 3;
}
}