Main code
float playerWidth;
float playerX;
float playerY;
float number;
float[] circleY = new float[10];
float circleRadius = 25;
float headRadius = 15;
Player player;
//=============================================================
void setup() {
size( 600, 600 );
player = new Player (width / 2, height / 2, 100);
for (int i = 0; i < circleY.length; i++) {
circleY[i] = random(height);
}
}
//=============================================================
void draw() {
background(#0062AA);
player.display();
player.move();
fill(#81580D);
for (int i = 0; i < circleY.length; i++) {
float circleX = width * i / circleY.length;
ellipse(circleX, circleY[i], 50, 50);
circleY[i]++;
if (dist(mouseX, mouseY, width/2, height/2) < circleRadius + headRadius) {
circleY[i] = 0;
}
}
}
Player class
class Player {
int x;
int y;
int dx = (int) random( -3, 3);
int dy = (int) random( -3, 3);
Player( int newX, int newY, int newRadius) {
x = newX;
y = newY;
}
void display() {
//helmet
fill(#81F1FF);
ellipse (mouseX, mouseY, 40, 40);
//head
fill(#EAD2A3);
ellipse (mouseX, mouseY, 30, 30);
//eyes
fill(#FFFEFC);
ellipse (mouseX-7, mouseY, 15, 15);
ellipse (mouseX+2, mouseY, 15, 15);
//pupils
fill(#120C00);
ellipse (mouseX - 9, mouseY, 5, 5);
ellipse (mouseX + 2, mouseY, 5, 5);
//eyebrows
fill(#EAD2A3);
arc(mouseX - 7, mouseY - 9, 20, 10, HALF_PI, PI);
arc(mouseX + 3, mouseY - 9, 20, 10, HALF_PI, PI);
//jetpack
fill(#22727C);
stroke(10);
rect(mouseX - 23, mouseY + 25, 10, 20);
ellipse(mouseX - 23, mouseY + 20, 20, 20);
ellipse(mouseX - 23, mouseY + 20, 10, 10);
ellipse(mouseX - 23, mouseY + 20, 1, 1);
line(mouseX - 23, mouseY + 10, mouseX - 23, mouseY -25);
fill(#FF0004);
ellipse(mouseX - 23, mouseY - 25, 10, 10);
//fire
fill(#F59607);
triangle(mouseX - 23, mouseY + 45, mouseX - 13, mouseY + 45, mouseX - 23, mouseY + 80);
fill(#FEFF1A);
triangle(mouseX - 23, mouseY + 45, mouseX - 13, mouseY + 45, mouseX - 23, mouseY + 60);
//torso
fill(#22727C);
stroke(30);
strokeWeight(2);
rect(mouseX - 11, mouseY +10, 20, 40);
rect(mouseX - 11, mouseY +10, 20, 30);
rect(mouseX - 11, mouseY +10, 20, 20);
rect(mouseX - 11, mouseY +10, 20, 10);
}
void move() {
x += dx;
y += dy;
}
}
I want the player to ācatchā the balls. The balls should respawn at the top of the screen when they collide with the players head.
I would really appreciate your help because I am awful at processing. Thanks in advance!