(More) Basic blocks Broadcasting messages Lesson 2 (More) Basic blocks Broadcasting messages
Recall… The blocks you’ve learnt in the last lesson: Event blocks Motion block Look blocks Sound blocks
Basic blocks Motion block – point towards Control blocks Sprite pointing towards an object. Control blocks FOREVER: The command inside this block will be done forever. IF: If (something) is correct, then do the followings.
Basic blocks Sensing block Looks block Touching something Change backdrop
Broadcasting messages One sprite broadcasts a message The other (same) sprite will do the commands after receiving the broadcasted message (e.g. message1).
Exercise 2 Your task: The “Dog” sprite moves “like walking” towards the “Cat” sprite. (Hint: use FOREVER. Choose an appropriate speed(steps).) Set the starting position of the Dog (initialization). The “Dog” barks (once) when touching the “Cat”. (Hint: use IF)
Exercise 2 The backdrop of the stage changes when the “Dog” touches the “Cat”. (Use broadcast) The cat ‘meow’s back after the dog barks. Play background music of your own choice.
Exercise 2 Bonus feature: Create a pause/play button so that you can pause/play when clicked. Hint: Pause/play are like on/off. You may need . E.g. (odd no) mod 2 =1 (even no) mod 2 =0