I tried to make the lives variable in the world and have the actors access it from there but it doesn't work. This is my code in the World.
and this is my code in the actor
My goal is to have three heart actors disappear as life decreases and a player actor that decreases life when they get hit. Can someone please help?
public class Sea extends World { public Sea() { super(1350, 700, 1); addObject(new Player(), getWidth()/2, getHeight()/2); for(int count=1; count<=10; count=count+1) { addObject(new Fish(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight())); } int life = 3; addObject(new Life1(), getWidth()/50,getHeight()*25/26); addObject(new Life2(), getWidth()/50+55,getHeight()*25/26); addObject(new Life3(), getWidth()/50+110,getHeight()*25/26); } }
public class Life3 extends Actor { int life = ((Sea) getWorld()).life; public void act() { } }