This tutorial was written by Allie Burnquist for Start-Up Studio at the Natural History Museum in Albuquerque, New Mexico. It describes a Brick Breaker / Pong Paddle Type game.
- Create New Project
- File: New
- Rename Project
- Right-Click Cat Sprite and select Delete
- Create Paddle
- Option 1 – Choose new Sprite from Library
- Option 2 – Paint new Sprite and name it Paddle
- Give your Paddle Sprite Motion
- Events: Add when flag clicked
- Motion: Add go to X: 0 Y: -150
- Test: Move your Paddle Sprite anywhere on the Stage and then press the flag on the upper right hand of the Stage. Does your Paddle move back to the starting position?
- Control: Add a forever loop under the Motion command
- Control: Add an if/then statement inside of the forever loop
- Sensing: Add key space pressed? block into the if/then statement. Select the drop down menu on the key space pressed and select right arrow
- Motion: Add change x by 10 inside the if/then statement under the key right arrow pressed then and change 10 to 15
- Test: Press the flag again to reset the Paddle and press the right arrow key. Does your paddle move right?
- Select if/then statement and drag out of the forever loop. Select the duplicate stamp and stamp the if/then statement to create a duplicate. Drag one under the other until they attach. Drag both back into the forever loop.
- Select the drop down menu on key right arrow pressed in the second if/then statement, then select left arrow. Change move 15 steps to -15 steps inside of the second if/then statement.
- Test: Press the flag again to reset the Paddle and press the left arrow key. Does your paddle move left? Now try the right arrow key. Does that still work?
- Note: At any time you can use the duplicate, delete, shrink or grow an item. You can also copy Script from one Sprite to another by grabbing the Script and dragging it over the Sprite you wish to copy to.
- File: Save Now
Now we have a Paddle that moves both left and right. Time to work on our Ball.
- Create Ball
- Option 1 – Choose new Sprite from Library
- Option 2 – Draw new Sprite and Name it Ball
- Give your Ball Sprite Motion
- Events: When flag clicked
- Motion: Go to X: 0 Y: 190
- Test: Move your Ball Sprite anywhere on the Stage and then press the flag on the upper right hand of the Stage. Does your Ball move back to the starting position?
- Motion: Point in direction 90 under Motion command
- Operators: Add pick random 1 to 10 into the point in direction, replacing the 90. Change the 1 to 10 and the 90 to 225
- Control: Add a forever loop under the Motion command
- Motion: Add move 10 steps into the forever loop and change 10 to 15
- Test: Press the flag again to reset the Paddle and activate the Ball. What happened to the ball? Try pushing the flag a few more times. Does the ball come down too fast? Try adding a wait 1 second Control before the forever loop. Play with the time. I like .5 seconds. How do we get the ball to bounce back?
- Motion: Add if on edge bounce into the forever loop under move 15 steps.
- File: Save Now
Now we have a moving Paddle and bouncing Ball, but we need to stop the ball from going through the Paddle.
- Control: Add an if/then statement inside of the forever loop under the if on edge, bounce Motion
- Sensing: Add touching? block Select the drop down menu and select Paddle.
- Motion: Add point in direction 90 under touching Paddle
- Operators: Add pick random 1 to 10 into the point in direction, replacing the 90. Change the 1 to 90 and the 30 to -30
- Test: Press the flag again to reset the Paddle and activate the Ball. Use your right and left arrows to move the Paddle and stop the ball from hitting the bottom of the Stage
- File: Save Now
- Prepare the Backdrop and Add Sound
- Stage: Backdrops
- Add a rectangle along the bottom of the Stage
- Select Ball Sprite: Scripts
- Controls: Add if/then statement inside the forever loop under the first if/then statement
- Sensing: Add touching color? into the if/then statement. Click the square of color in the touching color? block then select the rectangle on the bottom of the Stage
- Sound: Add play sound pop into the if/then statement under touching color? block
- Controls: Add stop all into the if/then statement under play sound pop Sound
- Test: Press the flag again to reset the game and try to play. Where did the sound go? Stop all ends up stopping the sound before it starts. Try placing a wait 1 second block between the play sound pop and stop all. Try playing with the time until you find one that works. I like .05. Once you find the right time, try to play the game again. Does everything work now? How could the game be better?
- File: Save Now
If everything is working right there are a few more things we can add to make our video game more dynamic.
- Adding a Game Over Screen
- Option 1 – Choose new Backdrop from Library
- Option 2 – Paint new Backdrop
- Add text and decorate the page however you would like and move back to the Script for Ball Sprite by clicking on the Ball Sprite
- Looks: Add switch backdrop to block in the second if/then statement in the forever loop between the play sound pop and wait .05 seconds. Select the drop down menu on the switch backdrop to block to backdrop 2
- Select backdrop 1 in backdrops and press the flag to see if it works. Want to hide the Ball and Paddle Sprites when the Game Over Screen comes up?
- Looks: Add hide block into the second if/then statement in the forever loop between switch backdrop to block and wait .05 seconds block and try again.
- Events: Add broadcast block into the second if/then statement in the forever loop between hide block and wait .05 seconds block. Select the drop down menu and choose new message and name the message Game Over.
- Select the Paddle Sprite
- Events: Add when I receive to the Script. Select the drop down menu and choose Game Over message
- Looks: Add hide block to the when I receive Game Over event
Right now the Ball and Paddle are hidden so we need to add a show command.
- Events: Add when space key pressed. Select the drop down menu and select space
- Looks: Add show block to when space key pressed
- Select go to X: 0 Y: -150 and drag script away from when flag clicked block and move to the when space key pressed block under show block
- Looks: Add hide block to when flag clicked
- File: Save
This is the final Script for the Paddle! We want to match the start commands with the Ball, so select the Ball Sprite to change the Script and repeat the previous steps.
- Events: Add when space key pressed. Select the drop down menu and select space
- Looks: Add show block to when space key pressed
- Select go to X: 0 Y: 190 and drag script away from when flag clicked block and move to the when space key pressed block under show block
- Looks: Add hide block to when flag clicked
- File: Save
This is the final Script for the Ball Sprite. Next we will create a title screen
- Adding a Title Page
- Option 1 – Choose new Backdrop from Library
- Option 2 – Paint new Backdrop
- Add text and decorate the page however you would like. Press Script at the top of your work area next to Backdrops.
- Events: Add when flag clicked
- Looks: Add switch backdrop to block. Select the drop down menu and select the background you created for a Title screen. Mine is called Backdrop 3
- Controls: Add forever loop under the Looks command
- Controls: Add if/then statement into the forever loop
- Sensing: Add key pressed? block into the if/then statement
- Looks: Add switch backdrop to block to the if/then statement under the key pressed block. Select the drop down menu and select the game play backdrop with your rectangle at the bottom of the screen. Mine is called Backdrop 2.
- Test: Click the flag in the upper right hand corner of the Stage area and play your game. Does everything work? What else could we add?
- File: Save
This is the final Script for the Backdrops. Now we can either add a score counter.
- Adding a Score Counter
- Select Ball Sprite to enter Ball Sprit Script
- Events: Add when flag clicked
- Data: Select make a variable and name variable Score (make sure for all Sprites is selected) and check mark Score variable
- Data: Add hide variable to when flag clicked block. Select drop down menu and select Score
- Events: Add when key pressed block. Select drop down menu and select space.
- Data: Add show variable to when space key pressed. Select drop down menu and select Score
- Data: Add set to under set variable Score. Select drop down menu and select Score set blank number to 0
- Control: Add forever loop under set score to 0 block
- Control: Add if/then statement inside forever loop
- Sensing: Add touching? block to if/then statement. Select drop down menu and select Paddle
- Data: Add change by block to if/then statement under touching paddle? block. Select drop down menu and select Score and set blank number to 1