I am making a game where a "knight" will go up a lane and attack another object, like Clash Royal. My issue is that I need it to attack and the way that I thought of to do it was to save the object that the knight intersected with first, then have another method that would get that object and reduce its health. I don't know how to save the object that the knight intersected and how to get its health variable. This is my code so far...
Any help would be appreciated. Thanks!
public void attack()
{
//possibly make the attack here?
}
public void playerMove() //move the player if it doesn't intersect another actor
{
moveTimer++; //time to wait to move
Actor c = (Actor)getOneIntersectingObject(Actor.class); //get intersecting object
if(moveTimer == 20) //how long until it acts, 20 act cycles
{
if(c == null) //if it hasn't touched anything
{
setLocation(getX(), getY() - 1); //move up one cell
moveTimer = 0; //reset timer to act again
}
else //if it has touched something
{
moveTimer = 0; //reset timer to act again
}
}
}