//In VikingLifeEater class
public void removeLife()
{
if( this.isTouching(Life.class) )
{
this.removeTouching(Life.class);//remove the Life class that the Life Eater is touching
count++;// increment by 1 each life that was eaten
}
}
//In Viking class
public void hit()
{
MyWorld world = (MyWorld) getWorld();
if(this.isTouching(Sword.class) ) //checks whether Viking has been hit by a sword
{
VikingLifeEater v = new VikingLifeEater();
world.addObject(v, vikingX, 40); //position lifeEater to eat life
vikingX += 50; //updates position to next Life
}
}
private int vikingX = 40;
