Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July 2009 www.cs.duke.edu/csed/alice/aliceInSchools.

Slides:



Advertisements
Similar presentations
Mike Scott University of Texas at Austin
Advertisements

Visual Lists By Chris Brown under Prof. Susan Rodger Duke University July 2012.
Space Man Sam: Grammar Mistakes By Aleis Murphy Duke University, Under the direction of Professor Susan Rodger July 2010.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Coloring Randomly: Random Selection in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
How Tall Are You? Introducing Functions By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made June 2014 by.
Lets Play Catch! Keeping Score in Alice By Francine Wolfe Duke University Professor Susan Rodger May 2010.
Lights Camera Action! Part 3: BDE Events By Deborah Nelson under the direction of Professor Susan Rodger Duke University July 2008.
Class-Level Variables in Alice By Jenna Hayes Under the direction of Professor Rodger Duke University, July 2008.
Wizard Game: Class-Level Variables in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July
Creating a 3D Interactive Story Prof. Susan Rodger Duke University Feb. 24, 2007.
Alice Learning to program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Methods Tutorial: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 9, 2008.
Alice Learning to program: Part Two by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Lights Camera Action! Part 2: Controlling Light in Alice By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June 2009.
Checking for Collisions Ellen Yuan Under the direction of Professor Susan Rodger at Duke University June 2014.
Distributing (Fun + Learning): The Distributive Property By: Peggy Li Under the direction of Professor Susan Rodger Duke University, June
Line up By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Making a Timer in Alice.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June
Shorter of two objects and changing color V2 Functions, events and setting the color in sequence and randomly This is a modification of the Changing Color.
Alice Learning to program: Part Three Camera Control, Invisibility, and 3-D Text By Ruthie Tucker and Jenna Hayes, Under the direction of Professor Rodger.
Changing Camera Views! Part 2: Simple Scene Change & Lighting Fixes By Bella Onwumbiko under the direction of Professor Susan Rodger Duke University July.
3–D Helium Molecule Tutorial Alice Project Duke University Professor Susan H. Rodger Gaetjens Lezin June 2008.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Checking for Collisions: Alternative Method Erin Taylor Under the Direction of Susan Rodger July 2015 Duke University.
Alice Pong Recreating Pong in Alice By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June 2010.
Changing Color, Using Text Objects, and Random Selection in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Animating Objects in Groups: Using Arrays and Lists By Ruthie Tucker under the direction of Professor Susan Rodger Summer 2008.
By Melissa Dalis Professor Susan Rodger Duke University June 2011 Multiplication Table.
A Simple Quiz: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009, added Part 2 July 2011.
An Introduction to Alice (Short Version) – Extras! Yossra Hamid Under the Supervision of Professor Susan Rodger Duke University, June 2014 This is a continuation.
Making a Timer in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1,
Alice Learning to program: Part Two Writing Your Own Methods by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Can I get your number? By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Distributing (Fun + Learning): The Distributive Property 1 Peggy Li Under the direction of Professor Susan Rodger Duke University, July 2011.
The Essentials of Alice (Bunny) By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Simple Collision Detection By David Yan Under the direction of Professor Susan Rodger and Chari Distler Duke University, June 2015.
Ready, SET, go! By Melissa Dalis Professor Susan Rodger Duke University July 2011.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Changing Camera Views! Part 1: Set Point of View to By Bella Onwumbiko under the direction of Professor Susan Rodger Duke University July 2013 Updates.
Learning to Program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
An Introduction to Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University, June 2009 Updated June 2014 by Ellen Yuan.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
Illuminating Computer Science CCIT 4-6Sep
Using Placeholders to Simplify your Methods: Learning Methods, Part 2 By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
Headshots in Alice Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008.
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June.
How Tall Are You? Introducing Functions for Alice 3 By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made.
By Melissa Dalis Professor Susan Rodger Duke University June 2011
Changing Color, Using Text Objects, and Random Selection in Alice
Let's Race! Typing on the Home Row
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Checking for Collisions: Using Functions in Alice
How Tall Are You? Introducing Functions
Getting Started With Alice
Headshots in Alice Duke University Professor Susan H. Rodger
under the direction of Professor Susan Rodger
Presentation transcript:

Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July

Download the Alice World called piñataGameStart.a2w that goes along with this tutorial. Adding the Text Object We will use this world to create a game that allows players to hit a swinging piñata with a bat. Many of the objects have already been created and placed in the world. We must create an object to display and update the score, and we will also write the code to play the game. Click add objects and add a new 3D Text Object to the world.

Once you have created the new text object, right click on it in the object tree and rename it score. Reposition the score where you can see it. Use resize and turn to face the camera. Adding the Text Object When it asks what to say, type score: 0.0.

