1.1 Scenarios, Worlds, and Actors

Greenfoot Scenarios, Worlds, and Actors

Unit 1: Meet Greenfoot · Lesson 1.1 · about 25 minutes · no coding experience needed

Every game you have ever played is a stage with things on it. A racing game is a track with cars. A platformer is a level with a player and some enemies. Greenfoot makes that idea literal: you build a stage, you put things on it, and you tell the things how to behave. Before you write a single line of code, you need names for those two parts.

What you will be able to do

  • Name the three parts of any Greenfoot project and say what each one does
  • Point at the world and the actors in a scenario you have never seen before
  • Explain why there is exactly one world but many actors

Words you will need

Scenario
In plain words The whole project. The entire game, in one folder.
More precisely A Greenfoot scenario contains the world class, every actor class, and the image and sound assets they use.
World
In plain words The stage. The rectangle everything else sits on.
More precisely A subclass of Greenfoot's World class. It owns the grid, its size, and the list of actors currently in it.
Actor
In plain words A thing on the stage. The player, an enemy, a coin, a wall.
More precisely A subclass of Greenfoot's Actor class. It has a position in the world, an image, and behavior of its own.

Build it step by step

Every step below leaves a scenario that compiles and runs. If you stop halfway you will have something that works, not something broken. Follow along in Greenfoot rather than reading straight through.

  1. Step 1

    On your screen The Greenfoot window with a scenario open. The world fills the large area on the left and the class diagram is stacked on the right.

    This is a scenario, open in Greenfoot. Two regions matter right now. The big rectangle on the left is the WORLD. Everything you can see sitting inside it is an ACTOR. That is the whole vocabulary for this lesson.

  2. Step 2

    On your screen The class diagram panel, showing World with a subclass beneath it and Actor with several subclasses beneath it.

    The panel on the right is the class diagram, and it is already telling you the same story. Everything in the top group descends from World. Everything in the bottom group descends from Actor. Greenfoot sorts your project into exactly those two families because every single thing in a scenario is one or the other.

  3. Step 3

    On your screen A close-up of one actor class in the diagram, showing the class name above a small preview of its image.

    public class Crab extends Actor
    {
        // behavior goes here, later
    }

    Double-clicking an actor class opens its code, and the first line says the same thing the diagram did. `extends Actor` is Java for "this is a kind of Actor". You are not expected to write this line yet. You are expected to recognize it, because it is how you tell what something is when the diagram is not in front of you.

  4. Step 4

    On your screen The world class code open, showing a class declaration that extends World.

    public class OceanWorld extends World
    {
        // the stage is set up here, later
    }

    And the world class says `extends World`. Notice the name is OceanWorld, not World. The name is yours to choose; the family it belongs to is what `extends` decides.

Mistakes almost everyone makes here

These are the wrong ideas students actually build at this point. Read them even if you think you understand, because a wrong idea you have not noticed is the expensive kind.

Common wrong idea The world is the background picture.

What is actually true The world is a thing that OWNS a background picture, a size, and a list of actors.

Why it matters This one matters later. In Unit 3 you will write code inside the world to place actors and keep score. You cannot write code inside a picture.

Common wrong idea An actor is the picture of the crab.

What is actually true The actor is the thing; the picture is one of its properties.

Why it matters The same crab actor can change its image and still be the same crab, in the same place, with the same score.

Common wrong idea There can be several worlds on screen at once.

What is actually true Exactly one world is showing at a time. Actors are the many; the world is the one.

Why it matters Scenarios do swap worlds later (a title screen, then a level), but they swap. They do not stack.

Check your understanding

Answer these before moving on. They are graded instantly and you can retry.

  1. 1. In a Greenfoot scenario, how many worlds are showing at once?

  2. 2. You open an unfamiliar scenario and see a fish, three bubbles, and a treasure chest inside a blue rectangle. How many actors are on screen?

  3. 3. A class declaration reads `public class Rocket extends Actor`. What does that tell you?

  4. 4. Which of these is the SCENARIO?

Fill in the code

Here are the first lines of two classes from an underwater scenario. One of them is the stage; the other is a thing that swims around on it. Fill in the family each one belongs to.

public class ReefWorld extends 
{
}

public class Jellyfish extends 
{
}
Stuck? Open a hint for each blank
  • Blank 1: ReefWorld is the stage. Which family is the stage in?
  • Blank 2: A jellyfish is a thing that sits on the stage.

Lesson quiz

This one counts toward your progress. Take it when the section above makes sense.

  1. 1. Which statement is TRUE about worlds and actors?

  2. 2. You want to add a coin that the player can collect. Should the Coin class extend World or Actor?

  3. 3. Which of these is NOT part of a scenario?

The short version

  • A scenario is the whole project.
  • The world is the one stage everything sits on.
  • Actors are the many things placed on that stage.
  • `extends World` and `extends Actor` are how a class says which family it is in.

If you get stuck

These pages cover the problems that come up most often in this lesson. Opening one is not cheating and it is not counted against you.

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]