Greenfoot Code Glossary

Key Down

if (Greenfoot.isKeyDown("right"))

       {

        setRotation(0);

        move(1);

        }

Is At Edge

if (isAtEdge())

            {

            turn(180);

             }

move(1);

if (Greenfoot.getRandomNumber(10)<1)

{

turn(Greenfoot.getRandomNumber(90) - 45);

}

Random

Actor Crab = getOneObjectAtOffset(0,0,Crab.class);

if (Crab != null)

{

getWorld().removeObject(Crab);

}

Remove Object

Play Sound

Greenfoot.playSound("munch.mp3");

Greenfoot.Stop();

Stop

Counter

Import the Counter!

Also, In the MyWorld editor, add 'counter' to each class's empty brackets that you have added the counter to!

Before Act() Method

private Counter counter;

Counter Code

counter.add(1);

After Act() Method

public Bear(Counter pointcounter)
    {
       counter = pointcounter;    
    }

Stuck?

If you start typing but can't remember what commands come next, press Ctrl and Space together to show a list of all possible commands that you can use.

© CSNewbs 2020