Enemy Shots Using Operators and Observables

Learn to introduce enemy shots and control their frequency through the interval operator.

We should allow the enemies in the game to shoot as well, Otherwise, it will be an unfair universe that we’ll have created, and a boring one! To enable enemy shots, we’ll do the following:

  • Each enemy will keep an updated array of its own shots.
  • Each enemy will shoot at a given frequency.

For this, we’ll use an interval operator to store new shots in the enemy value. We’ll also introduce a new helper function, isVisible, that helps filter out elements whose coordinates are outside the visible screen. This is how the Enemy Observable looks now:

Get hands-on with 1400+ tech skills courses.