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

2020/4/7

I need help too

Dominic Dominic

2020/4/7

#
Hi, so i am making a game where a man in space walks around and shoot monsters. I am trying to give him lives. So when he gets hit by a monster (worm), he will lose a life (Heart1). Right now he dies after hitting three mosnters. But i want to show it some how. I have a heart, that i want to go away, when he has lost a live. Thx in advance.
private int hearts = 3;
    public void losingHealth()
    {
        Actor worm = getOneIntersectingObject(worm.class);
        Healthbar heart1 = new Healthbar();
        getWorld().addObject(heart1, 200, 200);

        if (worm != null)
        {
            getWorld().removeObject(worm);
            hearts--;
        }
        if (hearts == 2)
        {
            getWorld().removeObject(heart1);
        }
        if (hearts == 0)
        {
            getWorld().removeObject(this);
        }
danpost danpost

2020/4/7

#
Dominic wrote...
Hi, so i am making a game where a man in space walks around and shoot monsters. I am trying to give him lives. So when he gets hit by a monster (worm), he will lose a life (Heart1). Right now he dies after hitting three mosnters. But i want to show it some how. I have a heart, that i want to go away, when he has lost a live. << Code Omitted >>
Please refer to my Value Display Tutorial scenario. It show how to represent values graphically (using a set of images).
Dominic Dominic

2020/4/7

#
Danpost. Sorry, but i have read your tutorial, and i don't see how it can help me. I need the code to remove an object and i just don't know how.
danpost danpost

2020/4/7

#
Dominic wrote...
Danpost. Sorry, but i have read your tutorial, and i don't see how it can help me. I need the code to remove an object and i just don't know how.
Look at Non-textual representations of a value. At the bottom is a link for A simple counting set object. That will show you the way to handle it. Instead of removing objects, it simply uses one object to represent the changing count.
Dominic Dominic

2020/4/8

#
oh thank you :)
You need to login to post a reply.