top of page

Train Expansion

In this game you are trying to keep the train running as long as you can while being faced with obstacles blocking the train's path.

In this tense game, you are trying to keep your train moving and alive. You do this by drawing tracks on the board for the train to follow, leading the train to stations, and giving your train more resources. You will also need to destroy natural resources that appear on the screen, which will sometimes take over the tracks that you have placed. Your goal is to keep the train surviving for as long as possible.


For this project, I programmed a game using Javascript in HTML5. Most of my programming work is done by using HTML5's canvas to be able to display the visual elements of my game.


One of my challenges with this game was to make the game work along a grid. Using some math and a 2-dimensional array I was able to work out the logic to make a grid in which different objects would appear. This also made it so that when the player drew tracks on the screen, the tracks would be placed into one of the cells.

Drawing Train Tracks

By using the Create Button, as well as buttons for tracks 1-6, the player can draw tracks on the screen. The player can also press the corresponding 1-6 keys or the C key on the keyboard to do this as well. 
Tracks cannot be drawn on top of each other, on top of stations, or on top of resources that spawn onto the screen. 


The Destroy button or pressing D on the keyboard allows the player to delete tracks from the screen. 

Screen Shot 2023-05-09 at 8.20.53 AM.png

Cell System

By using some math and logic in the HTML5 canvas object, I made my own cell system for the game. This was necessary to display modular pieces like the train tracks, as well as spawn the natural resources onto the board

Train movement

As the train moves forward it follows the path provided by the train tracks, turning where the tracks turn. This is done by first having the train "read" the track on the same "cell" that it occupies. Then the train evaluates whether it should stay at the current orientation or rotate along with the track. 

Natural Resources

Natural resources will spawn on the field and can be mined up to keep the train running for longer. However, they can also spawn on top of train tracks, which may cause the train to crash if it runs into the natural resource. In order to make sure that the game is fair to players, I programmed it so that natural resources can't spawn 

bottom of page