0% found this document useful (0 votes)
325 views60 pages

Making A Boat Racing Game in Alice

This document provides instructions for creating a boat racing game in Alice. It describes setting up the scene by adding a motorboat and torus objects to form arches along a racing path. It also covers adding a timer object that will count down and move with the boat. Code is written to continuously decrement the timer value while the race is in progress.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
325 views60 pages

Making A Boat Racing Game in Alice

This document provides instructions for creating a boat racing game in Alice. It describes setting up the scene by adding a motorboat and torus objects to form arches along a racing path. It also covers adding a timer object that will count down and move with the boat. Code is written to continuously decrement the timer value while the race is in progress.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Making

a Boat Racing Game in Alice

By Jenna Hayes
Under the direc:on of Professor Susan Rodger
Duke University, July 2010
Making a Boat Racing Game in Alice
This tutorial will teach
you to make a boat
racing game in Alice, in
which you steer a boat
with the arrow keys
through several arches,
trying to beat the clock
to the nish. You must
drive through each arch
before you get to the
nish line, and a score
will keep track of how
many arches youve
driven through.
SeMng Up the Scene
This tutorial will teach you
how to make a boat racing
game in Alice. First, open
up a water template world
in Alice. Then, from the
vehicles folder in the
Object Gallery, add a
motorboat object to your
world. AQer youve
posi:oned your boat, drop
a dummy object at your
camera and rename it
originalView, to save the
camera view.
SeMng Up the Scene
Using the object posi:oning buSons, turn your boat so that
the front of it is poin:ng away from the camera, and move
it closer to the camera un:l it looks something like this:
SeMng Up the Scene
Next, go into the Shapes folder in the object gallery and nd
the Torus object. Click and drag a torus into your world. Using
the object posi:oning buSons, rst resize the torus un:l it is
preSy large, then turn it un:l half of it is underwater. Then
move it so that it
is a liSle in front
of your boat, as if
your boat is about
to drive through it.
SeMng Up the Scene
Now, using your purple camera moving arrows, move your
camera forward for a few seconds, and then drag, drop,
resize, and turn another torus.
SeMng Up the Scene
Now repeat the last step un:l you have ten
toruss in your world. The path that you move
your camera along, and drop the toruss on,
will be the racing path for your motorboat.
You can make it perfectly straight, or put
some twists and turns in
it if you want. When
youre done, move your
camera back to
originalView.
Making a Timer
Now well add a :mer
to the world that will
:me the boat as it
races through the
arches. Add a 3D Text
object from the object
gallery into your world,
and make it say 0.0.
Then rename it in your
object tree to :mer.
Place it on top of your
boat.
Making a Timer
Since the boat will
move through the
world while its
racing, we want the
:mer to be able to
move with it. So, go
to the :mers
proper:es tab and
set its vehicle
property to
motorboat.
Making a Timer
Now we need to write
code to make our :mer
work. First, we need to
create world variable to
save the number value of
the :me that is leQ. Go to
the worlds proper:es
tabs, and create a new
variable, of the type
number, and name it
:merValue. It should be a
world variable, because
we will be using it in more
than one place in Alice.
Making a Timer
Now we need
to create a
method that
will count down
the amount of
:me that is leQ.
Create a new
world method
called
:merDecrease.
Making a Timer
We want the :mer to keep coun:ng down as long as there is
:me leQ. To put this into code, get a While loop and drag it
into the code, and select true. If :merValue is greater than
zero, that means theres :me leQ, so that will be the condi:on
of the While loop. Go to the worlds func:ons, get a>b, and
drop it onto the true part of the While loop. Pick any two
numbers from the drop down menu.
Making a Timer

From the world proper:es pane, grab :merValue and


drop it onto the rst number at the top of the While loop.
Then, change the second number to zero.
Making a Timer

The next thing we want is for the :mer to count down. To


