Difference between revisions of "Greenfoot"

From CompSciWiki
Jump to: navigation, search
(Added paddle image)
(More text for the Paddle up to the point where they are about to add the Paddle to code)
Line 18: Line 18:
 
Right-Click "Actor" and select "New subclass..."
 
Right-Click "Actor" and select "New subclass..."
  
Name your subclass Paddle by entering it into the New class name textbox.
+
Name your subclass Paddle by entering it into the New class name textbox. Now, for the image, click the "Import from file..." box in the bottom-left of this window. Find and select the Paddle.gif you just saved.
 +
 
 +
Press OK on that window to close it and create the new subclass.
 +
 
 +
In your main window, you want to add this newly created Paddle to your world. Press the compile button again to allow the Paddle you created to be usable. Then, right-click the Paddle box that now shows underneath the Actor box and select "new Paddle()".
 +
 
 +
There are two ways to add the Paddle object to the game screen:
 +
 
 +
The first way is to select the "Paddle" box, which is now located under the "Actor" box on the right-hand side, and select "new Paddle()". When you do this, you'll now see the image of the paddle following your mouse cursor. You can now place the paddle in the game screen by clicking anywhere within it.
 +
 
 +
There is a problem with this way, however. If you click the "Compile" button, your paddle disappears! This is because it recompiled all the code within the world and classes to rebuild your game screen! To make your paddle stay in the world, you have to add it directly to the code. This is the second way of adding the paddle to the game screen.
 +
 
 +
To add your paddle to the code of the MyWorld class you made earlier, right-click the MyWorld box and select "Open editor".
 +
 
 +
You are now in the thick of actual Java programming!
 +
 
 
== Step 3: Creating a Bouncing Ball ==
 
== Step 3: Creating a Bouncing Ball ==
 
== Step 4: Breakout Needs Bricks ==
 
== Step 4: Breakout Needs Bricks ==

Revision as of 12:30, 3 April 2012

COMP 1010 Home > Back to Extra Labs

Introduction

This lab is an introduction to Greenfoot. Greenfoot is an interactive tool for building Java programs using a mixture of programming and interactivity. With Greenfoot, you are able to get a 2D graphic program up and running much faster than you would using regular Java.

To familiarize you with Greenfoot, we will show you how to build a simple Breakout game.

Step 0: Starting a New Scenario

Step 1: Making a New World

Step 2: Adding a Paddle

First, right-click the following image and select Save As... and save it in the folder where you created your Greenfoot program.

Paddle.gif

On the right-hand side of your Greenfoot window, there are two boxes: One under "World classes" called "World" and another under "Actor classes" called "Actor".

Right-Click "Actor" and select "New subclass..."

Name your subclass Paddle by entering it into the New class name textbox. Now, for the image, click the "Import from file..." box in the bottom-left of this window. Find and select the Paddle.gif you just saved.

Press OK on that window to close it and create the new subclass.

In your main window, you want to add this newly created Paddle to your world. Press the compile button again to allow the Paddle you created to be usable. Then, right-click the Paddle box that now shows underneath the Actor box and select "new Paddle()".

There are two ways to add the Paddle object to the game screen:

The first way is to select the "Paddle" box, which is now located under the "Actor" box on the right-hand side, and select "new Paddle()". When you do this, you'll now see the image of the paddle following your mouse cursor. You can now place the paddle in the game screen by clicking anywhere within it.

There is a problem with this way, however. If you click the "Compile" button, your paddle disappears! This is because it recompiled all the code within the world and classes to rebuild your game screen! To make your paddle stay in the world, you have to add it directly to the code. This is the second way of adding the paddle to the game screen.

To add your paddle to the code of the MyWorld class you made earlier, right-click the MyWorld box and select "Open editor".

You are now in the thick of actual Java programming!

Step 3: Creating a Bouncing Ball

Step 4: Breakout Needs Bricks

 System.out.println("Hello Greenfoot");