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

2013/5/23

I need help please

manish1 manish1

2013/5/23

#
Hello, i am currently working on a tank game but need help with the health bar for the walls, currently i have this: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class wall here. * * @author (your name) * @version (a version number or a date) */ public class wall extends Actor { private int wallHealth_; /** * Act - do whatever the wall wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public wall() { wallHealth_ = 5; } public void act() { checkHealth(); checkDestroy(); } public boolean collides() { if(getOneIntersectingObject(BouncingBullet.class)!=null); return true; } public void checkHealth() { if(collides()) { wallHealth_--; } } public void checkDestroy() { if (wallHealth_ == 0) { World world; world = getWorld(); world.removeObject(this); } } } But the wall gets destroyed in one hit
bourne bourne

2013/5/23

#
Try removing the BouncingBullet: (or does this Object "bounce" off and so would be undesirable?)
public boolean collides()
{
    Object o = getOneIntersectingObject(BouncingBullet.class);
    if (o == null)
        return false;
    getWorld().removeObject(o);
    return true;
}
manish1 manish1

2013/5/23

#
no i called it bouncing bullet because it bounces off the edge of the screen sorry for the confusion but i will try that code
bourne bourne

2013/5/23

#
Just checked the Greenfoot API, change "Object" to "Actor"
public boolean collides()  
{  
    Actor a = getOneIntersectingObject(BouncingBullet.class);  
    if (a == null)  
        return false;  
    getWorld().removeObject(a);  
    return true;  
}  
manish1 manish1

2013/5/23

#
at getWorld().removeObject(o); it gives me a an error and says required greenfoot.Actor found: java.lang.Class<wall>
manish1 manish1

2013/5/23

#
*found: java.lang.Object
bourne bourne

2013/5/23

#
Refer to my last comment. Sorry about that.
manish1 manish1

2013/5/23

#
oh i see... oops i refreshed the page just now
You need to login to post a reply.