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);
Code to carry out a part of the program a suitable amount (used for random turning)
if (Greenfoot.getRandomNumber (10) <1)
{
}
How to set up the world subclass
Right click world and select new subclass
Choose image and name
Compile
How to add a character
Right click actor and select new subclass
Choose image and name
Compile
How to populate and save world
Right click on character and select “new …()”
Click where you want the character placed
Right click the background and click “save the world”
How to code a character
Right click on the character and select open editor
Add code
Click compile in the characters editor window
How to make an action constant
Add code outside of an if loop but still in the act loop. This section will be white
To what character do you add the code for an item to be removed
The character that causes the removal by touching the character to be removed
How to import a counter
Select edit, then import class, then counter
Compile
Add to world and save the world
Where and to what character is the code to add one to the counter added to (if counter goes up for touching a collectable character)
Inside the isTouching if statement of the character that touched the collectable
What is a superclass
A section heading e.g “World” or “Actor”
What is a class
A subclass of a superclass e.g the character or map
What method is run automatically
public void act()
What is a private property
A method or attribute accessible in only its declared class
What is a public property
A method or attribute accessible by any class