Scratch More complex scratch
Feb 23, 2016
Scratch
More complexscratch
Lesson Objectives
● Understand the concept of a variable● Using the random function● Move towards● Keep track of score using a variable
Setting up the need for a variable
● Before we learn about variables we must create the “need” for them!
● First of all we will create a baddie which will move towards the player
Move towards
● Baddie moves towards pucman until they touch
● That is game over!● Otherwise it points
towards him● And moves slowly!
Activity
● Add a baddie and make it move towards pucman.
● Use collect version 1 to help you
Items reappears!
● Forever will keep looping, err, forever!● It will repeat whatever is inside it● When collected it will move to a new postion
Random position
● Pick random (under operators) allows you to pick a number between a set of values.
● This allows you to pick a new X and Y position for your item!
Activity
● Get your item to move once collected!
Variables
● A variable is something which can change!● It must have a name (so we can refer to it)● And a value!
● The value can change over time and can be checked● In a loop or a if statement
● A score will be a variable
How a score will work
● Initially set to 0 on game start● When a item is picked up it will increase by
a set amount● On game over it will be displayed!.
Adding a score
● Click on make a variable● Call it score!● You should see the
options shown on the right
Setting score to zero
● This script should be added to the player.
Item code
● The item needs to change the score.● This is added to the item's code as shown
below.
Activity
● Add score to your game.
● If your feeling adventurous.● Open up collect version 2.● See how it works● Add it to your game!