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

2017/5/10

How do I add 100 health every time my snowman collects an igloo

jbush15 jbush15

2017/5/10

#
public class Health extends Actor
{
    public int Health = 800;

    public void act() 
    {

        {
            setImage(new GreenfootImage("Health : " + Health, 24, Color.GREEN, Color.BLACK));
            Health --;
        }    

        if (Health == -1)
        { Greenfoot.stop();
        }    
    }
jbush15 jbush15

2017/5/10

#
Right now I just have
{if (isTouching(Igloo.class))
            { removeTouching(Igloo.class);
                Greenfoot.playSound("slurp.wav");
                igloosCollected = igloosCollected + 1;
                Health = Health + 100;
danpost danpost

2017/5/10

#
You need to get a reference to the Health object in the world and adjust its value:
Health health = (Health)getWorld().getObjects(Health.class).get(0));
health.Health = health.Health+100;
(replace line 5 with these two lines).
You need to login to post a reply.