Search⌘ K

Create and Display Enemies

Explore how to create and animate enemy objects in a COVID Fighter game using JavaScript. Learn to construct enemy data structures with position and speed, and display them on a canvas while implementing vertical oscillation and boundary collision logic.

Introduction

In this lesson, we will be building the enemies that will be shown on the canvas. Remember that each enemy object will be moving in a vertical direction and bouncing back when it reaches the boundary of the canvas. You have already written the logic to move an object vertically and then bounce it back in the Coding Challenge: HTML Canvas with Moving Object lesson. The only difference is that here, our object is an image.

Now, let's jump to the code.

Create the structure of the enemy

As a ...