I want to make my character change his appearance when I move so that he faces where he goes.
how do I do this?
Player code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player extends characters
{
/**
* Act - do whatever the Mario wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
move();
}public void move()
{if (Greenfoot.isKeyDown("left"))
{
move(-5);
if (isTouching(Wall.class))
{
move(5);
}
}
if (Greenfoot.isKeyDown("right"))
{
move(5);
if (isTouching(Wall.class))
{
move(-5);
}
}
if (Greenfoot.isKeyDown("up"))
{
setLocation(getX(), getY()-5);
if (isTouching(Wall.class))
{
setLocation(getX(), getY()+5);
}
}
if (Greenfoot.isKeyDown("down"))
{
setLocation(getX(), getY()+5);
if (isTouching(Wall.class))
{
setLocation(getX(), getY()-5);
}
}
if ( isTouching(Collectibles.class) ) {
removeTouching(Collectibles.class);
}
if ( isTouching(End.class) ) {
removeTouching(End.class);
Greenfoot.setWorld(new Level1());
}
if ( isTouching(End2.class) ) {
removeTouching(End2.class);
Greenfoot.setWorld(new Level3());
}
if ( isTouching(Enemy.class) ) {
removeTouching(Enemy.class);
Greenfoot.setWorld(new Level2());
}
}
}