Managing Collisions Using Operators and Observables
Explore how to manage collisions between shots and enemies in a reactive spaceship game using RxJS observables and operators. Understand how to detect hits, update game state, and use takeWhile to control game flow until a game-over condition occurs.
We'll cover the following...
We'll cover the following...
When a shot hits an enemy, we want both the shot and the enemy to disappear. Let’s define a helper function to detect whether two targets have collided or not:
Now, let’s modify the helper function paintHeroShots to check whether each shot hits an enemy or not. For cases where a hit occurs, we’ll set a property isDead to true on the enemy that has been hit, and we’ll set the coordinates of the shot ...