Click on score in your object tree, and then go to the properties tab. Click on the create new variable button. Name the variable scoreValue, select the type Number, and click the arrow next to value to select other and type 0. Creating Variables

We need to keep track of a few more things during our game. To do this, we will create two world variables. Notice under the world properties that a list called pinataParts has already been created. This list is used later in the explode method that breaks open the piñata. You can play around with these values later to make the game easier or harder Now let’s create a variable to remember the number of hits needed to break the piñata. Create a world variable called numWinningHits, and set its value to 10. We will use this later to determine if the player has won the game. We also need to set the total amount of time. Create a world variable called time, and sets its value to 15.

Create a class-level method for score called initialize. Click on scoreValue in the properties tab, drag it into the initialize method, and set its value to 0. Now go back to the properties tab and find text. Drag text into the initialize method, and set its value to score: 0.0. Change the duration for both to 0 seconds. Initialize Method

Now we need to write a method that will add one point to scoreValue variable when the piñata is hit. Create another class-level method, called addPoints. Find scoreValue in the properties tab and drag it into the method, and choose to increment it by 1. Change the duration to 0 seconds. Add Points Method

Next drag text into the addPoints method, set its value to “score: ” and set its duration to 0 seconds. Next, click on world in the object tree, and find its functions tab. Find a joined with b and drag it into where you typed “score: ” and select default string for b. Then drag what as a string into default string, and select score.scoreValue from expressions. Add Points Method

Now let's divide the game into three parts: the set up and instructions, the game play, and what happens when the game is over. Click on world in the object tree and create a new world method called setUp. Now click on score in the object tree and drag its method initialize into the setUp method. Set Up Method

Now let's add instructions for playing the piñata game. The text object called instructions has already been added to the world, and its text is “Break the piñata!” Click on instructions in the object tree and select its properties. Drag isShowing into the setUp method, and choose true. Next drag text into setUp, and set it to “Press the up arrow...” Repeat this step with the text and set it to “...to swing the bat.” Set each duration to 2 seconds so there is enough for the player to read the instructions. Set Up Method

For fun, let’s swing the bat during the last instruction. Drag a Do together into the setUp method, then the last instruction “…to swing the bat” inside it. Then drag a Do in order below that. Now let’s swing the bat. Click on baseballBat in the object tree and drag the turn method into the Do in order, then select backward and ¼ revolution. Set the duration to.25 seconds and the style to abruptly. Make a copy of this line, and change its direction to forward. Set Up Method

Now let's prepare the player to start the game. Select instructions from the object tree and drag text three times into the setUp method outside of the Do together. First set the text to “Ready?” then “Set…” then “Go!” Now we want to hide the instructions. Drag in the isShowing property and set it to false, then change its duration to 0 seconds. The final step in the setUp method is to start the timer. Find timer in the object tree and drag its initialize method into the bottom of setUp and select the parameter world.time from expressions. Set Up Method The timer and its methods were created in the Timer Tutorial. See the Alice Repository for more information.

Set Up Method Check your setUp method to see if you missed anything! You can test it by selecting it When the world starts, but remember to set it back to my first method when you are done!

Now that the clock has been set, we need to swing the piñata. Create a new world method called playGame. Drag a while loop into the playGame method. Now click on the functions tab and drag a>=b into the condition, then select timer.timeLeft from expressions for a and 0 for b. Now we want the piñata to move while the timer goes down, so drag a Do together into the while loop. Next drag two copies of a Do in order inside the Do together. Play Game Method

In the first Do in order, we will make the timer count down. Click on timer in the object tree, and click on the properties tab. Drag text into the first Do in order, and choose default string for now. Change its duration to 0 seconds. Then go back to the world functions and replace default string with what as a string. Select timer.timeLeft from expressions as the what. Play Game Method

We want to count down the seconds, so drag Wait from the bottom of the screen, and select 1 second. Next find timeLeft from the timer properties and drag it into the Do in order. Select decrement timer.timeLeft by 1. Play Game Method

Now let's use the second Do in order to make the piñata swing! Go to the piñata methods and drag in turn, then select right and other to type in.1 revolutions. Now change the style to abruptly, duration to.5 seconds, and asSeenBy to camera. Right-click and make a copy of this line, and change the direction to left. Play Game Method

To perform the post-game animation, create a new world method called gameOver. The first step after the game ends is to move the piñata back to the center. Click on piñata and drag the turn method into gameOver. Select right and.05 revolutions, then change asSeenBy to camera and duration to.5 seconds. Now we will base our actions on whether or not the player won the game. Drag an If/Else statement into the method. Go to the world functions and drag a>=b into the If condition. From expressions, select score.scoreValue then world.numWinningHits. Game Over Method

