Hello I'm making a sonic styled game. My sonic can move 4 different directions which are up, down, left and right. Using the arrows you can move sonic around. Now i only have a picture for sonic running from left to right. I want to have 4 different pictures, one picture for each direction. How to do this?
import greenfoot.*;
/**
* Write a description of class sonic here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class sonic extends dier
{
private int muntjeGegeten = 0;
/**
* Act - do whatever the sonic wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.isKeyDown("left")) {
setRotation(180);
move(3);
}
if (Greenfoot.isKeyDown("up")) {
setRotation(270);
move(3);
}
if (Greenfoot.isKeyDown("right")) {
setRotation(0);
move(3);
}
if (Greenfoot.isKeyDown("down")) {
setRotation(90);
move(3);
}
tryToEat();
if (Greenfoot.isKeyDown("space")) {
World world = getWorld();
Lazer Lazer = new Lazer();
Lazer.setsonic(this);
world.addObject(Lazer, getX(), getY());
}
}
public void tryToEat()
{
if (canSee(muntje.class) )
{
eat(muntje.class);
muntjeGegeten++;
Greenfoot.playSound ("Ooh he stealing!.mp3");
World1 world = (World1)getWorld(); //casting
world.updateScore();
}
}
public void checkVijand1()
{
if (canSee(Vijand1.class) )
{
Greenfoot.playSound("game-over.wav");
Greenfoot.stop();
}
}
}
