Skip to main content
main-content
Top

About this book

Develop games using the JavaScript web scripting language. This compact short book will help you learn how to use modern JavaScript to make games for web browsers. They’re effortless to use and they work everywhere. If you’ve ever wanted to make a game, join author Christopher Pitt. You’ll start with nothing and build fun games, in no time at all.

What You'll LearnMake a game using JavaScriptMaster the game loopHandle player input, collision detection, gravity, ladders, and stairsWork with camera locking, mobs, and healthManage game inventoryHandle mapping and more

Who This Book Is For

Those who are new to game development with some experience with JavaScript and web development.

Table of Contents

Chapter 1. Introduction

Abstract
I'm a gamer. I've been a gamer since before I was a programmer. And yet I’ve never tried to build a game…until now. A few weeks ago, a coworker sketched a simple, beautiful platform game. The moment I saw it; I knew I wanted to build it.
Christopher Pitt

Chapter 2. The Game Loop

Abstract
Game loops are an essential part of every game. In this chapter, we’re going to set the stage for our game by creating a solid workflow and environment. We’ll see a few helpful libraries and render our first game character. This is gonna be fun!
Christopher Pitt

Chapter 3. Player Input

Abstract
What’s the difference between a movie and a game? Player input! In fact, it’s such a critical piece of game design that games are often defined by how they take player input.
Christopher Pitt

Chapter 4. Collision Detection

Abstract
It’s time for us to talk about collision detection. It affects obvious parts of our game, like walls we can’t walk through. Like floors we can’t fall through. It also affects obscure parts of our game like weapon projectiles and checkpoints.
Christopher Pitt

Chapter 5. Gravity

Abstract
In this chapter, we’re going to work on our code structure and add gravity to our game. We’ve already done most of the work for gravity, so it should be relatively straightforward to finish it up.
Christopher Pitt

Chapter 6. Ladders

Abstract
It would be pretty limiting if players could only move upward by jumping through gaps, or by jumping on boxes. Those aren’t the only options, though. We still have to learn about elevators, stairs, and ladders. Let’s start by building a ladder!
Christopher Pitt

Chapter 7. Stairs

Abstract
We’ve implemented jumping and climbing as the main ways to traverse a level vertically. These actions are great, but they limit level design to consist of platforms and ladders. Let’s expand our design options by implementing stairs (or the similar action of walking up slopes).
Christopher Pitt

Chapter 8. Camera Locking

Abstract
So far, we’ve limited the levels to the size of our browser window. That’s okay for a proof of concept, but real levels require more space than we’re currently able to give.
Christopher Pitt

Chapter 9. Projectiles

Abstract
Our game is full of keyboard control, but what about the mouse? This chapter is all about projectiles; how to fire them and how they move.
Christopher Pitt

Chapter 10. Mobs

Abstract
What fun would this game be if the player were to go through it all alone? What we need now are mindless mobs (or blobs if you prefer) to patrol and/or otherwise complicate the hero’s path.
Christopher Pitt

Chapter 11. Health

Abstract
I've played very few games where the first mistake leads to instant failure. Usually, there’s quite a lead-up to the final moment of failure. Sonic (https://en.wikipedia.org/wiki/Sonic_the_Hedgehog) loses his rings, Mario loses his powers.
Christopher Pitt

Chapter 12. Animation

Abstract
We’re nearing the end of our brief but enjoyable journey. It’s time to start adding some finishing touches. For instance, our sprites are too stoic. Let’s animate them!
Christopher Pitt

Chapter 13. Sounds

Abstract
Some of my fondest gaming memories are of the music and sounds I listened to as I played my favorite games. Whether it is the music of Bastion and Fez or the sounds of Stardew, our ears help us fully appreciate the game.
Christopher Pitt

Chapter 14. Gamepads

Abstract
We’re almost done now. Before we part ways, I thought it would be fun to experiment with gamepads. They’re only supported via JavaScript in a few browsers, but they sure are fun to use!
Christopher Pitt
Additional information