top of page

1. Setup & Populating the World

1. Open Greenfoot

This tutorial uses Version 2.4.2 which is the version students are given to use in the WJEC/Eduqas Component 2 exam.

​

Click here for more information and how to download 2.4.2

​

If you are using a more recent version the code should still work but the look of the program in the screenshots may be different.

​

In the Component 2 exam of the 2016 WJEC/Eduqas specification you would skip ahead to the New Object Placements stage further down this page as the classes should be set up for you.

greenfoot1.png
greenfoot2.png

2. New Scenario

For a new project, click 'Scenario' and then 'New'.

​

If you are using a more recent version of Greenfoot select 'New Java Scenario'.

​

Save this new project in a suitable location such as a folder named 'Greenfoot'.

​

You may wish to save this project as 'SimpleGame' or 'ExampleGame'.

​

3. Setup the MyWorld class

The first thing to do is to create a subclass of World called MyWorld which becomes our background object. 

greenfoot3.png

Right-click on the World class and select 'New subclass...'

Set the New class name to MyWorld.

​

Choose any image from the 'backgrounds' image category.

​

I have chosen the 'cell.jpg' image.

greenfoot4.png

Click the Compile button in the bottom right of the Greenfoot window to save the program.

greenfoot6.png

4. Create the Main Character class

Now to create a new class for the main character.

Right-click on the Actor class and select 'New subclass...'

Give the new object an appropriate name and choose a relevant image.

​

I have named my class 'Sheep' and selected the sheep.png image.

5. Right-click on Actor and create two more classes:

​

  • Collectable objects to pick up (e.g. my orange)

  • An enemy character to avoid (e.g. my elephant)

​

​

Don't forget to compile the program.

greenfoot6.png

After creating your classes you must move them over to the game world. This is known as populating the world.

1. New Object Placements

Right-click on your main character object and select the top option e.g. 'new Sheep()'.

​

Drag your mouse to the world and click to drop it.

​

Complete the following actions:

  • Place 1 main character object.

  • Place 5 collectible objects.

  • Place 2 enemy objects.

2. Save the World

Once you have populated your world with objects then right-click anywhere on the background and select 'Save the World'.

​

This saves the positions of each object so that it won't reset every time you start a new game.

​

You can close the MyWorld code that automatically opens when you save the world, we never add any code to this window.

bottom of page