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

2012/12/13

adding a shield

1
2
3
davemib123 davemib123

2012/12/16

#
ace, vonmeth your a star :)
GamesGrinder1998 GamesGrinder1998

2014/4/27

#
vonmeth wrote...
Add checks for that boolean. If that boolean is true, don't let certain things happen (like take a hit). For example to make it so enemy fire doesn't harm your Hero. First make your boolean shieldActive static.
    public void checkHeroCollision(){
        Actor collided = getOneIntersectingObject(Hero.class);
        if (collided != null){
            City cityWorld = (City) getWorld();  // get a reference to the world
            if(!Hero.shieldActive){ // is your hero shield not active? Then take damage
            Bar bar = cityWorld.getBar();  // get a reference to the counter
            bar.subtract(10);
            }
            getWorld().addObject(new explosionSmall(), getX(), getY());
            getWorld().removeObject(this);
            return;
        } else {
            if (getX() <= - outOfBoundary) {
                getWorld().removeObject(this);
            } 
        }
    }
Just include an else after the 'if' if you wish for the shield to have health, and subtract from it for each hit.
how could i use this code in my code
You need to login to post a reply.
1
2
3