This site requires JavaScript, please enable it in your browser!
Greenfoot back
kasperk22
kasperk22 wrote ...

2014/1/26

Difficulty levels in game (setspeed)

kasperk22 kasperk22

2014/1/26

#
Hey guys... i'm trying to add difficulty into my game, but even though i get no errors or anything else, it seems not to be working. Here's my code:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class Instructions here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Instructions extends Actor
{
public Instructions()
{
    setImage ( new GreenfootImage("Difficulty levels: Justin Bieber (e), Normal (n), INSANE!!! (h)", 50, Color.RED, Color.GREEN));
    difficulty();
}

public void difficulty()
{
    if(Greenfoot.isKeyDown("e"))
    {
        Greenfoot.setSpeed(40);
    }
    else if(Greenfoot.isKeyDown("n"))
    {
        Greenfoot.setSpeed(50);
    }
    else if(Greenfoot.isKeyDown("h"))
    {
        Greenfoot.setSpeed(60);
    }
}
}
danpost danpost

2014/1/26

#
You have line 14 in the wrong place. No keystrokes can be detected until the scenario has started and the constructor is executed before the scenario starts. Create an act method for the world class and move line 14 into it.
kasperk22 kasperk22

2014/1/26

#
oh like that... thanks alot! :D
You need to login to post a reply.