How to Make the Eye Monsters Disappear?

I'm making a simple space invader clone. I got everything down except making the eye monsters disappear after getting hit. I'm using a for-loop for drawing them.

Here's the code:

   void setup(){
      size(500,500);

    }

    void draw(){
      frameRate(60);
      clear();
      spaceBackground();
      spaceship();
       for(int i=0;i<9;i++){
        for(int j=0; j<1; j++){
          enemies(50*i+50,50*j+50);
      }
     }

      if (mousePressed){
        clicked = 1;
      }

      if (clicked == 1){
        xPos = mouseX;
        bullet();
        bulletSpeed();
        if (yPos <= 0){
         yPos = 375;
         clicked = 0;
        }
      }
    }

    void spaceship(){// draws spaceship
      noStroke();
      fill(255,0,0);
      triangle(mouseX,390,mouseX-30,460,mouseX+30,460);
      fill(255,255,0);
      triangle(mouseX-15,420,mouseX-30,460,mouseX-15,460);
      fill(255,255,0);
      triangle(mouseX+15,420,mouseX+30,460,mouseX+15,460);
      fill(0,0,255);
      ellipse(mouseX,435,20,20);
      fill(255);
      ellipse(mouseX+3,435-5,6,6);
    }

    void spaceBackground(){ //draws starry background
      for(int i=0;i<20;i++){
        for(int j=0;j<20;j++){
          strokeWeight(2);
          stroke(random(255), random(255),random(255));
          point(random(0,width),random(0,height));
        }
      }
    }

    float yPos=375;
    float ySpeed=50;

    void bulletSpeed(){//functions that adds vertical speed to the bullets
     yPos=yPos-ySpeed;
    }



    void bullet(){//draws bullet
      for(int i=5;i>0;i--){
        noStroke();
        fill(i*50,i*50,255);
        ellipse(xPos,yPos,i*5,i*5);
      }
    }

    void enemies(int xPos, int yPos){//draws eye aliens
      stroke(0);
      fill(255);
      strokeWeight(1);
      ellipse(xPos,yPos,40,40);
      fill(255,0,0);
      ellipse(xPos,yPos,20,20);
      strokeWeight(4);
      point(xPos,yPos);
      stroke(255);
      point(xPos+3,yPos-3);
    }

Sorry about the really bad layout. I'm new to these things.

Tagged:

Answers

  • Answer ✓

    edit post, highlight the code, press ctrl-o to format.

  • you'll need to delete all the backticks you've already added.

  • Please check previous posts related to your problem. You will need an array list to keep track of your bullets and other objects. You can find related discussions here: https://forum.processing.org/two/search?Search=bullet

    If you browse few of those post, you might find one that shows the proper approach.

    Kf

Sign In or Register to comment.