please format code with </> button * homework policy * asking questions
boolean running = false;
PImage imgbk;
PImage imgm;
PImage albert;
PImage imgnote;
String[] imageNames = {
"albert0.jpg", "albert1.jpg"
};
PImage[] images = new PImage[imageNames.length];
int numPeople = 2;
int dx, dy;
int score;
int startTime;
int albertX, albertY, albertW, albertH;
void setup()
{
size(850, 700);
imgbk = loadImage("b.jpg");
imgm = loadImage("m.jpg");
imgnote = loadImage("n.png");
for (int i = 0; i < imageNames.length; i=i++)
{
String imageName = imageNames[i];
images[i] = loadImage(imageName);
}
albertW = 150;
albertH = 150;
albertX = int(random(0, width-albertW));
albertY = int(random(0, height/2-albertH));
dx=5;
dy=5;
startTime = millis();
score = 0;
}
void draw() {
{
fill(0);
if ( score == -10) {
textSize(50);
fill(255, 0, 0);
text("You Lose!", 150, 270);
}
else if (running) {
image(imgm, 0, 0, width, height);
image(imgnote, mouseX, mouseY, 100, 130);
float r = random(0, 2);
int ir = int(r);
PImage img = images[ir];
image(img, 0, 0);
albertX= albertX + dx;
albertY= albertY + dy;
textSize(48);
fill(255, 255, 255);
text("Time: "+ (millis() - startTime)/1000 + "s", 25, 50);
text("Score: "+ score, 25, 100);
if (albertX<0 || albertX>width-albertW)
{
dx=-dx;
}
if (albertY<0 || albertY>height-albertH)
{
dy=-dy;
}
if (albertX+albertW >= mouseX && albertX <= mouseX + 100 && albertY+albertH >= mouseY && albertY <= mouseY + 130)
{
score = score - 1;
albertX = int(random(0, width-albertW));
albertY = int(random(0, height/2-albertH));
}
}
}
}
else {
image(imgbk, 0, 0, width, height);
PFont myFont;
myFont = loadFont("Rockwell-ExtraBold-65.vlw");
textFont(myFont);
fill(255);
text("Start", 80, 400);
}
}
}
void mousePressed() {
running = !running;
}