Unfair Punishment¶
In this lesson we will learn
- how to plan a fix with an IPO table
- how to improve gameplay by removing an unfair punishment
- how an object can delete itself when an event happens
In Game Design we learnt that unfair punishment damages the player's sense of control. We also found one in our game:
| Unfair punishment | Solution |
|---|---|
| A laser that hits an asteroid keeps going and can hit an astronaut behind it | the laser disappears when it hits the first object |
In this lesson we'll remove that unfair punishment.
Planning¶
We already have a solution: the laser disappears when it hits the first object. We also already know the tool for this, because we've used delete_object many times. So how should we use it here? Let's think about this:
- Which object needs to be deleted? → the laser
- Which events trigger the deletion? → either of the laser's collisions (with an asteroid or an astronaut)

We could add delete_object to both the asteroid branch and the astronaut branch of the laser's handle_collision method. But we want the laser deleted after every collision, so we can put it once at the end of handle_collision, outside the if.
Coding¶
Open Objects/Laser.py, add the highlighted code below and save it.
Code explanation
- line 52 → deletes
self(this laser) after any collision. It's outside theifandelif, so it runs whether the laser hit an asteroid or an astronaut.
PRIMM
- Predict what will happen when a laser hits an asteroid now.
- Run MainController.py and shoot at asteroids and astronauts.
- Investigate: what would happen if line 52 were indented one more level?
Commit and push¶
- In GitHub Desktop, type Laser stops at first hit in the Summary box.
- Click Commit to main.
- Click Push origin.