Creating a Simple Game in Alice Barb Ericson
Creating a Simple Game in Alice Barb Ericson Georgia Institute of Technology June 2008 Simple. Game. In. Alice 1
Objectives • Show 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 Simple. Game. In. Alice 2
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 Simple. Game. In. Alice 3
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 Simple. Game. In. Alice 4
Set-up the World • Click on File -> New World • Select the Template tab • Click on the grass world – click on open Simple. Game. In. Alice 5
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 Simple. Game. In. Alice 6
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 Simple. Game. In. Alice 7
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 Simple. Game. In. Alice 8
The hide method • Click on properties in 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 Simple. Game. In. Alice 9
Create the pop up method • Click on methods • Click the create new method button • name the method pop. Up – move the zombie randomly – move the zombie up above the ground – make the zombie visible Simple. Game. In. Alice 10
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 Simple. Game. In. Alice 11
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 Simple. Game. In. Alice 12
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%) Simple. Game. In. Alice 13
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 num. Hits – set the value to 0 Simple. Game. In. Alice 14
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 Simple. Game. In. Alice 15
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 increment. Hits Simple. Game. In. Alice 16
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 Simple. Game. In. Alice 17
While number of hits < 5 • Click on zombie in the object tree • Click on properties – drag out num. Hits = 0 and drop on the first 1 • Change the second 1 to 5 – click on other and enter 5 Simple. Game. In. Alice 18
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 Simple. Game. In. Alice 19
pop up and wait for 1 second • Drag out a zombie pop. Up • Drag up a wait tile and select 1 second • Try it out! – What happens after you click on the zombie 5 times? Simple. Game. In. Alice 20
Tell the user s/he won • Add some 3 D text that tells the user she or he won – Click on File and then on Add 3 D 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 Simple. Game. In. Alice 21
Make the text invisible to start • Click on the text in the object tree • Click on properties – Modify opacity to 0 Simple. Game. In. Alice 22
When the user wins show the text • Drag out opacity = 0 to the method – change to 1 (100%) • Play the game! Simple. Game. In. Alice 23
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 Simple. Game. In. Alice 24
Add instructions • Create 3 D 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 is. Showing to false Simple. Game. In. Alice 25
Show the number of hits • Create 3 D 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 Simple. Game. In. Alice 26
World increment. Hits method • Add an increment. Hits method to the world – call the zombie increment. Hits 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 num. Hits as what to convert Simple. Game. In. Alice 27
Change when mouse clicked • Modify then when mouse is clicked on the zombie to call the world's increment. Hits method • Try it! Simple. Game. In. Alice 28
Other Ideas • Have the zombie play a sound when hit – modify zombie increment. Hits 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 Simple. Game. In. Alice 29
Summary • Alice can be used to create simple 3 D games • Concepts covered – creating methods – creating a property (field) – creating a variable – using a while loop – creating a comment Simple. Game. In. Alice 30
- Slides: 30