
It would be nice to know the exact score we get from shooting each invader. This lesson will teach you how to create a "dynamic score label" that appears, then animates out whenever you shoot an invader. It creates for a really cool effect and immediately makes your game start to stand out compared to before.
The checklist for this feature is as follows:
Create score label with document.createElement(label)
Append to DOM with document.body.appendChild(score)
Change element's innerHTML
Change style for position, color, top, left, and userSelect
Call gsap.to() for animation
On complete, get parent node and call removeChild()
It's time to add our game's first special weapons: explosive bombs that bounce off the edges of our screen, explode when shot, and remove a large portion of enemy invaders on touch.
This video's chapters include:
Create bomb class
Render moving bombs
Have bombs bounce off edges
Add projectile-to-bomb collision detection
Create explosion animation
Add bomb-to-invader collision detection
Remove bombs from scene
Spawn new bombs over time
Here we'll learn how to create a power-up effect—one that allows your spaceship to shoot yellow projectiles in a machine gun-like rhythm. We'll utilize event listeners, object properties, timers, and randomization to achieve this effect.
Our checklist for this feature is:
0:00 Create MachineGunPowerUp class
01:44 Render and move across screen
03:28 Add collision detection and splices
06:49 Activate power up and set timer
08:31 Create machine gun effect
11:08 Change projectile color
12:18 Limit machine gun
13:44 Garbage collection
16:12 Spawn in random locations
At the moment, I'd say our game is too easy. As a result, we'll be covering how to make our enemies harder in two ways:
By spawning them more quickly over time
By increasing their velocity over time
We'll also be adding functionality that allows an enemy to end the game if they touch our player directly. You'll learn a bit more about spawn timers and how to affect object properties based on special events.
00:00 Spawn enemies more quickly over time
06:42 Increase grid velocity on bounce
08:31 Kill player on touch
We can create an animation for our spaceship in two ways:
Through a sprite sheet
Dynamic elements created directly within canvas
We'll opt for the second method here because it lends to a more randomized look.
0:00 Feature summary
0:43 Populate particles array
5:54 Render new particles
10:38 Spread out particles
Rather than throwing a user into our game right on the initial page load, it'd be much kinder to present them with a start screen in which they can choose when they'd like to begin playing. It'd also be nice if they could restart the game after losing. To achieve this effect, we'll utilize some external assets and integrate HTML directly into our JavaScript.
0:00 Download assets
2:36 Add background asset
7:37 Add button asset
14:36 Add title
18:16 Add click event listener to button
21:13 Game over screen
29:16 Fix spaceship particle bugs
We'll utilize a third-party JavaScript library called Howler to add sound effects and music. Howler fixes some native JavaScript audio API issues, such as not being able to overlap audio playbacks on top of each other. We'll learn how to add audio assets, loop audio, and alter the audio's volume.
0:00 Credits
1:25 Download assets
2:52 Import assets
6:48 Implement sound effects
13:21 Limit play rates
15:33 Loop audio
16:02 Lower overall volume
Some of you may have noticed that your game runs a lot faster on your computer than it does on mine. This is due to requestAnimationFrame being dependent on your monitor's refresh rate.
Most monitors run at 60hz, but newer ones like MacBook pros run at 120hz instead. This effectively doubles the speed at which your game runs, so we need to take this into account when releasing our game for others to play.
A game can run completely off of one file, but if we're to continue to make updates, it can get a little annoying to find exactly what it is we want to edit. As a result, it makes sense to refactor things into a scalable, more organized format.
Here I'll show you how I'd organize our game to make things a bit easier to find while fixing a bug or two along the way.
Here you'll learn how to deploy your site to GitHub pages for free. In the end, you'll have a visitable link that you can send to friends, family, and more.
Check out the finished game and deployed link for my instance using the attached link.
PLEASE READ: This is a freemium course—the first 2 1/2 hours are free (you can watch right here on Udemy [or YouTube] with each video's "Preview" button), while the remaining 3 hours require course purchase. I've always been a big advocate of spreading the basics to as many people as possible, as I believe knowledge and personal growth are some of the best ways to better our world as a whole. Enjoy.
Welcome to the Code Space Invaders course, where you will learn how to create a custom variation of the classic game, Space Invaders. We'll use JavaScript and HTML5 canvas fundamentals to progressively enhance your game development skills, and go all the way 'til you have a full-blown Space Invaders game live on the web.
My name is Christopher Lis, and I'm an award-winning Full-Stack Engineer with over ten years of web development experience. I've directly worked with clients like Harvard University, The Basketball Tournament, and premium award-winning agencies like Brave People.
The goal of this course is to give you the skillset required to code your own JavaScript games from scratch. Many game dev fundamentals are covered in this course, and much of what you'll learn uses hand-written math functions rather than hidden away abstractions that game dev libraries typically provide.
In this course, you'll learn everything from:
Setup a development environment
Create and move a player's spaceship
Import game images
Generate grids of enemy invaders at set intervals
Shoot projectiles
Remove enemies with precise collision detectionk
Create bombs that explode multiple invaders at once
Obtain machine gun power-ups that alter your rate of fire
Make enemies progressively harder
Add particle animations that follow your spaceship
Develop a game UI using HTML and CSS
Start and end screens with a restart button
Add custom sound effects and music
Code consistent frame rates for all types of monitors
Deploy to GitHub pages
And so much more.
If you're serious about taking your game dev skills to the next level, then let me guide you through the full production of a 2D Space Invaders game that's ready for production launch.