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

2015/4/9

Player not resetting

Salcrainia Salcrainia

2015/4/9

#
I don't want to have to remove the character from the world because it causes an issue with the lives and the points. Any suggestions would be appreciated :)
/**
     * This causes the mobs to kill the player upon collision and forces the player to lose a life
     */
    public void killed()
    {
        Player player = new Player();
        World world = getWorld();
        if(detect(Mob.class))
        {
            loseLife();
            player.setLocation(30, 335);
        }
    }
The lose life module also has nothing to do with the players position it just removes one life from them.
Salcrainia Salcrainia

2015/4/9

#
Never mind this works perfectly fine :)
/**
     * This causes the mobs to kill the player upon collision and forces the player to lose a life
     */
    public void killed()
    {
        Player player = new Player();
        World world = getWorld();
        if(detect(Mob.class))
        {
            loseLife();
            world.removeObject(this);
            world.addObject(player, 30, 335);
        }
    }
danpost danpost

2015/4/10

#
You could simplify things by just setting the location of the player already in the world (instead of removing it and adding a new one):
public void killed()
{
    if (detect(Mob.class))
    {
        loseLife();
        setLocation(30, 335);
    }
}
You need to login to post a reply.