do this, we need :merValue to subtract one from its value.
So, drag :merValue from the worlds proper:es pane into
the while loop. Then select decrement world.:merValue by
1.
Making a Timer
Now, we need to :e our 3D-Text to the :merValue variable,
so that the 3D-Text shows how much :me there is leQ. Click
on :mer in your object tree, and go to the proper:es tab.
Click and drag text into your While loop and choose default
string. Set the dura:on of this command to zero.
Making a Timer

Now, click on world in the object tree and go to the func:ons


tab. Scroll down to what as a string. Click and drag that onto
default string in your code. In the drop down menu, select
:merValue.
Making a Timer
The last step to making our :mer is to make sure that it takes
exactly one second for the :mer to count down one second.
To do this, click and drag a Wait from the boSom of your
method editor, and drop it into your While loop. Then select 1
second in
the drop
down
menu.
Steering the Boat
So that we can test
out our :mer, we
need to be able to
steer our boat
through the rings. To
do this, we need an
event. Click create
new event in the
event editor, and
select Let the arrow
keys move. Then
change it from
camera to
motorboat.
Steering the Boat
The last thing you
need before you test
out the :mer is to
allow the camera to
follow the boat. Click
on camera in the
object tree and go to
its Proper:es tab.
Then change its
vehicle from world to
motorboat.
Making a Timer
Now you need to gure
out how much :me to
put on your :mer, so
that your game is
challenging. My :mer
counts down 15
seconds, and if I race
through the arches
perfectly, I can beat the
clock. First, set your
:mer by changing
:merValues value in
the world proper:es
tab.
Making a Timer
When you change the value of
:merValue, you also have to
change the beginning text of your
:mer to match that number. To do
this, click on :mer in the object
tree and go to proper:es. Next to
text, change it to the number that
you have set :merValue to.
Change your When the world
starts event to
world.:merDecrease and play your
world to test it out. When youre
done tes:ng, change it back to
world.my rst method.
Making a Score
Now we need a scorekeeper to keep track of whether you
drive through all the rings. Add another 3D-Text object into
your world that says 0.0, and name it score in the object tree.
Now, posi:on it so that its in the upper leQ hand corner of
your screen.
Making a Score

Next, go to the scores


Proper:es tab and go to
color. Change the color
to red so that the score
shows up against the
white arches. Then, set
the scores vehicle to
motorboat so that we
can always see it, even
when we move the
motorboat.
Making a Score
Now we need to create a method that will increase your
score every :me you drive the boat through an arch. Click
on world in the object tree and create a new method
called scoreIncrease.
Making a Score
We only want the score to increase while there is s:ll :me
on the clock, so we will need a While loop. Drag and drop
a While loop into your method. Select true on the drop
down menu.
Making a Score
To nish the while loop, go to the world func:ons tab and
get a > b, and drop it on top of the true in the while loop. In
the drop down menu select expressions, then
world.:merValue then other, and type in 0 into the
calculator.
Making a Score
We want this method to
con:nuously be checking
to see if the motorboat is
inside any of the arches. To
do this, we will need to
make the arches into a list.
Go to the worlds
proper:es tab and click
create new variable. Select
Object, then name it
arches. Then click the
make a List box.
Making a Score
Add each of the arches
into the list. Since there
are 10 arches, and the
rst arch will be item 0,
your list should go up to
item 9. So, click the new
item buSon un:l your
list goes up to item 9,
and put each torus
object into the list.
When your list is all set
up, click OK.
Making a Score
Now that we have a list, we can have this method constantly
search through it to see if the motorboat is inside any of the
arches. To do this, get a For all in order from the boSom of
your method
editor, and
drop it into
your while
statement.
Choose
expressions,
and world.
arches in the
drop down
menu.
Making a Score
Now we need to write in our code to add a point to the score
if the motorboat is inside an arch. Get an If/Else from the
boSom of your method editor, and drop it into the For all in
order. Select true. Then go to the worlds func:ons tab, and
get an a<b, and drop it on top of the true. Choose any two
numbers.
Making a Score
Now, click on motorboat in the object tree and go to its
func:ons tab. Get a motorboat distance to, and drop it on
top of the rst number in the a<b. Select expressions, and
item_from_arches. Then, change the second number to 1.5.
Making a Score
Now, we want the
score to add a point
if it nds that you
are inside an arch.
To do this, click on
world in the object
tree and go to the
proper:es tab. Click
on create new
variable, and name
it scoreValue. Make
sure Number is
selected, then click
Ok.
Now click and Making a Score
drag
scoreValue
into your If/
Else under If.
Select
increment
world.score
Value by 1.
Then, in the
worlds
proper:es
tab, set the
value of
scoreValue to
0.
Making a Score
Now, we need to set the text of the 3D Text object to the
variable scoreValue. Click on Score in the object tree and go
to its proper:es tab. Click on text and drag it under your
increment command. Then select default string.
Making a Score
Now, go to the worlds func:ons tab and scroll down to what
as a string. Click and drag that on top of default string in your
code. Then select expressions and world.scoreValue. Finally,
change the dura:on of that command to 0.
Making Instruc:ons
Now that weve wriSen our score method, were going to
add in instruc:ons into our world so that the user knows
the rules of the game. To do this, you will need either
Powerpoint,
or Paint. I will
use Powerpoint.
Open up one of
the two
programs.
Making Instruc:ons
Insert a text box onto your Powerpoint slide and with a
font size of about 30, type out these instruc:ons:
To win this game, you must steer the boat
through each ring and beat the clock. You
receive one point for each ring, and there are
10 rings, so if your score is less than 10 at the
end, you lose!

