Download presentation
Presentation is loading. Please wait.
1
Let's Race! Typing on the Home Row
Michael Hoyle Susan Rodger Duke University 2012
2
Overview In this tutorial you will be creating a bike racing game to practice keyboarding. Your bike will move forward when you type the correct letters on the home row (including a,s,d,f,j,k,l). Your opponent moves forward at a fixed pace. Get to the end first to win!
3
Getting Started For this tutorial you should have downloaded the starting world from the Duke Alice Materials Repository Look around the world, it should be full of objects. We are going to write the methods to make them move. Feel free to move the camera using the green arrows, but make sure to set it back. Do this by right clicking on camera, selecting methods, set point of view to, Dummy objects, startPosition.
4
Getting Started The object letter is the letter at the top of the screen. Let's make it count down for our race. Click on letter. In its properties tab click and drag the text property into world.my first method. When asked what text to use, select other, and write "Ready,"
5
Getting Started Drag over the text property two more times, adding "Set," and "Go!"
6
Getting Started Go to world's methods tab and click create new method. Name your method "race".
7
Getting Started Drag your new race method into world.my first method underneath your countdown.
8
Making the Race Now switch to the world.race tab. This is where we will code how the actual race works. Drag a Do together into world.race.
9
Making the Race In world's methods tab, create two new methods, "player1race" and "player2race". Drag both of these new methods into the Do together block in world.race.
10
player2race player1race will be the method that responds to your typing to make your biker move forward. player2race is the method that tells the computer how to race against you. Let's do this first.
11
player2race We want him to keep going until he reaches the end. For this we will use a While. Drag a While into world.player2rac e and select true.
12
player2race Click on bikeKid2 in the Object tree. Under his functions tab, find bikeKid2 is at least threshold away from object. Click and drag this over the true in the While. Select 5 meters for threshold, and Dummy Objects, p2finish for object.
13
player2race Drag a Wait into the While. Select 1 second. Drag bikeKid2 into the While after the Wait. Select move toward, then 1 meter, Dummy Objects, p2finish. Now, click on the amount to change it to 5 meters. Click more to set duration to .25 and style to abruptly.
15
player2race Now player2race is finished! He will move forward every second. To change how long he waits between moves, change the value in the Wait block. You can use this later to change the difficulty. Press You should see a countdown, then the second biker should take off.
16
Receiving Input Our next step is to write player1race. We know that for that to work we will need to get input from the keyboard. We will do this using Events.
17
Receiving Input First lets create a New Variable in the world's properties tab and call it "current-letter". For type, select Other... String. For now, the value can just be "a".
18
Receiving Input Now we will create events to detect when a key is typed. Click in the Events section and select When a key is typed. Click any key and select letters, A.
19
Receiving Input Click and drag current-letter from world's properties tab, and drop it on Nothing in your event. Select set value, other, "a" Now when a is typed, current-letter will be "a"
20
Drag the entire event into the clipboard at the top-right of Alice.
Receiving Input Now we need to have similar events for every letter on the home row (a,s,d,f,j,k,l). Drag the entire event into the clipboard at the top-right of Alice. Now drag back down from the clipboard into Events 6 times, creating 7 duplicate events. Note: Alice doesn't let us create an event for the ';' key yet, so we cannot include that key in this game.
21
Receiving Input Change the duplicates to the letters on the home row (A,S,D,F,J,K,L)
22
player1race Now we are ready to write the player1race method! Click on the world.player1race tab. Drag in a While and select true.
23
player1race Just like in the player2race method, we want this While to keep running until your character reaches the end. Select bikeKid1 in the Object tree, and go to the functions tab. Drag bikeKid1 is at least threshold away from object over true. Select 5 meters, Dummy objects, p1finish.
24
player1race Click Create New Variable in world.player1race and call it "random-letter" We will use this to select a random letter to challenge you to type...
25
player1race ...but we will need a list of letters to choose from. Under world's properties tab, click Create New Variable. Call it letters-list, of type Other... String. Check the make a list box.
26
player1race Click 7 times, one for each letter on the home row.
Make the value of each item a single letter on the home row. These letters should be the same as the values you set to current-letter when you made your events.
27
player1race Now we can pick a random letter from this list to set to random-letter Drag random-letter down above the While and select set value, default string.
28
player1race From world's properties, click and drag letters-list on top of default string. Select random item from list.
29
player1race Now lets change letter to show random-letter's new value. Under letter's properties tab, click and drag over text. Select expressions, random-letter.
30
player1race By default, it takes 1 second to change this text. We want it to be instant, so click more, duration, then other. Enter 0 on the calculator.
31
player1race In the While, drag in an If/Else. Select true. Click and drag random-letter over true. Select expressions, world.current-letter.
32
player1race Inside this If, we need to put the code to select a new random letter, and move our character. First let's set our current-letter variable to a blank " ".
33
player1race Next we need to choose a new random letter, then set letter to show that text. Use the clipboard to use the same code you used earlier.
34
player1race Finally, we can move our player forward. Click and drag bikeKid1 into the If statement. Select methods, move towards, 5 meters, Dummy Objects, p1finish. Click more to set duration=.25, and style=abruptly.
35
Try it Out! Press and try to play the game. Notice anything wrong? You should be able to control your character if you type the letters right, but he quickly cycles off the camera.
36
Setting Vehicle Properties
We need to set the camera to follow your character. Click on camera, and under the properties tab, find the vehicle property. Click world, and select bikeKid1, the entire bikeKid1. Now your camera should follow your biker.
37
Setting Vehicle Properties
We also need to make sure that the letter stays on the screen. Use the same process as last slide to set letter's vehicle to camera.
38
How does the game end? If you play the game now, both players can keep moving until they're both at the end. We're going to need to create a variable that tells us whether the game is over or not.
39
currently-playing In world's properties tab, click create new variable. Name it "currently-playing", of type boolean.
40
currently-playing In world.my first method, drag and drop currently-playing just after "Go!". Choose set value, true.
41
currently-playing Now, in BOTH player1race AND player2race, set currently-playing to false at the very bottom of the method (below everything else). This means as soon as anyone finishes, the race will be over.
42
Check to see if it's over Now we need both our players to always check to see if the race is over before moving again. To do this, find the While in BOTH player1race AND player2race. Click the rightmost arrow, select logic, and, expressions, world.currently-playing.
43
Check to see if it's over Make sure you do this in player1race AND player2race!
44
See Who Won We're almost done, we just need to do a check to see who has won once the game is over. To do this, create a method under world's methods tab called "check- win" Drag this new method to the bottom of world.my first method, after race.
45
See Who Won Now go to the world.checkWin tab. Drag in an If/Else and select true. Click bikeKid1 and go to his functions tab. Find bikeKid1 is within threshold of object. Click and drag this over the true in the If/Else. Select 5 meters, Dummy objects, p1finish.
46
See Who Won In this condition, you won. Go to letter's properties tab. Drag over text, select set value, other. Type in "You Win!"
47
See Who Won Now drag the entire If/Else onto the clipboard. Click the clipboard and drag the statement into the Else section of the first If/Else.
48
See Who Won Now change the values in the code you just pasted. Click bikeKid1, select bikeKid2, the entire bikeKid2. Click p1finish, select Dummy Objects, p2finish. Select "You Win!" and type in "Try again!"
49
You just finished creating your own bike race typing game!
Congratulations! You just finished creating your own bike race typing game! View the next slide for some additional challenges.
50
Challenges Add more letters to the typing game. Give the player the ability to select difficulty levels. Play sounds for getting a letter right, winning, and losing. Make the second player move faster when he's behind. Add another opponent.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.