Wiff-Waff+Game




 * This lesson will cover**
 * Variables
 * Procedures
 * Collision detection
 * Mobile features**
 * Working with graphics
 * Using timers in games
 * Using timers in games


 * Plus, as an extension**
 * Motion detection and control

Your teacher will demonstrate a classic bat & ball game. This is the app that you are about to create. In this game, the bat will move continuously and the user will change its direction by clicking the arrow buttons at the bottom of the screen. This makes the game quite challenging, but more fun to play!
 * Introduction**

//**Task 1: Creating the interface**// Create the interface for this app as shown over leaf.

It is easier to work with a white background as you assemble the components.
 * Hint**: Set the Screen component’s background colour to Black **at the very end**.

There is no screencast this time try and code this yourself!
 * Task 2 - The coding**

Let’s consider the main steps we need to code in our game. There are **four** main stages: Let’s design these stages by creating an algorithm for each one .
 * set up the game
 * move the bat
 * ball collides with bat
 * ball reaches an edge

**Algorithm**
set the score to 0 set the ball enabled to true (lets it move) set the ball colour to green set the ball’s coordinates to 150, 150 set the ball’s heading to a random number between 45 and 135 degrees disable the start button
 * to Set Up Game (procedure)**


 * when Start button is clicked**
 * call Set Up Game procedure**

set bat heading to 180 (left)
 * when left button is clicked**

set bat heading to 0 (right)
 * when right button is clicked**

play beep sound set ball heading to ball heading - random number (say, 170 to 190)
 * when ball collides with bat (use Ball.CollidedWith block)**
 * call Increase Score procedure**

sides || ** -3 ** || if edge = -1 (bottom of screen) else bounce ball off edge play beep sound
 * || ** 1 ** ||  ||
 * ** 3 ** || Screen
 * || ** -1 ** ||  ||
 * when ball reaches an edge (use Ball.EdgeReached block)**
 * call Lose Game procedure**

add 10 to score set Score label text to “Score: “ + the score
 * to Increase Score (procedure)**

play lose sound play vibration for 500 millisecs set ball paint colour to red disable the ball (stop it moving)
 * to Lose Game (procedure)**

Add buttons which allow the user to select levels: Easy, Medium or Difficult. Each of these buttons should adjust the speed of the ball to suit.
 * Extension 1: Skill levels**

Let’s add motion control to our game, so that tilting the phone will move the bat.
 * Extension 2: Cool feature**

You will need to add an **OrientationSensor** component to your app (**Sensors→OrientationSensor**). In this app, we will use the sensor’s **roll** value, which detects left and right tilt on the phone.
 * Note that this feature will only work on a phone.**

//**Algorithm**//
if orientation sensor roll > 0 then (phone is tilted to the right) set the bat heading to the right (0) else (phone is tilted to the left) set the bat heading to the left (180)
 * Moving bat (using Orientation Sensor)**