mini game help
in
Programming Questions
•
1 year ago
Ball ball2;
boolean moveup = false;
void setup() {
size(200, 200);
smooth();
// Initialize balls
ball2 = new Ball(32);
}
void draw() {
background(255);
// Move and display balls
fill(0);
ellipse(width/2,height-20,40,40);
if (moveup == true){
height--;
}
if (keyPressed == true){
moveup = true;
} else {
ellipse(width/2,height-20,40,40);
}
ball2.move();
ball2.display();
}
class Ball {
float r; // radius
float x, y; // location
float xspeed, yspeed; // speed
// Constructor
Ball(float tempR) {
r = tempR;
x = random(width);
y = (40);
xspeed = (1);
yspeed = (1);
}
void move() {
x += xspeed; // Increment x
y += yspeed; // Increment y
// Check horizontal edges
if (x > width-20 || x < 20) {
xspeed *= - 1;
}
//Check vertical edges
if (y > 40 || y < 20) {
yspeed *= -1;
}
}
// Draw the ball
void display() {
stroke(0);
line(0, 60, width, 60);
noStroke();
fill(255, 0, 0);
ellipse(x, y, 40, 40);
}
}
i have this code and i want to make it that when the black ball goes up (press any key), if it touches the red ball, it says you win, but if it misses and goes past red ball, it says game over
thanks for any help
thanks for any help
1