simplegameinalice1 barb ericson georgia institute of technology june 2008 creating a simple game in...
TRANSCRIPT
SimpleGameInAlice 1
Barb Ericson
Georgia Institute of Technology
June 2008
Creating a Simple Game in Alice
SimpleGameInAlice 2
Objectives
• Show how to create a simple game in Alice– Creating methods in Alice– Creating a field or property of an object– Creating a variable– Using a while loop– Creating a Boolean function– Creating a comment
SimpleGameInAlice 3
Things to Consider
• All objects in an Alice movie or game must be created before the game starts– you can make them invisible to start
• click on properties and set the opacity to 0
– you can also hide objects by moving them under the ground
• move down some amount
• You can update a field (property) in an object to track if it has been clicked on
SimpleGameInAlice 4
Click the Zombie Game• While the user hasn't won hide
the zombie and after some random amount of time between 1-3 seconds have it pop up in a random place.
• If the user clicks on the zombie increment the number of hits and when it reaches 5 let the user know s/he won
• If the user doesn't click on the zombie within 1 second hide it again
• Add instructions at the beginning to let the user know how to play– and then make them invisible
after some amount of time
SimpleGameInAlice 5
Set-up the World
• Click on File -> New World
• Select the Template tab
• Click on the grass world– click on open
SimpleGameInAlice 6
Add Objects to the World
• Click the add objects button at the bottom of the scene
• Scroll to the City category and click on City
• Add some Buildings by dragging out some building clusters
SimpleGameInAlice 7
Add the Zombie
• Click on Local Gallery to get back to the list of categories
• Open the People category
• Scroll over to Zombie and add one to the world
SimpleGameInAlice 8
Hide the Zombie
• Create a method to hide the zombie– Click on zombie in the
object tree– Click on methods in
the details window– Click the create new
method button– name the method hide
SimpleGameInAlice 9
The hide method
• Click on propertiesin the detail window
• Drag out opacity = 1 (100%)
• Put it in the hide method
• Change the opacity to 0 (0%)
• Click on methods• Pull out zombie move
down 2 meters
SimpleGameInAlice 10
Create the pop up method
• Click on methods• Click the create new
method button• name the method
popUp– move the zombie
randomly– move the zombie up
above the ground– make the zombie
visible
SimpleGameInAlice 11
Move the zombie randomly
• Start by dragging out zombie move tiles– one for each of left, right,
forward, and backward
• Click on world in the object tree to select it
• Click on functions in the details window
• Drag out random number and drop it on the 1 meter– select 0 for min and 2 for
the maximum
SimpleGameInAlice 12
Add a comment
• You can add a comment to explain what you are doing in English
• Drag a // tile from the bottom of the method editing window to where you wish to place the comment– Click on the down arrow– Select other– Type in the comment
SimpleGameInAlice 13
Showing the zombie
• Click on zombie in the object tree to select it
• Click on methods in the details window
• Drag out a zombie move tile– select up 2 meters
• Click on properties in the details window
• Drag out opacity = 0– change to 1 (100%)
SimpleGameInAlice 14
Adding a property (field)
• We need to store the number of hits on this zombie
• Click on the properties tab
• Click the create new variable button
• name the variable numHits– set the value to 0
SimpleGameInAlice 15
Increment the number of hits
• If the user clicks on the zombie we want to add 1 to the number of hits so far
• Create a method that does this– It should be a new zombie method
SimpleGameInAlice 16
Respond to mouse click on zombie
• In the events window click the create new event button– select When the
mouse is clicked on something
• Change the anything to the zombie (the entire zombie)
• Change the nothing to zombie incrementHits
SimpleGameInAlice 17
Method to run the game
• Click on world in the object tree
• Select methods• Pull up a while tile
from the bottom of the editor window– select true
• Click on functions– drag out a < b and
drop it on true• select 1 and 1
SimpleGameInAlice 18
While number of hits < 5
• Click on zombie in the object tree
• Click on properties– drag out numHits = 0
and drop on the first 1
• Change the second 1 to 5– click on other and
enter 5
SimpleGameInAlice 19
Hide and wait a random amount of time
• Click on methods• Drag out hide• Drag up a wait tile
from the bottom of the editor window– select 1 second
• Click on world in the object tree– click on functions– drag out random
number and drop on the 1 second
SimpleGameInAlice 20
pop up and wait for 1 second
• Drag out a zombie popUp
• Drag up a wait tile and select 1 second
• Try it out!– What happens after
you click on the zombie 5 times?
SimpleGameInAlice 21
Tell the user s/he won
• Add some 3D text that tells the user she or he won– Click on File and then on
Add 3D Text– Type in the text
• you can change the font
• Place it where you want it to appear– Click on add objects to get
to the mouse controls– Click on done when done
SimpleGameInAlice 22
Make the text invisible to start
• Click on the text in the object tree
• Click on properties– Modify opacity to 0
SimpleGameInAlice 23
When the user wins show the text
• Drag out opacity = 0 to the method– change to 1 (100%)
• Play the game!
SimpleGameInAlice 24
Speeding things up
• All animation takes 1 second by default– you can change this
using the more…
• Make the zombie move up or down and become visible and invisible at the same time– use a do together from
the bottom of the editor window
SimpleGameInAlice 25
Add instructions
• Create 3D text that tells the user what to do in the game
• When the game starts wait for 1 second– then make the text
invisible• can set isShowing to
false
SimpleGameInAlice 26
Show the number of hits
• Create 3D text that says Hits and one that says 0
• Click on the 0 in the object tree– Click on properties– Drag out text = 0
• select default string
• Use the mouse controls to position the text– Click on Add Objects to
see the mouse controls• when done click on done
SimpleGameInAlice 27
World incrementHits method
• Add an incrementHits method to the world– call the zombie
incrementHits method– click on 0 then properties
• drag out text = 0– select default string
• replace the default string with the what as string function in the world to convert the number to a string
• choose expressions and pick zombie numHits as what to convert
SimpleGameInAlice 28
Change when mouse clicked
• Modify then when mouse is clicked on the zombie to call the world's incrementHits method
• Try it!
SimpleGameInAlice 29
Other Ideas• Have the zombie play a sound when hit
– modify zombie incrementHits method– use play sound in methods
• you can also record your own sounds– click on properties for the zombie– click on the + next to Sounds– and record a sound and name it
• Count the number of times the zombie has appeared• Add a way to lose
– maybe it will only run till it appears 10 times– maybe add a timer and a time limit– maybe add other objects that if you click on these you lose
• Make the amount of time you give the user to click on the zombie a random amount from 0.5 to 1 second
SimpleGameInAlice 30
Summary
• Alice can be used to create simple 3D games
• Concepts covered– creating methods– creating a property (field)– creating a variable– using a while loop– creating a comment