Then, right click on the text


box and select Save as
Picture.
Making Instruc:ons
Now, name this picture instruc:ons, and underneath that
where it says Save as type:, choose .bmp. This is so the
background of the instruc:ons ends up being white, and not
see-through, as it would with a .png type.
Making Instruc:ons
Now we will put these
instruc:ons into the Alice
world. Go to File in your Alice
world, and select Make
Billboard. Find your
instruc:ons, click on it, and
select Import. Now your
instruc:ons will appear in
your world. Go to the add
objects screen so that you can
use the object posi:oning
buSons to move the
instruc:ons over your boat,
and closer to the camera.
Making Instruc:ons
Now what we will do is make it so that when the
instruc:ons are clicked on, the game will start. We will
need an event for this, so leave the Add Objects area and
click create new event. Choose When the mouse is clicked
on something. Change the rst anything to instruc:ons.
Making Instruc:ons
Now, get a Do together from the boSom of your method
editor and drag and drop it onto the second anything. The
rst thing we want in there is for the instruc:ons to disappear
so the user can see the whole screen. Go to the instruc:ons
proper:es tab, and click and drag isShowing to the Do
together. Select false when you drop it. Then, change the
dura:on on that command to 0.
Star:ng the Game

Now, we need to make


sure that the :mer counts
down when the game
starts, and stops if you get
to the nish before :me
runs out. To do this, we
will create another
variable. Go the worlds
proper:es tabs and click
create new variable.
Name it gameOn and
select Boolean. Then, set
its value to false.
Star:ng the Game
Now we need to go back into the :merDecrease method to
tell the :mer only to count down when world.gameOn is true.
Go into that method, and then go to the worlds func:ons
tab. Drag and drop a both a and b on top of the
world.:merValue > 0. Select true.
Star:ng the Game
Now, click on true and select expressions, and world.gameOn.

Now, we need to make it so that when the instruc:ons are


