hello wombat: lesson 1 java game programming with greenfoot

13
Learn Java with Greenfoot Lesson 1: Hello Wombats! To open the sample Greenfoot project, do “Scenario”->”Open” Browse to the Greenfoot directory and open “scenarios”, and select “wombats”. You will see a Greenfoot project that looks as followed.

Upload: jessica-chiang

Post on 12-Nov-2014

1.792 views

Category:

Documents


0 download

DESCRIPTION

This is Lesson 1 of my new series: Learn Java with Greenfoot. In this lesson, we will take a look at a simple sample game created using Greenfoot and Java.

TRANSCRIPT

Page 1: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot

Learn Java with Greenfoot Lesson 1: Hello Wombats!

To open the sample Greenfoot project, do “Scenario”->”Open”

Browse to the Greenfoot directory and open “scenarios”, and select “wombats”.

You will see a Greenfoot project that looks as followed.

Page 2: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot

If you’ve followed the Scratch series (if you have not, I would strongly recommend), then itshould be quite obvious to you that the Greenfoot has similar interface to Scratch.

Page 3: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot

To “populate” the world, right click at the “wombatWorld” on the top of the Current Programpanel. Then select “void populate()” from the drop-down list.

Page 4: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot

You would see two bears and six leaves shown up in the world. Click the “Run” button to startthe program. Once the program starts, these two bears will move about finding leaves to eat.Obviously, they are vegetarian grizzly bears. The game/program will end when all leaves aregone.

These two poor bears are too hungry; let’s give them more leaves by right-clicking the tool barnear the "wombatWorld" label. Select "Void randomLeaves(int howMany)" from the drop-downlist.

Page 5: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot

An window would pop up and ask how many random leaves to add. Enter “10” and click “OK”.

Page 6: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot

Ten leaves would be added randomly.

We are ready to run the program now. To run the program step by step, click “Act”. To run theprogram continuously, click “Run”.

Page 7: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot

You can view the Scenario Information by clicking the highlighted button.

Page 8: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot

Next, we can change the Actor’s image. Right click on the Wombat button and select “Setimage” from the drop-down menu.

Page 9: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot

Select an image you like. I selected the Linux Penguin named “tux.png”. Click OK to save.

Page 10: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot

Also change the Leave’s image. I changed it to the image of a strawberry.

Page 11: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot

When done, click “Compile all” button to recompile the program. To compile a program justmeans to build a program executable.

Page 12: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot

To run the modified program, we will repopulate the world and restart the program. To populatethe world, right click wombatWorld title above the program view and select “void populate()”from the drop down list. Then click the “Run” button to run the program. Also, you can addmore strawberries by selecting the “void randomLeaves(int howMany)” from the drop-down list.

Page 13: Hello Wombat: Lesson 1 Java Game Programming with Greenfoot