///Justin Chen
///DMA Interactivity 28 Fall 2008
///Project 2
///A one-button game
Toy player;
Wall w1;
Wall w2;
int mode = 0;
PImage m1;
PImage in;
PImage one;
PImage two;
PImage gj1;
PImage gj2;
PImage f1;
PImage f2;
PImage p1;
PImage p2;
PImage end;
void setup() {
size(600, 400);
smooth();
player = new Toy(40, 200, 10, 10, color (0));
w1 = new Wall(0,0);
w2 = new Wall(0,0);
noCursor();
m1 = loadImage("title.jpg");
in = loadImage("intro.jpg");
one = loadImage("mission1.jpg");
p1 = loadImage("plane.png");
p2 = loadImage("plane2.png");
gj1 = loadImage("gj1.jpg");
two = loadImage("mission2.jpg");
f1 = loadImage("no1.jpg");
f2 = loadImage("no2.jpg");
gj2 = loadImage("gj2.jpg");
end = loadImage("end.jpg");
}
void draw() {
///////////////////////////////////////////////TITLE PAGE////////////
if (mode == 0) {
image(m1,0,0);
}
/////////////////////////////////////////////HOW TO PLAY/////////////
else if (mode == 1) {
image(in,0,0);
}
//////////////////////////////////////////////MISSION ONE////////////
else if (mode == 2) {
image(one,0,0);
w1.x =0;
player.y=200;
}
//////////////////////////////////////////////MISSION ONE PLAY////////
else if (mode == 3) {
w1.display();
w1.move();
color c1 = get (int(player.x), int(player.y));
color c2 = get (int(player.x+10), int(player.y+10));
player.display();
player.move();
if ((c1 == color(0)) || c2 == color(0)) {
mode = 7;
}
// else if((c1 == color(255,0,0)) || c2 == color(255,0,0)) {
// mode = 5;
// }
if (w1.x+ 9306 == 50) {
mode = 5;
}
if (keyPressed == true && key == ' ') {
image(p2,player.x, player.y);
}
else {
image(p1,player.x, player.y);
}
}
////////////////////////////////////////////MISSION TWO PLAY//////////////////
else if (mode == 4) {
w2.display2();
w2.move();
color c1 = get (int(player.x), int(player.y));
color c2 = get (int(player.x+10), int(player.y+10));
player.display();
player.move();
if ((c1 == color(0)) || c2 == color(0)) {
mode = 8;
}
// else if((c1 == color(255,0,0)) || c2 == color(255,0,0)) {
// mode = 9;
// }
if (w2.x + 18275 == 50) {
mode = 9;
}
if (keyPressed == true && key == ' ') {
image(p2,player.x, player.y);
}
else {
image(p1,player.x, player.y);
}
}
/////////////////////////////////////////////MISSION ONE SUCCESS////////////////
else if (mode == 5) {
image(gj1,0,0);
}
else if (mode == 6) {
image(two,0,0);
w2.x =0;
player.y=200;
}
else if (mode == 7) {
image(f1,0,0);
}
else if (mode == 8) {
image(f2,0,0);
}
else if (mode == 9) {
image(gj2,0,0);
}
else if (mode == 10) {
image(end,0,0);
}
}
class Toy {
float x, y,w,h;
color c;
float speedX = 1.0;
float speedY = 1.0;
Toy(float xin, float yin,float win, float hin, color cin ) {
x = xin;
y = yin;
w = win;
h = hin;
c = cin;
}
void move() {
if (keyPressed == true && key == ' ') {
y -= 3.5;
}
else{
y += 3.5;
}
}
void display() {
noFill();
noStroke();
rect(x, y,w,h);
}
}
class Wall {
float x, y;
PImage w1;
PImage w2;
Wall(float xin, float yin) {
x = xin;
y = yin;
w1 = loadImage("wall1.gif");
w2 = loadImage("wall2.gif");
}
void move() {
x -=4.0;
}
void display() {
image(w1,x,y);
}
void display2() {
image(w2,x,y);
}
}
void keyPressed() {
if ((mode == 0) && (key == ' ')) {
mode = 1;
}
else if ((mode == 1) && (key == ' ')) {
mode = 2;
}
else if ((mode == 2) && (key == ' ')) {
mode = 3;
}
else if ((mode == 5) && (key == ' ')) {
mode = 6;
}
else if ((mode == 6) && (key == ' ')) {
mode = 4;
}
else if ((mode == 7) && (key == ' ')) {
mode = 2;
}
else if ((mode == 8) && (key == ' ')) {
mode = 6;
}
else if ((mode == 9) && (key == ' ')) {
mode = 10;
}
else if ((mode == 10) && (key == ' ')) {
mode = 0;
}
}
Justin - Project 2
on Wednesday, Nov 19, 2008 – 2:32 pm
2 Comments
Justin, I need to see all of the code to grade this.
so i’ve been practicing and i can finally beat this game.