BBoard PONG game Creative Computing #1
BBoard Pong: Create the Pong game in Scratch (S4A)......but use your BBoard as the controller! Once you have learned some basic skills, you can create your own interactive games!
First step: Download Scratch4Arduino (S4A) Goto: s4a.cat Click on Downloads and follow the install instructions WATCH OUT! You will need to install some firmware onto your Arduino first. CLICK HERE for more help
Connecting BBoard to Arduino For power: B/B9 -> A/GND B/B8 -> A/5V To control red light: B/B1 -> A/D10 Don t worry about the colour of the wires. It doesn t matter - its only plastic covering!
Test: Is Arduino talking to the BBoard? Switch on the red light when...the space bar is pressed (Remember the BBoard red light is connected to the Arduino D10 port so when D10 is on, so is the red light)
Controlling the light using a button To receive button 1 press event: B/B5 -> A/D2 We are now going to change pressing the space bar with pressing the BBoard button (switch 1) Once we know how to do that, we can get both buttons working = a game pad!
Change Space bar press -> Button 1 press Now if the button 1 is pressed...it sends a signal to D2. Then D10 switches on the red light! Else, the light is switched off.
Challenge #1 If BBoard B3 connects to the green light and...the Arduino can accept another button event on D3...re-arrange these blocks to make button 2 switch on the green light
Solution #1 Now both button presses are captured...and result in a light being switched on or off
Wiring recap: Just to make sure! You should have the following wired up: B9 -> GND B8 -> +5v B1 (red light) -> D10 B3 (green light) -> D12 B5 (switch 1) -> D2 B6 (switch 2) -> D3
The next step: Create the PONG game We now have the basic wiring and skills sorted. Now we need to: 1. 2. 3. 4. 5. 6. Hide the Arduino and ports control Create the PONG sprites (bat, ball, boundary) - CLICK HERE for help Make the bat move when arrow keys are pressed Make the ball bounce around the screen until it hits the boundary Make the ball bounce off the bat Control the bat using the BBoard buttons
Hiding the Arduino sprite and panel SIMPLEZ! Use Hide from a When green flag event For the panel...right click and Hide
HELP! CLICK HERE Create the Pong sprites: bat, ball, boundary Don t forget to name the sprite appropriatley Click the paintbrush to create a new sprite Don t forget to centre the sprite!
Make the bat move when arrow keys are pressed IF left arrow pressed THEN Move bat 10 steps to the left END IF IF right arrow pressed THEN Move bat 10 steps to the right END IF
Ball bounces until hits the boundary Bounce around the screen...until it hits the boundary
Ball bounces until hits the boundary or bat Bounce around the screen...until it hits the boundary or...or the bat, where upon it bounces off
Move the bat with the BBoard buttons [Select the Arduino control] Create a movebatleft or movebatright broadcast event...if the button 1 or button 2 is pressed.
The new bat code IF button 1 pressed THEN Move bat 10 steps to the left END IF IF button 2 pressed THEN Move bat 10 steps to the right END IF
Extension challenges Player has x3 lives Indicate number of lives using lights on BBoard (x3 lights = x3 lives) Add sound when ball hits bat or boundary Start a new game by using the light sensor as another button