import static javax.swing.JOptionPane.showMessageDialog;
import java.util.Random;
Random rand = new Random();
float x = 450;
float Ball = 0;
int RandomSpawnWidth;
float speedBall = 3;
int score = 0;
float speedPlayer = 10;
PFont Font;
float BallX = 25;
float BallY = 25;
void setup()
{
size(800, 600);
RandomSpawnWidth = rand.nextInt(600);
Font = createFont(“arial.ttf”, 24);
textFont(Font);
}
Background background = new Background(); //first class
Grass grass = new Grass(); // second class
void draw()
{
float ellipseRadius = 25;
float circleRadius = 25;
background.display();
if (keyPressed) {
if (key == ‘a’ || key == ‘A’) {
x = (x-speedPlayer);
}
}
if (keyPressed) {
if (key == ‘d’ || key == ‘D’) {
x = (x+speedPlayer);
}
}
if (x >= 800) {
x = 800;
}
if (x <= 80) {
x = 80;
}
fill (#00F727);
ellipse (400, 700, 900, 500); // landscape
fill (#674700);
rect(400, 400, 20, 50); // middle tree stump
fill (#018E02);
ellipse (410, 400, 50, 50); // middle tree leafs
fill (#674700);
rect(500, 450, 21, 51); // right tree stump
fill (#018E02);
ellipse (510, 445, 50, 50); // right tree leafs
fill (#674700);
rect(50, 500, 150, 400); // left tree stump
fill (#018E02);
ellipse (110, 350, 350, 350); // left tree leafs
fill (#E52525);
rect(x-60, 545, 30, 50); //body
fill (#DEACAC);
ellipse(x-45, 540, 50, 50); // head
fill (#000000);
rect(x-60, 532, 13, 10); //left eye sunglasses
rect(x-50, 532, 11, 3); //middle piece sunglasses
rect(x-42, 532, 13, 10); //right eye sunglasses
ellipse(x-45, 551, 10, 5); //mouth
ellipse(x-55, 595, 13, 5); //left foot
ellipse(x-35, 595, 13, 5); //right foot
fill (#FEFF0D);
ellipse(10, -5, 250, 250); //sun
if (mousePressed) {
fill (#E0E0E0);
ellipse(10, -5, 250, 250); //moon
}
grass.display();
fill(#FFFFFF);
text("Score: " + score, 693, 33);
Ball = Ball + speedBall;
if (Ball > 600) {
showMessageDialog(null, “Close One!”);
System.exit(0);
}
if (Ball < 600);
{
fill (#FF780F);
ellipse(RandomSpawnWidth, 0+Ball, 50, 50);
if (dist(BallX, BallY, 50 ,50) < ellipseRadius + circleRadius) {
BallY = 0;
speedBall = speedBall + 0.5;
Ball = Ball + speedBall;
score++;
speedPlayer = speedPlayer + 0.25;
}
}
}
Background class
class Background {
void display() {
int[] colors = {123, 151, 212, 201, 52, 102, 190, 87, 145, 78, 220, 40, 15, 129, 248, 123, 124, 125, 20, 52, 62, 73, 81, 21, 215};
background (rand.nextInt(colors[20]));
}
}
Grass class
class Grass {
void display(){
for (int x = 0; x <= 805; x = x+10) {
fill(#1CFF34);
triangle( x-15, 620, x+15, 620, x, 570 ); //I used the grass of the practice examn as an example for my grass.
}
}
}
Hey! I’m making a catching ball game with collison detection. But the collision detection won’t work. Can somebody help me ASAP. Thanks in advance! Hope someone can help me quick!