Snake in CreateJS Tutorial Part 1

Hello

The snake is a really simple game that depends on moving a Snake and eating a food. Moving is restricted by a game borders and food position is randomly generated, so the player needs to move from one position to other having longer snake (each time he eats the food).

We are going to use the CreateJS library and it’s boilerplate that I’ve shown here: https://frontendgamedev.com/createjs-in-5-minutes/.

If you have any troubles with the CreateJS itself, I suggest you check the https://createjs.com/ site.

The code can be found in the repository: https://github.com/szymkab/frontendgamedev-snake.

So… let’s start.

Preparation of repository

In order to start working on the game, we need to clone the repository and run setup commands. I’ve described that process in the article mentioned above, so make sure you have done it and we can start.

Rendering a snake in a game world

Firstly, open the app.js file and remove the objects (graphics and text) that are added (line 25 to 38). Instead of sample code we are going to create a World class that will be responsible for rendering and controlling user input.

Create a World.js file in source/objects directory with class World:

// source/objects/World.js

export class World {
  constructor(stage) {
    this.stage = stage;
  }
}
Continue reading