clicked on, gameOn turns to true so that the :mer will start
coun:ng. To do this, click and drag world.gameOn from the
worlds proper:es tab, and drop it into the Do together under
the When mouse is clicked event. Also, change the dura:on
of that command to 0.
Star:ng the Game
Now we need the scoreIncrease and the :meDecrease
methods to start when the instruc:ons disappear. So, drag
both of those from the worlds methods tab up into the
events Do together. Now weve got everything in place to
actually play the game. Test your world to make sure
everything works.
Star:ng the Game
One last thing to add
to your world is an
instruc:on to the user
to click on the
instruc:ons when
they are ready to play.
For this, add in a 3D
Text object that says
Click Instruc:ons To
Start. Posi:on it
above your
motorboat.
Star:ng the Game
Now, go to the new 3D Text object proper:es pane, and click
and drag isShowing into the Do together under the When
mouse is clicked on event. Select false, and change the
dura:on to 0. Now, it will also disappear when the
instruc:ons are clicked on.
When the Game Ends

Now we need to write


some methods for what
to do when the game
ends. Well need to
write a winning method,
and a losing method.
They should both be
very short. Lets start
with the winning
method. Create a new
world method and
name it win.
When the Game Ends
The rst thing to do in this method is set world.gameOn to
false so that the :mer stops coun:ng down. To do that, go
to the worlds proper:es tab, and click and drag
world.gameOn into the method. Set its value to false.
When the Game Ends
Then, we will add a text
object into the world that
says You win!. Place it on
the motorboat, and set its
vehicle to motorboat,
change its color to
something other than
white, and change its name
to You Win in the object
tree. Then, set its
isShowing to false so that
its invisible. AQer that,
click and drag its isShowing
into the win method, and
select true.
When the Game Ends
Now we will do the exact same thing for a world.lose
method. Create the method, and name it lose. Then
go to the worlds proper:es pane and click and drag
world.gameOn into the method. Then, set it to false.
When the Game Ends
Now we need to add a 3D
Text object that says You
Lose. Add the object,
posi:on it on the boat,
change its color, and name
it You Lose in the object
tree. Set its vehicle to
motorboat, and set its
isShowing to false so that it
is invisible, and then click
and drag its isShowing into
the lose method, and select
true. Now we have
methods for when the
game ends, win or lose.
When the Game Ends

The next thing we need to do is make events that will


decide whether world.win or world.lose will execute at
the end of the game. Click create new event, and select
While something is true. Then right click on it, and select
change to, and then When something becomes true.
When the Game Ends
Now, go to the worlds func:ons tab, and click and drag
both a and b onto the condi:on of the new event. Select
true and true. Now click and drag an a<b onto the rst
true, and select 1 and 1. Then go to the motorboats
func:ons tab, and click and drag motorboat distance to
onto the rst 1. Select torus10.
When the Game Ends
Now, get an a==b from the
worlds func:ons tab, and
drag and drop it onto the
second true. Choose
expressions, then
world.scoreValue, then
other. Type in 10.
When the Game Ends
Now, drag a world.win from the worlds methods tab,
and drop it onto the Nothing on the event. Now, create a
new While something is true event, and change it to
When something becomes true. This will be an event for
when the user loses the game.
When the Game Ends
Now, follow the exact same steps for this event as you did for
the world.win When something becomes true event. The only
dierence will be, instead of geMng an a==b for the second
true, get an a<b. This is because if your score is less than 9
when you get to the last arch, that means you missed at least
one arch and you will lose the game. Also, drag world.lose
over nothing instead of world.win.
When the Game Ends
Now we need one more event for the last game end
possibility. If the :mer ever counts down to 0, that means
that the user has not made it to the nish line in :me,
because the :mer will always stop coun:ng down when the
user gets to the nish line. Therefore, if :merValue ever
equals 0, the user has lost. Create one more While something
is true event, and change it to When something becomes
true.
When the Game Ends
Now, get an a==b from the worlds func:ons tab, and
drop it onto the true. Select expressions, then
world.:merValue then 0. Then, get world.lose from the
worlds methods tab, and drop it on top of Nothing.
Now youve nished your boat racing game! If you want,
you can make changes to your game to make it harder.
You can add arches, or shorten the amount of :me given
at the beginning. You can change the arches colors, and
add dierent amounts of points for each color of arch. You
can also add in background objects to decorate your world
if you wish.

You might also like