Hey, i am trying to make a game, on the main menu screen you select your difficulty, e.g easy, you will have 5 lives and they will show up as hearts in the top left corner of the game, but when i pick medium or hard they will be moved a bit to the right, does anyone know why is that?
import greenfoot.*; public class HealthBar extends Actor { private int health; public HealthBar(int initialHealth) { this.health = initialHealth; update(); } public void update() { GreenfootImage image = new GreenfootImage(50 * health, 50); image.clear(); for (int i = 0; i < health; i++) { GreenfootImage heart = new GreenfootImage("heart.png"); heart.scale(40, 40); image.drawImage(heart, i * 45, 5); } setImage(image); } public void loseHealth() { if (health > 0) { health--; update(); } } public boolean isAlive() { return health > 0; } } import greenfoot.*; public class Dungeon extends World { private Player player; private HealthBar healthBar; public Dungeon(int difficulty, int initialHealth) { super(600, 400, 1); player = new Player(difficulty); addObject(player, 300, 200); populateMonsters(); } public Dungeon(int initialHealth) { super(800, 600, 1); healthBar = new HealthBar(initialHealth); addObject(healthBar, 125, 30); } private void populateMonsters() { for (int i = 0; i < 10; i++) { addObject(new Monster(), Greenfoot.getRandomNumber(getWidth()), Greenfoot.getRandomNumber(getHeight())); } addObject(new Boss(), 500, 300); } public void act() { if (getObjects(Monster.class).isEmpty()) { } } public Player getPlayer() { return player; } } import greenfoot.*; public class Button extends Actor { private String text; private int difficulty; public Button(String text, int difficulty) { this.text = text; this.difficulty = difficulty; updateImage(); } private void updateImage() { GreenfootImage image = new GreenfootImage(text + " - Click to start", 24, Color.WHITE, Color.BLACK); setImage(image); } public void act() { if (Greenfoot.mouseClicked(this)) { int initialHealth = (difficulty == 1) ? 5 : ((difficulty == 2) ? 3 : 1); Greenfoot.setWorld(new Dungeon(initialHealth)); } } } import greenfoot.*; public class MainMenu extends World { public MainMenu() { super(600, 400, 1); prepare(); } private void prepare() { addObject(new Button("Easy", 1), 300, 150); addObject(new Button("Medium", 2), 300, 200); addObject(new Button("Hard", 3), 300, 250); } }