From the course: HTML5 Game Development with Phaser
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Friendly fire
If we can simply spam the explosions, the game isn't very difficult at all. Let's add an extra element of strategy to our game by allowing the emitter particles to cause harm to the bunnies as well. This will require that we ensure, whenever we spawn an explosion, that we do so far enough away from any of our bunny entities that we do not cause any unnecessary deaths. So, inside of Gamejs, once again we'll scroll down to our update function, and we're going to copy this initial function here, which checks our space rocks against our emitters, and we'll paste that in below the other two overlap functions. In this instance we're going to check, instead of space rock group, our bunny group. We're going to check that against our emitter, which is named Burst. And when a collision is detected, we're going to invoke a new function called friendlyfire. So, let's create that function right now. Right underneath checkBunniesLeft. So friendlyfire as a new function, and here we'll pass through a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.