float cowBoyX = 0;
float cowBoyY = 250;
float hatY;
float headX;
float headY;
float headW;
float headH;
boolean hatOnHead = false;
float hatNum;
float num;
Hat hat01 = new Hat(250, -950, 1);
Hat hat02 = new Hat(400, -1050, 2);
Hat hat03 = new Hat(200, -1000, 3);
Hat hat04 = new Hat(200, -1350, 4);
Hat hat05 = new Hat(300, -1500, 5);
Hat hat06 = new Hat(500, -1600, 6);
Hat hat07 = new Hat(500, -1900, 7);
Hat hat08 = new Hat(560, -2000, 8);
Hat hat09 = new Hat(200, -2250, 9);
Hat hat10 = new Hat(300, -2500, 10);
Hat hat11 = new Hat(250, -2500, 11);
Hat hat12 = new Hat(400, -2650, 12);
Hat hat13 = new Hat(200, -2800, 13);
Hat hat14 = new Hat(200, -3300, 14);
Hat hat15 = new Hat(300, -3500, 15);
Hat hat16 = new Hat(500, -3900, 16);
Hat hat17 = new Hat(500, -4900, 17);
Hat hat18 = new Hat(560, -4000, 18);
Hat hat19 = new Hat(200, -5200, 19);
Hat hat20 = new Hat(300, -5550, 20);
int direction = 1;
int score;
int speedx = 7;
PFont font;
PImage bg;
PImage brownhat;
int numFrames1 = 11; //for cowboy animation
int frame = 0; //for cowboy animation
PImage[] images1 = new PImage[numFrames1]; //for cowboy animation
///////////////////////////////////////////////////////////////////////
void setup() {
size(600, 400);
frameRate(15);
font = loadFont("Edmunds-48.vlw");
bg = loadImage("cowboyBackground.png");
brownhat = loadImage("hat.png");
images1[0] = loadImage("horseR0001.gif");
images1[1] = loadImage("horseR0002.gif");
images1[2] = loadImage("horseR0003.gif");
images1[3] = loadImage("horseR0004.gif");
images1[4] = loadImage("horseR0005.gif");
images1[5] = loadImage("horseR0006.gif");
images1[6] = loadImage("horseR0007.gif");
images1[7] = loadImage("horseR0008.gif");
images1[8] = loadImage("horseR0009.gif");
images1[9] = loadImage("horseR0010.gif");
images1[10] = loadImage("horseR0011.gif");
}
//////////////////////////////////////////////////////////////////////
void draw() {
background(bg);
fill(255);
textFont(font, 26);
text(score + "/20 hats", 450, 35);
textFont(font, 27);
if ( millis() > 10 && millis() < 15000) {
text("Press SPACE to catch the", 30, 30);
text("hats on the cowboy's head", 30, 60);
}
if (score == 2 || score == 3 ) {
text("Welcome to the Wild Wild West!", 50, 50);
}
if (score == 5 || score == 6 ) {
text("Giddy Up! ", 50, 50);
}
if (score == 8 || score == 9 ) {
text("Ride 'em, Cowboy!!", 50, 50);
}
if (score == 10 || score == 11 ) {
text("YEEHAAAWWW!!", 50, 50);
}
if (score == 20 ) {
text("You won, Partner!!", 50, 50);
}
hat01.display();
hat01.move();
hat01.grab();
hat02.display();
hat02.move();
hat02.grab();
hat03.display();
hat03.move();
hat03.grab();
hat04.display();
hat04.move();
hat04.grab();
hat05.display();
hat05.move();
hat05.grab();
hat06.display();
hat06.move();
hat06.grab();
hat07.display();
hat07.move();
hat07.grab();
hat08.display();
hat08.move();
hat08.grab();
hat09.display();
hat09.move();
hat09.grab();
hat10.display();
hat10.move();
hat10.grab();
hat11.display();
hat11.move();
hat11.grab();
hat12.display();
hat12.move();
hat12.grab();
hat13.display();
hat13.move();
hat13.grab();
hat14.display();
hat14.move();
hat15.display();
hat15.move();
hat15.grab();
hat16.display();
hat16.move();
hat16.grab();
hat17.display();
hat17.move();
hat17.grab();
hat18.display();
hat18.move();
hat18.grab();
hat19.display();
hat19.move();
hat19.grab();
hat20.display();
hat20.move();
hat20.grab();
/////////////////////////////////////////////////////////////
//cowboy
headX = cowBoyX + 100;
headY = cowBoyY + 25;
headW = 50;
headH = 50;
image(images1[frame], cowBoyX, cowBoyY, 150, 150);
frame = (frame+1)%numFrames1; // Use % to cycle through frames
if (cowBoyX > 580) {
cowBoyX = -50;
}
if (keyPressed) {
if (key == 32) {
cowBoyX += speedx * direction ;
}
// }
// }
}
}
class Hat {
float hatY;
float hatX;
boolean hatOnHead = false;
float hatNum;
Hat(float x, float y, float num){
hatY = y;
hatX = x;
hatNum = num;
}
void display() {
image(brownhat, hatX, hatY, 50, 50);
}
void move() {
hatY = hatY + 5;
}
void grab() {
if (hatOnHead || ((headX + headW) > hatX &&
headX < (hatX + 50) &&
(headY + headH) > hatY &&
headY < hatY + 50)) {
hatX = cowBoyX+70;
hatY = cowBoyY;
if (hatOnHead == false) {
hatOnHead = true;
score = score + 1;
println("increasing score");
}
}
}
}
Alexis - Project 2
on Sunday, Nov 16, 2008 – 11:11 pm