60-Smart Enemy Shooting Backwards

In this post, another behavior to the previous enemy, such that when the player is above it, it will shoot up instead of down; once the player is below it, it will shoot down again.

This can be done by comparing the y position of the player and the enemy and set a flag to tell the enemy when to shoot backward or forward.

As the enemy’s laser inherited the laser behavior of the player, we can use the base.Move() of the parent class laser to make the enemy laser travel upwards when shoot backward is switched to true.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store