Methods and Functions Flashcards
Check if the right keyboard arrow has been pressed
if (Greenfoot.isKeyDown(“Right”))
{
}
Make an object point right
setRotation (0);
Make an object point down
setRotation (90);
Make an object point left
setRotation (180);
Make an object move forward 1 space
move (1);
Make an object point up
setRotation (270);
play a sound file called “pop.wav”
Greenfoot.playSound (“pop.wav”)
Generate a random number between 0-100
Greenfoot.getRandomNumber (100);
Return a true / false value when an object is at the edge of the world
if (isAtEdge())
{
returnFalse
}
Make an object turn 45 degrees
turn (45);
Return true or false if the object is touching another (e.g. touching an object of a class called “Snake.class”)
if (isTouching(Snake.class))
{
}
Remove an object from the game world that the object is touching (for example, Heart.class)
removeTouching(Heart.class);
Stop code
Greenfoot.stop();
Add 1 to the counter from another character
Counter counter = (Counter)getWorld().getObjects(Counter.class.get(0));
counter.add(1);