Click on baseballBat in the object tree and drag the roll method into the If statement. Select right then other and type 1.25 revolutions. A text object called gameOverText is included in the world, and it has already been set to say “¡Felicidades!”. Go to its properties tab, then drag isShowing into the If statement and select true. Set the duration to 0 seconds. The explode method has already been written to make the piñata burst. Find explode in the world methods and drag it into the If statement. Game Over Method If you don’t like “¡Felicidades!” (which means “Congratulations!” in Spanish), you can change the text and color in the gameOverText properties.

Now let’s create the animation for when the player loses. Drag a Do together into the Else. Find baseballBat in the object tree, and drag the roll method into the Do together, then select right and.25 revolutions. Now make a copy of this line and change the object to the piñata. Game Over Method

Now we need to change the text for when the player loses. Click on the gameOverText and find its properties. Drag text into the Else statement under the Do Together, then set it to “Que lastima!” with a duration of 0 seconds. “¡Qué lástima!” is “What a shame!” in Spanish. See the next page for how to type accents Next, drag in color and set it to light gray with a duration of 0 seconds. In the final step, drag isShowing into the Else, select true, and set the duration to 0 seconds. Game Over Method

Mac: á = Option + e, then a é = Option + e, then e í = Option + e, then i ó = Option + e, then o ú = Option + e, then u ñ = Option + n, then n ¡ = Option + 1 ¿ = Option + Shift + ? PC: (use the keypad and make sure you have num lock on)* á = Alt é = Alt í = Alt ó = Alt ú = Alt ñ = Alt ¡ = Alt ¿ = Alt These are just some of the many different foreign characters you can create. Try searching for “keyboard accent codes” to find more. Typing Accents Now add accents so the text says “¡Qué lástima!” *On some laptops you will have to press the fn key and use the blue numbers

Now we need to call the three methods we have made in my first method. Click on the my first method tab, then find the new methods and drag them in. My First Method Do this for the setUp, playGame, and gameOver methods. This is all that we will include in my first method. Change the first event back to when world starts, do my first method

If you try playing the game, you will see that the piñata swings across the screen but there is no way to hit it. Create a new world method called batHit. This method will turn the bat toward the piñata, check to see if the piñata has been hit, then turn the bat back. Bat Hit Method Drag an If/Else statement into the batHit method. Then find the world functions and drag a>b into the If condition, then select timer.timeLeft from expressions and 0. Click on the baseballBat and drag its turn method into the If statement. Select backward and ¼ revolution, then change the duration to.3 and the style to abruptly.

Make a copy of the turn method, and change its direction to forward. Now drag another If/Else statement between the two turn methods. Bat Hit Method Next find Wait at the bottom and drag it below the second turn method, still inside the If statement. Select other and type.3 seconds. Our piñata will be turning during a 1 second period. Try experimenting with the durations in this method to make it easier or harder to hit.

Now we want to check that the bat has hit the piñata. Go to the world functions, find both a and b, and drag it into the inner If condition. Bat Hit Method Drag a<b into both parts and choose any values. Click on baseballBat and go to its functions tab. Drag baseballBat distance to the left of into the first number and choose piñata. Then drag baseballBat distance to the right of into the third number and choose piñata.

Now click on piñata in the object tree and find its functions. Drag piñata’s width into the two remaining spots. Bat Hit Method But since the measurement is from the center, we must divide piñata’s width by 2. Click the arrow next to it and select math, piñata’s width /, then 2. Do this for both places where you dragged piñata’s width.

To finish the method, click on score in the object tree, then drag the addPoints method into the If statement. This will give the player points only when the bat has hit the piñata. Bat Hit Method

Now we need to create two events: one to recognize when the player wins and another to swing the bat when the player presses the up key. Click create new event in the top of the window, and select While something is true. Events Right click on the blue area of the new event and select change to then When something becomes true.

Go to the world functions and drag a>=b into the condition. Select score.scoreValue from expressions then world.numWinningHits from expressions. Events Click on timer in the object tree then go to the properties tab. Drag timeLeft into the do Nothing and select set value to and choose 0. This will end the game when the player reaches the required number of hits.

Now click create new event and select When a key is typed. Change any key to Up. Then click the arrow next to Nothing and change it to batHit. Events

Finishing Up Now you are ready to play the game! Click play and try your best to break the piñata. Keeping track of a score can be used in many games. Some games require a certain score to reach the next level. Others may keep track of the players’ high scores. You can create different events and methods to update your score. All you need to do is keep track of your score and update its display.