I put the line into the code, but instead of the images loading, it is only showing a green foot logo
Here is the revised Hero class code.
public class Hero extends Mover
{
String imgSet;
GreenfootImage[] images = new GreenfootImage[8];
private static final int jumpStrength = 20;
private int level;
private int jumped = 0;
public Hero()
{
changeImage(1);
level = 1;
}
public void changeImage (int x)
{
if (x == 1)
{
imgSet = "wizard_1";
}
else if (x == 2)
{
imgSet = "princess";
}
else if (x == 3)
{
imgSet = "goblin_2";
}
else if (x == 4)
{
imgSet = "barbarian_1";
}
for (int i=0; i<8; i++)
images[i] = new GreenfootImage(imgSet+"_run_00"+(i+1)+".png");
}
public void act()
{
if (getWorld() instanceof CharSelect) return;
checkKeys();
checkFall();
checkNextLevel();
landOnTop();
}
private void checkKeys()
{
if (Greenfoot.isKeyDown("left") )
{
moveLeft();
}
if (Greenfoot.isKeyDown("right") )
{
moveRight();
}
if (Greenfoot.isKeyDown("up") )
{
if (onGround())
jump();
}
}
private void jump()
{
vSpeed= -jumpStrength;
fall();
jumped++;
}
public void landOnTop()
{
if (isTouching(Ground.class))
{
setLocation(getX(), getY() - 1);
}
}
private void checkFall()
{
if (onGround()) {
setVSpeed(0);
}
else {
fall();
}
}
/**
* Check whether we should go to the next level, and if yes, start the next level.
*/
private void checkNextLevel()
{
if (getX() == getWorld().getWidth()-1) {
if (level == 1) {
level = 2;
getWorld().removeObject(this);
Greenfoot.setWorld(new Level2(this));
}
else {
level = 1;
getWorld().removeObject(this);
Greenfoot.setWorld(new Level1(this));
}
}
}
}
