This site requires JavaScript, please enable it in your browser!
Greenfoot back
LukaMoon
LukaMoon wrote ...

2020/5/20

I want to make a bullet be able to affect the lives of both heros in multiplayer mode!

LukaMoon LukaMoon

2020/5/20

#
public class EnemyBullet extends Enemy
{
    int MOVE_VAL = 4;
    int BULL_SIZE = 25;
    
    // // This is the constructor of the EnemyBullet
    public EnemyBullet()
    {
        getImage().scale(BULL_SIZE, BULL_SIZE);
    }
    /**
     * Act - do whatever the EnemyBullet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        // This makes the bullet move
        setLocation(getX(), getY() + MOVE_VAL);
        
         // this determines whether the bullet hits the enemy and removes it 
        Mizuki m = (Mizuki) getOneIntersectingObject(Mizuki.class);
        Bunker b = (Bunker) getOneIntersectingObject(Bunker.class);
        if (m != null)
        {
          // Decrease Mizuki's life count by 1
          m.lives--;
          getWorld().removeObjects(getWorld().getObjects(MizukiLife.class));
          // Redraw Mizuki's ships
          for (int x = 0; x < m.lives; x++)
          {
                getWorld().addObject(new MizukiLife(),44 + 80*x,909);
            }
          // Removes Mizuki and goes to the lose screen if out of lives
          if (m.lives == 0)
          {
           getWorld().removeObject(m); 
           Greenfoot.setWorld(new SinglePlayerLose());
          }
          // Remove the enemy bullet
          getWorld().removeObject(this);  
        }
        // this determines if the bullet hit a bunker
        else if (b != null)
        {
          getWorld().removeObject(b); 
          getWorld().removeObject(this);  
        }
        // this makes the bullet disappear once it reaches the border
        else if (getY() > 940) 
        {
          getWorld().removeObject(this);   
        }
        
    }    
}
Hi! extremely new to programming I'm completing a school project and I'm trying to get the current enemy bullet class that I used in the single player mode, to also affect the lives of Miyano, the second player. How would I do this? Both controllable actors would be on at the same time. I also want to make it go to a different ending screen, but the enemies will still be the same
danpost danpost

2020/5/20

#
The world should detect game over. The players should detect enemy bullets (not the other way around). Also, EnemyBullet instances are not Enemy instances. The one class should not extend the other.
LukaMoon LukaMoon

2020/5/20

#
How would I do that?
You need to login to post a reply.