help with removal of hearts
in
Programming Questions
•
1 year ago
Hey guys, I'm doing a game as a schoolproject where u are supposed to catch some things falling, and I want to have hearts that indicates that you have missed an item. I have manage to make one heart dissapear. But the other two hearts i dont know how to remove, i have tried different things...but it hasnt worked.
so please help me out!
- Heart heartOne;
- Heart heartTwo;
- Heart heartThree;
- Catcher catcher; // One catcher object
- Timer timer; // One timer object
- Drop _drops;
- Drop[] drops; // An array of drop objects
- int totalDrops = 0; // totalDrops
- int xValue = 200;
- void setup() {
- size(400, 400);
- smooth();
- catcher = new Catcher(32); // Create the catcher with a radius of 32
- drops = new Drop[1000]; // Create 1000 spots in the array
- timer = new Timer(1500); // Create a timer that goes off every 2 seconds
- timer.start(); // Starting the timer
- heartOne = new Heart(382, 20, 20, 20);
- heartTwo = new Heart(360, 20, 20, 20);
- heartThree = new Heart(338, 20, 20, 20);
- }
- void draw() {
- background(255);
- // Set catcher location
- catcher.setLocation(xValue, 360);
- // Display the catcher
- catcher.display();
- //display heart
- heartOne.heartDisplay();
- heartTwo.heartDisplay();
- heartThree.heartDisplay();
- // Check the timer
- if (timer.isFinished()) {
- // Deal with raindrops
- // Initialize one drop
- drops[totalDrops] = new Drop();
- // Increment totalDrops
- totalDrops ++ ;
- // If we hit the end of the array
- if (totalDrops >= drops.length) {
- totalDrops = 0; // Start over
- }
- timer.start();
- }
- // Move and display all drops
- for (int i = 0; i < totalDrops; i++ ) {
- drops[i].move();
- drops[i].display();
- if (catcher.intersect(drops[i])) {
- drops[i].caught();
- }
- }
- //BOUNCE ON WALL
- if (xValue<=0)
- {
- xValue = 0;
- }
- if (xValue>=width)
- {
- xValue = width;
- }
- for (int i = 0; i < totalDrops; i++) {
- if (drops[i].reachedBottom())
- {
- heartOne.remove();
- }
- }
- }
- void keyPressed() {
- if (key == CODED) {
- if (keyCode == LEFT) {
- xValue = xValue-20;
- }
- }
- if (key == CODED) {
- if (keyCode == RIGHT) {
- xValue = xValue+20;
- }
- }
- }
- ////////
- class Drop {
- float x,y; // Variables for location of raindrop
- float speed; // Speed of raindrop
- color c;
- float r; // Radius of raindrop
- Drop() {
- r = 8; // All raindrops are the same size
- x = random(width); // Start with a random x location
- y = -r*4; // Start a little above the window
- speed = random(1,2); // Pick a random speed
- c = color(50,100,150); // Color
- }
- // Move the raindrop down
- void move() {
- // Increment by speed
- y += speed;
- }
- // Check if it hits the bottom
- boolean reachedBottom() {
- // If we go a little beyond the bottom
- if (y > height) {
- return true;
- } else {
- return false;
- }
- }
- // Display the raindrop
- void display() {
- // Display the drop
- fill(c);
- noStroke();
- for (int i = 2; i < r; i++ ) {
- ellipse(x,y + i*4,i*2,i*2);
- }
- }
- // If the drop 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;
- }
- }
- /////////////////
- class Heart {
- int xHeart;
- int yHeart;
- int wHeart;
- int hHeart;
- boolean heartCheck;
- Heart(int _x, int _y, int _w, int _h)
- {
- xHeart = _x;
- yHeart = _y;
- wHeart = _w;
- hHeart = _h;
- }
- void remove()
- {
- xHeart = 100;
- heartCheck = true;
- }
- void heartDisplay()
- {
- ellipse(xHeart, yHeart, wHeart, hHeart);
- }
- }
1