Project 265: Gravity Dodger

9. Create hero boundary conditions

There are boundary conditions for our hero: enemy collision, left edge collision & right collision. Can you program what should happen in each of these cases?
Starting point file for this challenge

Your goal

Steps

1. Hero & Enemy Collision

When the hero collides with the enemy, the hero should disappear an the game should be over.  So we'll add an If Statement and add the "touching Enemy?" as the condition.  Then we can grab a "hide" block,  "wait .25 seconds"  and "stop all" to hide the character briefly and end the game.

2. Left Edge & Right Edge Collision

When the hero collides with the left edge of the screen, it should bounce and enable the controls to quickly move to the right. What should our X speed be set to when we hit the edge of the screen? A good setting would be zero, that way we don't have to move too quickly in the opposite direction.   So to test for the condition we'll add an If statement,  and a "touching edge" block.  Then head to the Motion tab and grab the "if on edge, bounce" block, then finally get the "set x speed to 0" block from Variables.

3. Prevent hero rotation

We need to make sure that our hero doesn't rotate when it hits the edge of the screen. Head to the right side of the screen to the Sprite Manager and click on the Direction button.   Set the rotation style to "do not rotate" on the right.

4. Make hero reappear when the game starts

When we created the hero and enemy collision, we made our hero disappear. How do we program our hero to show back up when the game starts?

5. Test hero boundary conditions

Add the Two Conditions we built to the forever loop. Any time we build new functionality, we want to test our project to make sure that it is working as intended. Does the game end when the enemy collides with the hero? Does the hero bounce off of the left and right portions of the screen?