yr 10 greenfoot programming ooklet€¦ · yr 10 greenfoot programming ooklet week 2 so let [s...
TRANSCRIPT
YR 10 GREENFOOT PROGRAMMING BOOKLET
Enter your name here:
WEEK 1
Greenfoot is a computer language which allows you to create computer games. You will actually learn how to program a
computer. In this section you will learn…
How to create a background and change its appearance
How to place objects (players) on your background
How to get your objects to move
The following instructions show you how to do these tasks, your teacher will also help if you are lucky.
PART 1. Setting up the world
The background for your game/program is often called the stage. To create this…
Right click on WORLD
Select ‘New subclass…’
In the new window type in a name (e.g. Stage) and then choose the background style you want. Click OK.
If you then double click on ‘Stage’ you can adjust the dimensions of your stage (600 x 400 is the usual setting)
Then click compile. This saves your work and carries out the programming instructions you have written.
Now go on to the next page and complete task 1.
TASK 1
1. Change the dimensions of your background (world) by altering the bit that says 600,400. You must make your back-
ground AS LARGE AS POSSIBLE WITHOUT SCROLL BARS APPEARING. To do this, double click on the WORLD LABEL and
you will get this window again…
Keep changing the numbers until you get it right, you will have to click COMPILE each time to see the result.
2. Now change the style of your background so that it is NOT TOO BUSY, keep it plain so that the design doesn’t make it
difficult to see your players when you add these later. To do this, right click on the STAGE LABEL, select set image and
you will get this window again…
SAVE THE WORLD!
3. Finally, take a screenshot of your finished work and paste it below
PART 2. Adding objects and creatures and stuff
Before doing this, you need to create the ANIMAL class so that the objects can do stuff like EAT and SEE other objects.
Click on ACTOR, then right click on EDIT and select IMPORT CLASS. Click on ANIMAL and select IMPORT.
You should now have this…
Now you can start to add your objects and creatures. Right Hand Click on ANIMAL, select ‘new subclass’ then carefully
and confidently create your creature (aliteration). I’ve done one called EvilSheep.
You now need to click on COMPILE.
You can now right click on ‘EvilSheep’ and select ‘new EvilSheep’.
To add lots of evil sheep, hold down SHIFT and click your left hand mouse button on the stage.
After you have added your new creatures, you will need to ‘save the world’ in a similar way to
Doctor Who. Just right click on your background (stage) and select SAVE THE WORLD. Do this every
time you change or add to your stage.
TASK 2
1. Using the techniques you have just learnt, add some ‘nasty’ creatures or objects.
2. Now add a ‘good guy’ who will be the main player.
3. Add some objects which will be food.
Here is a bit of an example that Sir has
created. The good guy is Colin and the
food are mushrooms. Do you like
mushrooms?
4. Finally, take a screenshot of your finished work and paste it below
PART 3. BRING THE CREATURES TO LIFE
The way your creatures move and interact will define how good your game is, so give it some thought but for now, keep it
simple. In the Sir’s game, Colin eats the mushrooms and the game ends with a win if he gets to eat them all. However, he has
to watch out for the evil sheep who will eat Colin if they catch him – and then the game ends in defeat.
GOOD GUY COLIN
Colin needs to be controlled by the user (you) and he needs
to eat mushrooms. If you double click on Colin you get this
window.
We now need to fill this with programming code. If you add the bits shown below, your ‘good’ guy will move when you click
run and use the arrow keys.
The boxes in blue tell you what the code does…
E.g. move(7); ...this moves Colin seven units forward in the direction he is facing.
IMPORTANT POINTS—You MUST type the instructions carefully, any mistakes will stop your program from working. Use capi-
tal letters where they are shown and make sure that MOST (but not all) lines end in a semicolon (;).
All brackets are ( or ) UNLESS they are by themselves and then they are { or }.
Always save the world after you have changed your screen design and compile, compile, compile.
Now go on to the next page and complete task 3.
TASK 3
1. Copy the code shown on the previous page, compile, click RUN and check your GOOD GUY can move about. This gives
you a PASS level.
2. Adjust some values to change the speed of your GOOD GUY as well as how much he/she turns when you press the arrow
keys. This will give you a MERIT level.
3. For top marks (DISTINCTION) try to work out how to get your good guy to move forward only when the UP arrow is
pressed. To really show off, try to get your good guy to move backwards as well.
4. Finally, take a screenshot of your finished code and paste it below.
YR 10 GREENFOOT PROGRAMMING BOOKLET
WEEK 2
So let’s recap. You should now have the following completed tasks…
• A background which is of appropriate size
• A good guy who can move about and can be controlled using the cursor (arrow) keys
• A load of bad guys who can’t yet move
• Some food which will be eaten by your good guy
PART 4. Making the bad guys move
If you double click on your bad guy (underneath ‘Animal’), you will get this window…
In the bit that says //Add your action code here….you need to add some code.
TASK 4
You need to get your bad guys to move and bounce off the sides of the world. They also need to kill (eat) your good guy if
they bump into him. Here is some of the code you will need, BUT you need to work out what needs to go where the stars
appear.
When you have finished, test it, make sure it works and maybe make some adjustments. Then screenshot your code and
paste it below.
PART 5 and TASK 5
The problem you have now is that the bad guys always move in the same way. It would be much more exciting if they
would bounce off the walls in different ways. So, in the code you have just written, change the number that the bad guys
turn into the code below…
The stars need to be replaced by numbers, your teacher will explain how this works so you can pick sensible numbers. Then
screenshot your new code and paste it below.
PART 6 and TASK 6
Using your new found knowledge, now add some code to the good guy so that he eats the food when he sees it. CLUE: the
code is very similar to the code where your bad guys eat your good guy. Then screenshot your code and paste it below.
Bonus task
See if you can make your game more exciting by…
1. Changing the amounts your players move by
2. Getting your bad guys to bounce off food to make the game more unpredictable OR getting your bad guys to die
when they ‘touch’ the food. (You do this by getting the food to ’EAT’ the bad guy).
Then screenshot your changed code and paste it below.
YR 9 GREENFOOT PROGRAMMING BOOKLET
WEEK 3 & 4
So let’s recap. You should now have the following completed tasks…
• A background which is of appropriate size
• A good guy who can move about and can be controlled using the cursor (arrow) keys
• A load of bad guys who bounce off walls and will eat the good guy if they touch him/her. Then the game ends.
• Some food which will be eaten by your good guy
PART 7 and TASK 7. Displaying a ‘You Lose’ message.
Go into PAINT and design a LOSE message. Save it in a sensible place in your user area. To add the ‘Lose’ image, it’s the same
as adding a player or food, but you’ll need to ‘Import from file’ the ‘Lose’ image that you have saved.
PART 8 and TASK 8.
Now add a WIN message by designing it in PAINT, saving it and importing it. When you have finished you should have
something like this…
This shows me setting up a
WIN message. You’ll need
to Import from file shown
here.
When you have done task 7 and 8, screenshot your animal objects (as on the previous page)
and paste it below.
PART 9 and TASK 9
Now you need to display your LOSE message when your good guy gets eaten. Add the following code to your bad guy code
(shown in the red oval). Note that you will have to change the numbers 450 and 300 to display your message in the middle
of your screen. See if you can work out the right values by trial and error and using your brain.
When you have finished this bit, paste your code below.
PART 10 and TASK 10
Using the screenshot below, you now need to adapt your good guy code by adding the bits circled in red. Your lovely
teacher will explain how these bits of code work. Note that you will have to change the last bit of code (the if (count==9) )
to suit your game.
Then screenshot your changed code and paste it below.
PART 10. WHAT IF IT DOESN’T WORK?
Greenfoot can be a right pest sometimes. You try to compile and it won’t or it doesn’t seem to respond. There are usually 5
things that can be wrong…
Brackets – remember brackets with text are like this… ( or ) Use curly brackets { } when the brackets are by themselves. With curly brackets always make sure that an open bracket has
a matching closing bracket. Use EDIT-AUTO LAYOUT to line up your programming code to make it easier to see which bracket
is in the wrong place.
Watch out for uppercase and lowercase letters, this is a real pain in Greenfoot, things like canSee and atWorldEdge have
uppercase letters where you wouldn’t expect them.
If Green- foot moans about ‘canSee’ and ‘eat’ it will be because you
haven’t added the ANIMAL class. If you haven’t, you’ll need to add
it and then change the code for all of your creatures and change
‘Actor’ so that it says ‘Animal’ shown in the red oval.…
Don’t forget to have a semicolon at the end of each line (mostly). You don’t need them after IF’s.
MESSY!
Missing Close (Green) bracket here
Missing Close (Grey) bracket here MESSY!
Missing Close (Green) bracket here
Missing Close (Grey) bracket here