Activity: Sprite Overlap & Events - Part 2
We use kind to give a label to our sprites so we can define how one kind of sprite will react when moving on top of another kind of sprite.
By making several cloud shaped sprites with the same kind of Cloud
, we can write code so that all of the clouds interact with the Helicopter
in the same way with an overlap event.
In this activity, the student will continue to work with:
- on overlap event with a kind applied to several identical sprites
- Overlap events
Concept: Kind Overlap Event “bump” action

Having sprites bump rather than pass over each other is useful game behavior for a kind overlap event. One way to simulate a bump is:
- Move the sprite in the opposite direction after the overlap (we will make it bump backwards). The faster we bump, the farther we move away from the overlap object
- Change x position by (-1) * (vx)
- Change y position by (-1) * (vy)
- Stop the sprite
- Shake the stationary object (cloud)
- Move 1 pixel (in any direction)
- pause
- Move back
Example #1: Bump action from overlap event
- Review the code below
- Create a new project and name it “copterBump1”
- Create the sample code and run the code
- Look at the overlap event - note which sprite is named sprite and which is otherSprite, and how the code creates the bump behavior
Student Task #1: Soft Landing
There is a “T” shaped landing area at the bottom of the example. The helicopter sprite should not go through the landing pad, it should land!
- Starting with example #1, replace the helicopter motion with the short method using dx (left-right buttons)
- Review the rest of the code, and then add an on overlaps event for when the helicopter overlaps with the landing (note the kind of LandingPad)
- The block of code in the overlap event should stop the helicopter velocity motion (setting both
vx
and vy
to zero) and then change the helicopter position up 2 pixels so it isn’t overlapping any more
- Challenge: add a new sprite and kind to the screen (for example, a mountain or a tree) and set the overlap action to make the helicopter sprite have an erratic motion after an overlap. This should require 3 or more changes in position and/or velocity
Challenge hint
Erratic motion can be made by changing the sprite position back and forth multiple times. Try changes in velocity and/or position separated by short pauses.
Student Task #2: Add a new unique sprite with kind of Cloud
- Starting with example code or task #1
- Add a new sprite that looks nothing like a cloud (for example, a hat or a tree)
- Make sure the new sprite has kind of Cloud even though it is not a cloud
- Position the new sprite so it is not touching any other sprite
- Challenge: add another Sprite that looks different from the previous new sprite and give it a kind other than Cloud and make sure it has a unique overlap event action (e.g. - might say something new)
- Test the overlaps on the new sprite(s)
What did we learn?
- Describe how a kind can improve code (for example, how it can make programming easier, more powerful, more efficient, …).
- Explain why in creating a “bump” effect negative
X
and Y
velocities are used to change the X
and Y
positions.