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

2020/6/21

Adding Lives This is very urgent so please help asap!

1
2
3
4
soumya.__.khanna soumya.__.khanna

2020/6/21

#
Same thing
danpost danpost

2020/6/21

#
soumya.__.khanna wrote...
Same thing
Just for clarity, change line 21 in Worlds class to:
checkLife();
and then replace the method with:
public void checkLife()
{
    int lives = Hero.getLives();
    if (lives == 4) removeObject(life4); 
    if (lives == 3) removeObject(life3);
    if (lives == 2) removeObject(life2);
    if (lives == 1) removeObject(life1);
    if (lives == 0) removeObject(life0);
}
(a switch block might be an improvement here)
soumya.__.khanna soumya.__.khanna

2020/6/21

#
Still didn't remove the hearts
soumya.__.khanna soumya.__.khanna

2020/6/21

#
Updated World Class
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
 * The parent class of worlds
 * 
 * @soumya.__.khanna (Soumya Khanna) 
 * @I'llLookItUp (Jun 17th, 2020)
 */
public class Worlds extends World
{
    public int width = getWidth(); //Width of the world --Accessed in children classes
    public static Hero mario = new Hero(); //Declaring the Swimming Mario Class
    //Number of hearts based on the life of Mario
    public Life life0;
    public Life life1;
    public Life life2;
    public Life life3;
    public Life life4;
    public Score score; //Adding the score board 
    public void act()
    {
        checkLife();
    }
    public Worlds()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(2200, 576, 1, false);
    } 
    public void lifeCounter(int x, int y)
    {
        //Declaring all lives
        life0 = new Life();
        life1 = new Life();
        life2 = new Life();
        life3 = new Life();
        life4 = new Life();
        //Adding lifes evenly spaced around
        addObject(life0, x, y);
        addObject(life1, x + 30, y);
        addObject(life2, x + 60, y);
        addObject(life3, x + 90, y);
        addObject(life4, x + 120, y);
    }
    public void checkLife()
    {
        int lives = Hero.getLives();
        if (lives == 4) removeObject(life4); 
        if (lives == 3) removeObject(life3);
        if (lives == 2) removeObject(life2);
        if (lives == 1) removeObject(life1);
        if (lives == 0) removeObject(life0);
    }
    public Score getScore()
    {
        return score; //Information from scoreboard
    }
}
danpost danpost

2020/6/21

#
soumya.__.khanna wrote...
Still didn't remove the hearts
Remove one line, 35 or 36, from WaterWorld class.
You need to login to post a reply.
1
2
3
4