I'm creating a maze game where the walls are 4 different colors that I choose when I make the object in the world.
I also have a player class and I want it to work so that when the player is at an offset of 5 pixels to check what color of the wall it's close to and make it so that all of the walls in the maze of that color glow.
What I have so far that isn't working:
Navigator class
public void act()
{
useOffsets();
examineKeysPressed();
}
public void examineKeysPressed()
{
if ( Greenfoot.isKeyDown("left") && getOneObjectAtOffset( -5,0, Barrier.class ) == null )
{
setLocation( getX() - 2, getY() );
}
else if ( Greenfoot.isKeyDown("right") && getOneObjectAtOffset( 5,0, Barrier.class ) == null )
{
setLocation( getX() + 2, getY() );
}
if ( Greenfoot.isKeyDown("up") && getOneObjectAtOffset( 0,-5, Barrier.class ) == null )
{
setLocation( getX() , getY() - 2 );
}
else if ( Greenfoot.isKeyDown("down") && getOneObjectAtOffset( 0,5, Barrier.class ) == null )
{
setLocation( getX() , getY() + 2 );
}
}
public void useOffsets()
{
Barrier barrier = (Barrier)getOneObjectAtOffset( -5,0, Barrier.class );
if ( barrier.getImage().getColor() == Color.RED )
{
barrier.glow();
}
/*if ( getOneObjectAtOffset( 5,0, Barrier.class ) != null )
{
examineOffsets();
}
if ( getOneObjectAtOffset( 0,-5, Barrier.class ) != null )
{
examineOffsets();
}
if ( getOneObjectAtOffset( 0,5, Barrier.class ) != null )
{
examineOffsets();
}*/
}
I'm getting a null pointer exception with the getColor() code.
I think I need to use a list
Any help please.

