Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Games with Greenfoot

Similar presentations


Presentation on theme: "Creating Games with Greenfoot"— Presentation transcript:

1 Creating Games with Greenfoot
Overall time on activity: 30 minutes Wombats Creating Games with Greenfoot

2 What is Greenfoot? A free environment that makes it easy to create 2D animations, simulations, and games

3 Getting Started To start Greenfoot click on Greenfoot.
2 mins Getting Started To start Greenfoot click on Greenfoot. Click on “Scenario” in the menu Choose Open Pick the wombats scenario It starts by showing an empty WombatWorld Which is a 2D grid of cells

4 Adding Objects to the World
3 mins Adding Objects to the World Right click on Wombat in the class display to see a pop-up menu Create a Wombat by selecting new Wombat() A picture of a wombat will appear attached to the cursor Click in the world to place the wombat Shift-click to place more than one object Class Display

5 Add Leaves Add several leaves to the world
1 mins Add Leaves Add several leaves to the world Right click on Leaf in the class display Quickest: Hold down the shift key Click in the grid to place each leaf

6 Greenfoot Objects There are two basic types of things in Greenfoot
Worlds and actors. Worlds hold actors a stage for actors Actors can act They may move They may eat food They may stay where they are

7 Run the Simulation Click on act to execute one simulation time step
4 mins Run the Simulation Click on act to execute one simulation time step Act one time Click on run to have it continuously execute time steps Keep acting till you Click on pause to stop Click on reset to start over With a new WombatWorld Execution Controls

8 What Happened? Questions
How did the wombats move? Did they eat any leaves? Did the leaves move? What happened when a wombat reached the edge of the world? If you don’t know the answer to any of these questions place more wombats and/or leaves in the world and run again Or click on act to see things in slow motion

9 The Wombat Scenario To get information on any scenario
Click on the Project Information button In top right corner above the class display Read the displayed documentation Click close when done

10 Actor Methods You can see and execute all methods that an actor knows how to do By right clicking on an actor in the grid Select a method to execute it You can call some other methods as well

11 Method Return type The words before the methods define the return type of a method. If the behavior is about changing the state of the object, the return type will be “void” which means it is telling the object to do something. The other is a non-void type which is asking the object a question. And specifies what the return type will be. A method with a void return type does not return a value. A non-void method returns a value.

12 Return Types non-void return a value.

13 Exercises 8 mins Call out the canMove( ) method on your wombat.
Does it always return true? Or can you find situations in which it returns false? Using a newly created wombat, the getLeavesEaten ( ) method will always return zero. Can you create a situation in which the result of this method is not zero? Call out the setDirection (int direction) method. Provide a parameter value and see what happens. Which number corresponds to which direction? Write them down. What happens when you type in a number greater than 3? What happens if you provide input that is not a whole number, such as a decimal number (2.5) or a word (three)?

14 World Methods Right click near the title of the world
To show the world menu Select populate() This will add wombats and leaves to the world Then click on run What happens? Do all the leaves get eaten?

15 Changing Actors Changing Actors Right click on the actor’s class
Choose “Set Image” Choose the image from the library Compile the program

16 What I have learnt this lesson:
Scratch and Greenfoot share some themes: Sprite = Actor, Stage = World Greenfoot scenarios consist of classes Many Objects can be created from a class The return type of a method specifies what a method will return Methods with non-void return type represent questions; Methods with void return types represent commands. Collaborate, be creative and pursue the a solution.


Download ppt "Creating Games with Greenfoot"

Similar presentations


Ads by Google