Greenfoot Flashcards
Code to check if the right keyboard arrow has been pressed
if (Greenfoot.isKeyDown (“Right”))
{
}
Code to make an object point right
setRotation (0) ;
Code to make an object point down
setRotation (90) ;
Code to make an object point left
setRotation (180) ;
Code to make an object point up
setRotation (270) ;
Code to make an object move forward 1 space
move (1) ;
Code to play a sound file called “pop.wav”
Greenfoot.playSound (“pop.wav”) ;
Code to Generate a random number between 0-100
Greenfoot.getRandomNumber (100) ;
Code to check if an object is at the edge of the world
if (isAtEdge())
{
}
Code to make an object turn 45 degrees
turn (45) ;
Code to check if the object is touching another (e.g. touching an object with the class name Snake)
if(isTouching(Snake.class))
{
}
Code to remove an object from the game world that the object is touching (for example removing an object with the class name Heart)
removeTouching(Heart.class) ;
Code to stop the program
Greenfoot.stop() ;
Code to add 1 to the counter from another character
Counter counter = (Counter)getWorld().getObjects(Counter.class).get(0) ;
counter.add(1) ;
Code to make the character turn a random angle between -45 and 45
turn(Greenfoot.getRandomNumber (90) -45);