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

2017/1/23

Why isn't my health reducing?

1
2
danpost danpost

2017/1/25

#
Jillis wrote...
Thanks dan for your help. And yes, I commented out those lines, and the healthbar executed once on each startup.
Was 'hitEnemy' being called from the User act method? (you can uncomment those lines -- now that we know that the health bar is working properly).
Jillis Jillis

2017/1/25

#
For some reason my Greenfoot has stopped working! :( When I open it from my desktop, the small rectangular screen appears that says "Stride Java Greenfoot Version 3.0.4" and a loading bar, but nothing is happening, I reinstalled it, and my Java is up to date, any more ideas? Edit: After 10 mins of loading the firewall error thing popped up, I've disabled all firewall on my computer but still no luck. I will be back later and try to fix it again:)
Jillis Jillis

2017/1/25

#
hitenemy is not called in the act method for my user:
public void act() 
    {
        String key = Greenfoot.getKey();
        if (Greenfoot.isKeyDown("a"))
        {
            setRotation(180);
            if (GetObjectInFront(Wall.class)==null)
            move(10);
        }
        if (Greenfoot.isKeyDown("d"))
        {
            setRotation(0);
            if (GetObjectInFront(Wall.class)==null)
            move(10);
        }
        if (Greenfoot.isKeyDown("w"))
        {
            setRotation(270);
            if (GetObjectInFront(Wall.class)==null)
            move(10);
        }
        if (Greenfoot.isKeyDown("s"))
        {
            setRotation(90);
            if (GetObjectInFront(Wall.class)==null)
            move(10);
        }
        if ("left".equals(key))
        {
            setRotation(180);
            fire();
        }
        if ("right".equals(key))
        {
            setRotation(0);
            fire();
        }
        if ("down".equals(key))
        {
            setRotation(90);
            fire();
        }
        if ("up".equals(key))
        {
            setRotation(270);
            fire();
        }
    }
Super_Hippo Super_Hippo

2017/1/25

#
Well, I think it should be called from the act method or it will never get executed...
//after line 47
hitEnemy();
Jillis Jillis

2017/1/26

#
Working! Thank you for pointing that out!
Jillis Jillis

2017/1/26

#
Also, I wanted my health to decrease bit by bit, is there a way to insert a buffer/delay to the losehealth method being called?
danpost danpost

2017/1/26

#
Jillis wrote...
Also, I wanted my health to decrease bit by bit, is there a way to insert a buffer/delay to the losehealth method being called?
You already have it so that the enemy must be untouched before a second health unit is removed by touching again. Are you wanting to change that behavior so that if the enemy is touching for an extended amount of time that health is reduced more?
Jillis Jillis

2017/1/29

#
Well basically what is happening currently, is that it's too difficult to move away in time, it just appears to decrease completely at once. You intersect the enemy and the health reduces very quickly. I have just realised while writing this that increasing the health may fix this.
Super_Hippo Super_Hippo

2017/1/29

#
Did you change anything in the 'hitEnemy' method?
You need to login to post a reply.
1
2