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

2018/1/28

using one actors variable in another

roonie01 roonie01

2018/1/28

#
I am trying to make a laser access my players damage variable to subtract from the damage variable when the laser hits my player class
public class Laser extends Actor
{
    
    /**
     * Act - do whatever the Laser wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        setLocation(getX()+3,getY());
        if(isAtEdge())
        {
            getWorld().removeObject(this);
        }
        if(getWorld()!=null)
        {
            if(isTouching(Player1.class))
            {
                
                
                getWorld().removeObject(this);
           }
        }
    }    
}
Yehuda Yehuda

2018/1/28

#
Why do you not just control the player's health from the player. In player, check to see if it's touching a laser, if it is then subtract health and removeTouching(Laser.class). Then, remove lines 15 - 23 in Laser. protected void removeTouching(java.lang.Class<?> cls)
roonie01 roonie01

2018/1/28

#
thank you
You need to login to post a reply.