Light li; // declare light object
Light li2;
Light li3;
Light li4;
Light li5;
Light li6;
Light li7;
Light li8;
Light li9;
Light li10;
Spotlight sp;
PImage bg;
PImage light;
int score = 0;
int page = 0;
float sec;
boolean over = false;
PFont scoreFont;
PFont welcomeFont;
void setup() {
size(600, 400);
smooth();
bg = loadImage("bg.png");
light = loadImage("light.png");
li = new Light(0.2, 2.5, 100, 255); // construct object
li2 = new Light(0.6, 1.0, 150, 255);
li3 = new Light(1.0, 1.5, 200, 255);
li4 = new Light(2.0, 1.75, 250, 255);
li5 = new Light(0.75, 1.25, 300, 255);
li6 = new Light(1.25, 2.25, 100, 255);
li7 = new Light(1.5, 1.3, 150, 255);
li8 = new Light(0.4, 1.6, 200, 255);
li9 = new Light(0.25, 1.4, 250, 255);
li10 = new Light(2.25, 1.35, 300, 255);
sp = new Spotlight();
scoreFont = loadFont("score.vlw");
welcomeFont = loadFont("welcome.vlw");
}
void draw() {
timer();
restart();
if (page == 0) {
background(bg);
fill(255, 5);
noStroke();
rectMode(CENTER);
rect(width/2, height/2, 300, 150);
fill(255, 150);
textFont(welcomeFont);
textLeading(16);
textAlign(LEFT);
text("Catch as many fireflies as you can. Click inside the rectangle to play.", width/2, height/2+30, 140, 100);
li.move();
li.display();
li2.move();
li2.display();
li3.move();
li3.display();
li4.move();
li4.display();
li5.move();
li5.display();
li6.move();
li6.display();
li7.move();
li7.display();
li8.move();
li8.display();
li9.move();
li9.display();
li10.move();
li10.display();
}
if (page == 1) {
background(bg);
li.move();
li.display();
li2.move();
li2.display();
li3.move();
li3.display();
li4.move();
li4.display();
li5.move();
li5.display();
li6.move();
li6.display();
li7.move();
li7.display();
li8.move();
li8.display();
li9.move();
li9.display();
li10.move();
li10.display();
sp.move();
sp.display();
fill(255);
textFont(scoreFont);
text(score, 10, 200);
}
// if ((millis() > 10,000) && (mousePressed == true)) {
// start = true;
// }
}
void mousePressed() {
if (page == 0) {
if ((mouseX > 150) && (mouseX < 450) && (mouseY > 125) && (mouseY < 275)) {
page = 1;
}
}
else {
if(score == 0) {
sp.step = 0;
li.check();
li2.check();
li3.check();
li4.check();
li5.check();
li6.check();
li7.check();
li8.check();
li9.check();
li10.check();
over = true;
}
}
}
void timer() {
if(over) {
sec += 0.07;
}
}
void restart() {
if (page == 1 && sec >= 5.0) {
page = 0;
sec = 0;
over = false;
score = 0;
li.reset();
li2.reset();
li3.reset();
li4.reset();
li5.reset();
li6.reset();
li7.reset();
li8.reset();
li9.reset();
li10.reset();
sp.step = 0.002;
}
}
Scott - Project 2
on Sunday, Nov 16, 2008 – 11:30 pm