I need to make the Man object class change black on the Wall and red on the Fire, but I'm not sure how to.
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Man here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Man extends Actor
{
/**
* Act - do whatever the Man wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
checkKeyPress(); // call this method to work
}
public void checkKeyPress()
{
if (Greenfoot.isKeyDown("left"))
{
setLocation(getX()-1,getY()); // get loaction of x and y, then move -1 on x move Left
}
if (Greenfoot.isKeyDown("right"))
{
setLocation(getX()+1,getY()); // move Right
}
if (Greenfoot.isKeyDown("down"))
{
setLocation(getX(),getY()+1); // move down
}
if (Greenfoot.isKeyDown("up"))
{
setLocation(getX(),getY()-1); // move up
}
}
public boolean onFire()
{
Actor Fire = getOneObjectAtOffset( 0 , 0, Fire.class);
return Fire != null;
}
public boolean onWall()
{
Actor Wall = getOneObjectAtOffset( 0 , 0, Wall.class);
return Wall != null;
}
}