Broadcasting - Learn Coombe Dean

Broadcasting
(Adding a new level)
Games Programming in
Scratch
Games Programming in Scratch
L3 Adding a new level
Learning Objectives:
o Understand the purpose of repeat loops and procedures (broadcasts)
o Use a broadcast in your own Scratch program
Excellence
I can extend my program with additional features of my own ideas,
making confident use of looping and broadcasts
Developing
I can make use of broadcasts for different features within my
program and explain the benefits of their use
Secure
I can make use of loops and broadcasts within my program following
examples given, as well as describing their basic purpose
Foundation
I can make use of loops in my program with support and
describe why they are used
Games Programming in Scratch
L3 Adding a new level
What is better?
Both of the scripts below do the same thing, they
draw a square shape, but which is better…
This...
or This...
WHY?
Games Programming in Scratch
L3 Adding a new level
Efficiency of Code (Using ‘Loops’)
• Used to repeat commands automatically
• Can specify how many times or make it happen
forever
• Shorter code = Smaller program =
Better to look at + Easier and quicker for
computer to run
Games Programming in Scratch
L3 Adding a new level
Efficiency of Code (Using ‘Procedires’)
Here’s another question…
Why is…
Dance
Better than…
Left foot forward
Left foot back
Right foot forward
Right foot back
Raise arms
Clap
Lower arms
Games Programming in Scratch
L3 Adding a new level
Efficiency of Code (Using ‘Procedures’)
• Can be called or used as many times as needed without
having to write out the whole ‘Dance’ instructions each
time
And again…
• Shorter code = Smaller program =
Better to look at + Easier and quicker for computer to run
Games Programming in Scratch
L3 Adding a new level
Procedures or ‘Broadcasting’
• Look at the following example:
• When does the code block on the right run?
It runs all of these actions in the ‘Procedure’
each time the sprite touches the ‘Shark’
Games Programming in Scratch
L3 Adding a new level
Concurrent Events
• Using a broadcast can also make two things
happen at the same time
• Both blocks of code will run concurrently (at
same time!)
Games Programming in Scratch
L3 Adding a new level
Adding ‘Next Level’ using Broadcast
Use a ‘Broadcast’ to create more levels in your game…
1) Create a variable called ‘Level’
On the ‘Main Character’
2) Add events to ‘reset’ the level
to 1 when game starts
3) Add a ‘forever’ loop to check
when the Score has got to 10
(or whatever number you want)
before ‘Broadcasting’ Next Level event
Games Programming in Scratch
L3 Adding a new level
Adding ‘Next Level’ using Broadcast
Use a ‘Broadcast’ to create more levels in your game…
On the ‘Enemy’
4) Add events to ‘change’ the level
by 1 and reset score to 0 when it
receives ‘Next Level’ broadcast
To make the game get gradually harder, you can…
5) Change the ‘move 10 steps’ of the
enemy, and replace it with the ‘Level’
variable number (so that as the levels
go up, so does the speed of the enemy!)
Games Programming in Scratch
L3 Adding a new level
Doing more things with ‘Next Level’ Broadcast
There are more things you can do when the ‘Next Level’ broadcast
message is sent within the game
Stage – Make the background
change each time you go up a
level.
Enemy – Make an extra ‘clone’
enemy every time you go up a
level
Main character – Make the
main character do something
(like flash/change costume)
when go up a level
Games Programming in Scratch
L3 Adding a new level
Comment your Code
Games Programming in Scratch
L3 Adding a new level
Finding Ideas for other ‘Broadcast’ uses
• How do other games in the Scratch library
make use of Broadcasting?
• Type broadcast into the search box and look
at the code using the See Inside button.
• How could you build some of these ideas into
your own game?
Games Programming in Scratch
L3 Adding a new level
Broadcast – Your own idea!
Broadcasts can be used for lots of different things.
Try to now add another broadcast to your game for a
different idea…
You could use it to:
– Change the colour of a sprite temporarily (Looks)
– Change the costume (Look under the Costume tab)
– Change the background to create a new level