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

2014/6/23

Ending the game at zero lives

Svek Svek

2014/6/23

#
Hey i really need some help and fast! Sorry for the rush but i have an exam tommorow where i need to know this. So this is the problem I want to end my game and switch to the EndWorld if lives are 0 this is my code:
 public void checkPlayer()
    {
        setLocation (getX(), getY() +2);
        if(isTouching(Player.class))
        {
            GameWorld myWorld = (GameWorld) getWorld();
            myWorld.getLifeCounter().add(-1);
            myWorld.removeObject(this);
        }

        else if (getY()> getWorld().getHeight()-5){
            getWorld().removeObject(this);

        }

    }
please please help me out!!
danpost danpost

2014/6/23

#
In the 'if(isTouching(Player.class))' block, after line 7, you need to ask 'if the "new" current value of the life counter is zero, set a new end game world as the active world'.
You need to login to post a reply.