...

/

Managing Collisions Using Operators and Observables

Managing Collisions Using Operators and Observables

Learn to emit values through the takeWhile operator.

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:

Press + to interact
function collision(target1, target2)
{
return (target1.x > target2.x - 20 && target1.x < target2.x + 20) &&
(target1.y > target2.y - 20 && target1.y < target2.y + 20);
}

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 ...

Access this course and 1400+ top-rated courses and projects.