Here is my code, but I am also having trouble displaying the hearts.
MAIN:
Heart[] drops; // An array of heart objects
int totalDrops = 0; // totalDrops
float r;
//arrow
Arrows[] spikes;
int index =0;
void setup() {
size(500,500);
smooth();
spikes = new Arrows[50];
drops = new Heart[100]; // Create 100 spots in the array
}
void draw() {
background(255);
for (int i = 0; i < spikes.length; i++) {
if (spikes[i] != null) {
spikes[i].display();
spikes[i].shoot();
}
}
for (int i=0; i< totalDrops; i++) {
drops[i].move();
drops[i].display();
}
}
void mousePressed() {
//shoot arrow
spikes [index] = new Arrows (mouseX, mouseY, 1);
index = (index + 1) % (50);
}
HEART CLASS:
class Heart {
float x,y; // Variables for location of heart
float speed; // Speed of heart
color c;
float r; // Radius of heart
Heart() {
r = 8; // All hearts are the same size
x = random(width); // Start with a random x location
y = -r*4; // Start a little above the window
speed = random(3,9); // Pick a random speed
c = color(255,0,0); // Color
}
// Move the heart down
void move() {
// Increment by speed
y += speed;
}
// Display the heart
void display() {
// Display the heart
fill(c);
noStroke();
for (int i = 2; i < r; i++ ) {
smooth();
beginShape();
vertex(x+50, y+15);
bezierVertex(x+50, y-5, x+90, y+5, x+50, y+40);
vertex(x+50, y+15);
bezierVertex(x+50, y-5, x+10, y+5, x+50, y+40);
endShape();
}
}
// If the Heart is caught
void caught() {
// Stop it from moving by setting speed equal to zero
speed = 0;
// Set the location to somewhere way off-screen
y = - 1000;
}
}
ARROW CLASS:
class Arrows {
//Stating variables: color, x and y position
color c;
float x;
float y;
float r;
//Defining and renaming variables to make it work; fill in these spaces in actual program
Arrows (float xpos, float ypos, float tempR) {
c = color (146, 77, 79);
x = xpos;
y = ypos;
r = tempR;
}
//Display function, defining xposition and yposition variables
void display () {
//How to make arrows - stick
fill(c);
smooth ();
rectMode(CORNERS);
rect(x+15, y, x+25, y+70);
//line(x+20, y, x+20, y+65);
triangle(x,y,x+20,y-20,x+40,y);
}
void shoot () {
//Speed Variables
y = y - 3;
// xposition = xposition + xspeed;
if (x > width) {
x = 0;
}
}
}