Derby game question
in
Programming Questions
•
2 years ago
I am trying to figure out a way to display whatever "horse" reaches the end first. Any ideas on how to make something pop up and say RED WINS when the red horse reaches the end?
Here is the code:
- PImage first;
PImage back;
PImage a;
PImage b;
PImage c1;
PImage rw; - boolean running;
boolean bwin;
color c = color(0);
color c2 = color(100,0,0);
color c3 = color(0,100,0);
float x = 0;
float y = 100;
float speed = random(20,30);
float x2 = 0;
float y2 = 300;
float speed2 = random(20,30);
float x3 = 0;
float y3 = 500;
float speed3 = random(20,30); - void setup() {
size(screen.width-100,screen.height-100);
frameRate(10000);
smooth();
first = loadImage("title.JPG");
back = loadImage("grass.jpg");
a = loadImage("black horse.jpg");
b = loadImage("red horse.JPG");
c1 = loadImage("green horse.jpg");
rw = loadImage("red wins.JPG");
} - void draw() {
background(255);
move();
display();
if(bwin) {
println("black wins");
}
if(running) {
println("running");
}
else {
println("not running");
}
} - void move() {
if (running) {
x = x + speed;
if (x > width) {
x = 0;
}
x2 = x2 + speed2;
if(x2 > width) {
x2 = 0;
}
x3 = x3 + speed3;
if(x3 > width) {
x3 = 0;
}
}
} - void display() {
image(first,0,0,screen.width,screen.height);
if (key == CODED);
if (key == ENTER) {
image(back,0,0,screen.width,screen.height);
image(a,x,y,150,150);
image(b,x2,y2,150,150);
image(c1,x3,y3,150,150);
}
} - void keyPressed() {
running = true;
} Thanks !!!
1