Communicating between objects MESSAGE PASSING. CHALLENGE Can YOU do WHACK a MOLE in less than 5 minutes?????

Slides:



Advertisements
Similar presentations
Create a Simple Game in Scratch
Advertisements

In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.
Create a Simple Game in Scratch
Mission Technology Introduction to Scratch! June 2007.
Pong! “The oldest commercially available game in history” Resources created from the video tutorials provided by David Phillips on
Harry Potter Scratch Game
Adventures in Animation Harry Potter Game Pranali Choubal Kunal Shaw Barb Ericson Dec 2007.
A Christmas Scratch game
Code Club Session 3 Shark Eats Fish. Picture of finished product here.
This game is loosely based on the Whack-A- Mole arcade game.  Each game starts with 45 seconds of play.  Moles randomly pop out of holes on the landscape.
Write Your First Computer Game!. Coding: Programming Languages Just like you can speak Chinese to someone who understands Chinese to tell them what to.
Scratch Programming Session 9 of 10 Review elements to use in stories, games, etc.
Extending the Pong Example Barb Ericson Georgia Tech June 2011.
Adventures in Animation Introduction to Scratch! Michelle Venable-Foster June 2006.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
CATCH SCRATCH! Programming from Scratch. Remember Scratch?
Code Club Session 2 Dance Party. What will we learn ?  How to change the background  How to create animations  How to make objects talk to each other.
Introduction to Scratch!
How to make Space Invaders
Timers Exploring Computer Science Lesson Objectives The students will be able to: Create a timer.
Using MIT Scratch for Programming and Control Exercise 3 Ball Game Year 9 ICT Autumn Term 2007.
We will be creating a spaceship that simulates real movements in space. The spaceship will fire a laser beam that can destroy targets. The spaceship will.
©Robomatter – Distribution or copying without permission is prohibited. 3B STEM Computer Science 1 ©Robomatter – Distribution or copying without permission.
Using MIT Scratch for Programming and Control Exercise 6 – Creating a Scratch Packman Year 9 ICT Autumn Term 2007.
How to make a Shooting Target game in Scratch!. WE ARE GOING TO MAKE A TARGET GAME. This game will have: A Target that will move when clicked. A Timer.
ACO 101 Making a program. mb_your_brain_on_improv.html mb_your_brain_on_improv.html.
2015 CSE/EGR Summer Camps 1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed.
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
Flip the Tiles Brought to you by powerpointpros.com.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Variables and Random Numbers Computer App Session 4.
Marble Racer. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
Scratch for Interactivity Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
Get Going On ….. Load the word file ‘Glossary’ and complete it. You will have homework today.
How to create a basic game in Scratch. The Scratch Stage The Scratch stage is 480 pixels wide and 360 pixels high x increasesx decreases.
Lives and Scoring Games Programming in Scratch. Games Programming in Scratch L2 Lives and Scoring Learning Objectives Define a variable Understand the.
CoderDojo Sligo "Above all, be cool" Code and notes by Michael Madden, 2012.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Index Background Costumes Making object walk smoothly Controlling an object with the keyboard Control an object with the mouse Changing costume when hit.
Scratch Helicopter Game
Create a Halloween Computer Game in Scratch
Intro CS – Screens and Variables
Broadcasting (Adding a new level)
Games Programming in Scratch
Scratch for Interactivity
Building with Numbers Module 4: Investigation 2 Timers and Stopwatches
How to develop a presentation portfolio in Foliotek
Scratch for Interactivity
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Stopwatch Cards Stopwatch Cards
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Maze Race. Maze Race Race The first thing you need to do is change the background so click on stage. Then click on background. Now click paint Select.
Stopwatch Cards Stopwatch Cards
Stopwatch Cards Stopwatch Cards
Game Over Module 4 Lesson 2.
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Stopwatch Cards Stopwatch Cards
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Creating a Simple Game in Scratch
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Stopwatch Cards Stopwatch Cards
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Stopwatch Cards Stopwatch Cards
Presentation transcript:

Communicating between objects MESSAGE PASSING

CHALLENGE Can YOU do WHACK a MOLE in less than 5 minutes?????

OBJECT COMMUNICATION Here’s a problem If one sprite needs to react to a change as a result of a different sprite’s activity, how can we do that? Well, there’s a way we could do it using variables…

OBJECT COMMUNICATION Using Variables to communicate We could create a variable that sprite1 changes (by say, adding a score to it) In sprite 2, we could forever check the value of the variable. When it reaches say, 100, we could make sprite 2 go faster (make the game harder) But there’s an easier way…

OBJECT COMMUNICATION broadcasts Sprites (and the stage!) can broadcast to each other! It’s called a broadcast, because its just like a radio signal It goes out to everyone (including the sprite that sent it) Anyone can choose to react to a broadcast, or can ignore it Choosing to react to it is like ‘tuning’ your radio to a station

OBJECT COMMUNICATION broadcasts To create a broadcast… Go to the section Drag out to your code Click the down arrow, then new, and enter in a name for your broadcast Click OK!

OBJECT COMMUNICATION broadcasts To react to a broadcast… Go to the section Drag out to your code Click the down arrow, and select the name of the broadcast you wish to react to Add your code to react to the broadcast!

OBJECT COMMUNICATION Remember… Every object can react to a broadcast, including the Stage, and the sprite initiating the broadcast To react to a broadcast, an object must add the a ‘when I receive…’ section, and have the appropriate code The order in which sprites react is undetermined. So either a) don’t rely on the order, or b) if you must, add code to control the reaction order

OBJECT COMMUNICATION Add a start screen (to the stage), that has the words ‘press p to play’ When p is pressed… Change the background of the stage to the default ‘play’ background Broadcast a ‘GameStarted’ broadcast In the sprites, change their code when the app is started, to instead hide themselves Move the code you had into a section that reacts to the GameStarted signal Ensure it works!

OBJECT COMMUNICATION Augment what we did! Add a timer to the “mole”! Add a variable to track the score Every time 5 seconds passes, get the Mole to say (for 0.5 seconds) the ‘score’ which reflects how long it lived So if the score is ‘6’, it means the Mole survived for 30 seconds Add a second sprite, a dragon Make it start out more slowly But every time the Mole says its score (use a broadcast!), make the dragon go say, 10% faster (multiply its current movement speed by 1.1. You’ll need another variable)