Presentation is loading. Please wait.

Presentation is loading. Please wait.

Games Programming in Scratch

Similar presentations


Presentation on theme: "Games Programming in Scratch"— Presentation transcript:

1 Games Programming in Scratch
Lives and Scoring Games Programming in Scratch

2 Learning Objectives: We are learning to…
Understand and use variables in a program Annotate a program with comments to explain scripts

3 Today’s Lesson Learning Objectives:
Understand and use variables in a program Annotate a program with comments to explain scripts Excellence I can extend my program to use variables of my own idea and fully explain scripts I have created using comments Developing I can use multiple variables in a program and add comments to explain how they are used Secure I can describe the purpose of variables and use them in a program following instructions given Foundation I can with support use variables in a program

4 But, at the moment.. What happens when one sprite touches another one?
So far… Planned idea for our game Added ‘Sprites’ that move in Scratch Main Character that moves with arrow keys 2nd Character that moves on it’s own (Don’t worry, we will change these to your own chosen characters later!) But, at the moment.. What happens when one sprite touches another one?

5 What ‘should’ happen when one sprite touches another?
When? Forever / When clicked / On a key-press Condition? If touching… / If time exceeds… / If x = y… What do you want to happen? Change colour / end game / go back to start

6 If Spaceman touches Asteroid then Game Over
Looping and Selection The easiest possible answer might be… If Spaceman touches Asteroid then Game Over If... Then Forever loop The ‘loop’ is used here to keep checking ‘if’ the Astroid is touching the spaceman, and ‘if’ it is, ‘then’ it says “Game Over” and stops then game.

7 Looping and Selection Loops and Selection can be used to do LOTS of different things in program (and a game). Repeat sounds or movement Repeat counting something Check if touching something Check a score or lives And loads loads more things!

8 Modifying your game Today’s Task 1 Open your game from last lesson
For ‘Main Character’, change your ‘Movement’ controls so that they use ‘Forever’ and ‘If…then’ blocks Delete the original ‘movement events’ (e.g. up, down, left, right) Add these ‘blocks’ instead NOTE!: This will make the ‘up arrow’ work. You need to extend it to add the other directions!

9 What is a ‘Variable’? A variable represents a location in memory
This location is used to hold a value which you assign to it. You can change the value in the program. You give a variable a name, which you use to refer to it, for example to set an initial value, change, use or output the value. For example: A variable called “Lives” might hold the value “3”. Set Lives = 3

10 Variables

11 Writing the algorithm Discuss in pairs! 2 mins
What are the steps required to set the starting value of lives and reduce that by one when one sprite touches another?

12 Programming Lives When game starts Start with 3 lives Check constantly
If.. you are touching an enemy Subtract 1 life

13 Adding ‘Lives’ to game using Variable
Today’s Task 2 Adding ‘Lives’ to game using Variable Create a ‘Variable’ under Data, and call it ‘Lives’ Then add the following blocks to your game Change this to the whatever your ‘Enemy’ is called Think about the Algorithm! When game starts Start with 3 lives Check constantly If.. you are touching an enemy Subtract 1 life Test it out… Does it work? What is it doing?

14 NEXT: Scoring What will these blocks do in your game?
What makes you earn points in the game? Collecting something? Beating a timer? Solving a problem? Use of Show and Hide blocks for items to collect What will these blocks do in your game?

15 Adding item to ‘pick-up’ (collect)
Today’s Task 3a Adding item to ‘pick-up’ (collect) Add a new sprite from the library for something that you are going to ‘collect’ (e.g. Apple, Coin)

16 Adding ‘Score’ to game using Variable
Today’s Task 3b Adding ‘Score’ to game using Variable Create a ‘Variable’, and call it ‘Score’ Then add the following blocks to your game to the object you want to collect! e.g. Coin, Apple Test it out… Does it work? What is it doing?

17 Variable display settings
Show or Hide Integer variable Slider Large or Small (With or without label) Moveable

18 Ending the game How could you add an ‘ending’ to the game?
What should make the game stop? Could be a running of ‘time’ or ‘lives’ maybe? We will look at the ‘lives’ option. What would be the steps (algorithm) for using ‘lives’ to stop the game? When game starts Check constantly If.. Lives = 0 Say message “Game Over!” Stop all game

19 Add ‘Ending’ to the game
Today’s Task 3b Add ‘Ending’ to the game Add the following blocks to your ‘Main Character’ Try it out! Does it work?

20 Adding Comments in Scratch
Comment boxes in Scratch help you, and others, understand your code at a later date Commenting is good practice for professional programmers


Download ppt "Games Programming in Scratch"

Similar presentations


Ads by Google