Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating your own Handheld Games Console

Similar presentations


Presentation on theme: "Creating your own Handheld Games Console"— Presentation transcript:

1 Creating your own Handheld Games Console
Coding the Micro:Bit Creating your own Handheld Games Console

2 Learning Habits Which learning habits will be important for this unit of work and why? Noticing details Adapting : Reflecting and making changes Reasoning: Thinking rigorously, methodically and giving explanations. Empathising… …with feelings and views Effective use of time Questioning: Asking questions to get below the surface Listening… …to understand Imagining… …how things could be and seeing a range of possibilities Distilling… …what you have learnt and what you need to learn Collaboration: Working effectively with others Meta Learning: Talking about how you have been learning Imitation: Picking up good habits from others Independence: Working effectively alone Managing distractions… …and sustaining concentration Capitalising: Using resources purposefully Making links… …and recognising relevance Perseverance: Overcoming frustration and difficulty Planning… …your learning in advance

3 Lesson Objectives Lesson Objectives
To develop our skills in programming using the blocks language To understand the purpose of variables To develop understanding of coordinates and see how they are used in developing graphical programs. Success Criteria ALL: To develop a simple pong game turning the device into a handheld console. MOST/SOME: To be able to develop the code to solve a number of challenges. Literacy – Key Words Variables A memory store in a program (think of it as a box which stores a piece of data) Coordinates A system which enables us to locate the position of an object using a horizontal (x) and vertical (y) . For example a pixel on a screen

4 Lets Create Pong! To create a Pong we need to understand a few things. 1. Coordinates Whenever we create computer games, we will need to draw items on the screen and update their position over time. The position of screen objects is always described with screen coordinates and the Micro:Bit is no exception. The LEDs on the Micro:Bit can be thought of as screen pixels and each LED can be described using an X and Y coordinate. X-Coordinates Y-Coordinates This LED has the coordinate (3, 2)

5 Lets Create Pong! 2. X-Velocity / Y-Velocity So we should now be OK with the idea of X and X positions of the LED’s on the Micro:Bit. The next thing to understand is that when we wish to update the position of a screen object (lit up LED), we do so using X and Y velocities. This is not as scary as it sounds. It simply stands for a number which we use to add to an item’s coordinate so that it can be repositioned on the screen and therefore appear to be moving. For example, if the LED (3,2) had an X-Velocity of 1, it would move to the right 1 place each time the screen was updated. X-Coordinates Y-Coordinates This LED has the coordinate (3, 2)

6 Lets Create Pong! 3. Variables So that we can keep track of the item’s coordinates and other data, variables are required. Variables are simply stores of data (think of them like boxes to store a stuff in). To create a variable and store data in them, we will need to use the following scripts: This allows us to create new variables and give them names This allows us to set our variables to particular values (ie store data in the variable)

7 Step 1 - Coding Pong Go to www.microbit.co.uk/create-code
Click on ‘New Project’ Create the following script: This scripts will create the start screen, plotting the ball and paddle to start the game. Create 5 variables Set each variable to the values you see in the example script. Use a ‘Show LEDs’ script and tick the bottom row. Plot the ball using the ball’s x and y coordinates. Plot the Paddle using the paddle’s y coordinate (hardcode the x coordinate to 0)

8 Step 1 - Coding Pong Next, create the following scripts:
These scripts move the paddle up and down when the appropriate button is pressed. Create a ‘when the A/B button is pressed’ script Un-plot the paddle from the screen If the paddle is not already at the top / bottom of the screen, change its y position so that it moves up /down Otherwise, redraw the paddle in the same positon as before (ie. no movement).

9 Step 1 - Coding Pong Finally, create the following script:
This script moves the ball around the screen, bouncing off walls and the paddle, or shows an X if the paddle misses the ball. In a forever script, begin by un-plotting the ball Then, in an IF statement, code the condition that if the ball is at the right hand side of the screen, change the x-velocity so that it moves left (bounces back) – otherwise let the ball continue to move left. Then in another IF statement, code the condition that if the ball is at the left side of the screen and level with the paddle, change the x-velocity so that it bounces off the paddle, otherwise clear the screen and show a cross (ie. game over). Then in a final IF statement, code the condition that if the ball is at the top or bottom of the screen, change the y-velocity so that it bounces back into play. Finally, update the position of the ball with the updated velocities and re-plot the ball. Pause for a short while and repeat.

10 Step 2 – Compiling and Flashing
If its working it is time to COMPILE and FLASH. Press the COMPILE button. Once the HEX file has downloaded, go into your documents and find it. Now plug in your device to an available USB port. Open the device up as if it were a USB memory stick. Now drag the HEX file into the opened device folder (as if you were transferring files to a memory stick). Now the FLASHING will be complete and you can try out your software on your Micro:Bit.

11 Your Working Handheld Games’pong’sole

12 Class Tasks Challenge 1 Speed up the game so that the ball moves faster. Challenge 2 Add a variable called score and add a script so that each time the paddle and ball meet, the score variable is updated by 1 and this score is shown at the end of the game. Challenge 3 Add a script which will pause the game when both the A and B buttons are pressed.

13 Class Tasks – Possible Solutions
Challenge 1 Challenge 2 Challenge 3 + + +


Download ppt "Creating your own Handheld Games Console"

Similar presentations


Ads by Google