Building a Complex Operator
Let's create an observable operator for the laser cannon functionality.
We'll cover the following
Now it’s time to put on our game designer hats and figure out what sort of weapons we should give the player.
If we give the player a laser cannon that can fire on every frame, then they’re practically invulnerable. That’s no fun at all. We’ll need to limit how often the player’s laser can fire.
We’ll need an observable operator that can take the game state, check to see whether a given condition is true (spacebar is pressed) and whether a given amount of time has passed since the last time it fired.
Complex operator for game
Alas, RxJS doesn’t have this built-in but it does contain the tools for us to build such an operator ourselves. In util.ts
we’ll add the following function:
Get hands-on with 1400+ tech skills courses.