160 likes | 280 Views
Extending the Pong Example. Barb Ericson Georgia Tech June 2011. Goals. Learn about Creating a variable to keep score Displaying text to let the user know if s/he won or lost Using broadcast and receive to allow sprites to communicate. Project Description.
E N D
Extending the Pong Example Barb Ericson Georgia Tech June 2011
Goals • Learn about • Creating a variable to keep score • Displaying text to let the user know if s/he won or lost • Using broadcast and receive to allow sprites to communicate
Project Description • We will add to the example in Games – 4 Pong to add a score that is displayed and tell you if you won or lost.
Big Picture • Open the pong game example • Create a variable to keep score • Create new text sprites to tell you if you won or lost • Use broadcast and receive to allow sprites to communicate
Open the Pong game • Click on File then Open • Select Examples and games and open 4 Pong
Create a variable • Click on "Variables" and then on "Make a variable" • Name the variable score • Click "OK"
Variable Tiles • When you create a new variable a set of 5 tiles are created • First controls the display of the variable • Uncheck to not display • Second sets the value of the variable • Third changes the value • Fourth shows the value • Fifth hides the value
Start Score at 0 • Drag "set score to 0" from "Variables" category after the "go to x: 13 y:157"
Increment Score • When the paddle hits the ball • Drag "change score by 1" from "Variables" • Drop before "move 5 steps"
Draw text sprites • Use the paint editor to paint text sprites • Select T for text • Select font type and size • Select color • Type the text
Hide text sprites • Select sprite under stage view • Select Scripts tab • Drag out "when green flag clicked" from "Control" • Drag out "hide" from "Looks"
Broadcast when lost • Two sprites can communicate using broadcast and receive • Have the ball broadcast the message "lost" • Click the down arrow to create a new message
Show text sprite • When the "You Lost!" text sprite receives the message "lost" • Show the sprite
Add a way to win • When the score equals 5 tell the user s/he won • And show "You Won!" sprite • Stop execution of all scripts
Challenges • Make the ball speed up over time • Add another variable named speed • Move by speed each time you hit the ball with the paddle • Play a sound when you lose or win • Try to create two player game with two paddles
Concept Summary • Variables • Can be displayed • Can be set to a value • The value can be changed • Incremented or decremented • You can create text sprites • That you hide when the game starts • Two sprites can communicate using broadcast and receive