Is it possible to can one objects img from another object when they interact then get rid of it with a counter?
I would like to change the hollow to a pow then to nothing, but as it stands my img will change but the wrong object, when I tried to put the same code into the hollow object it would change but not go away and my counter was messed up.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class YuruichiSit here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Yuruichi extends Support
{
private int hollowKilled;
private int imgCounter;
public Yuruichi()
{
hollowKilled = 0;
imgCounter = 50;
}
/**
* Act - do whatever the YuruichiSit wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
fightHollow();
}
public void move()
{
if (Greenfoot.isKeyDown("up"))
{
setLocation(getX() ,getY() -1);
}
if (Greenfoot.isKeyDown("down"))
{
setLocation(getX() ,getY() +1);
}
if (Greenfoot.isKeyDown("right"))
{
setLocation(getX() +2,getY() );
setImage("YuruichiRunRight.png");
}
if (Greenfoot.isKeyDown("left"))
{
setLocation(getX() -2,getY() );
setImage("YuruichiRun.png");
}
}
public void fightHollow()
{
Actor Hollow = (Hollow) (getOneObjectAtOffset(0, 0, Hollow.class));
if (Hollow != null)
{
//hollowKilled ++;
//setImage("comicpunch.png");
//remove(Hollow.class);
if (imgCounter == 0 )
{
remove(Hollow.class);
setImage("comicpunch.png");
hollowKilled ++;
}
else
{
imgCounter --;
}
}
}
}