LittleTown Journey - Prototype Godot Train Game

This is a prototype for a small cozy train game. The goal is just to drive around and enjoy the atmosphere, and maybe honk the horn sometimes.

Most of my work in Godot so far has just been with small mechanics. By pushing the development closer to something akin to a real game, I was hoping to learn what parts of the process were difficult - thus hinting that I might need more practice there. It was a worthwhile exercise as I exposed the need to learn more about scene management and "meta" features (like menus and settings.)

Behind the scenes

Rail network generated from tilemap data

The rail network is constructed at runtime from the data built into the level. Tiles for the different types of rail were placed down in the Godot editor. When a level starts it runs an algorithm that builds the rail network from the tilemap data.

Getting that algorithm right was one of the most challenging, but rewarding, parts of this project. It required building a network of paths that handle looping and switching junctions. In the future I'd like to clean this algorithm up and share it as its own project.

The actual "tracks" are the Path2D nodes generated by the algorithm, with knowledge of the joining tracks at their head or tail.

Driving

The train cars - and engine - are PathFollow2D nodes. They travel along the track paths and if they are linked to another car then that follower will be pulled along as well. When reaching the head or tail of a section of track they re-parent themselves to the next section.

The first car is the "engine" and it uses a physics-based system for pulling the train. Each car added to the train adds to the "total_mass" value of the engine, which has a fixed horsepower. That means that shorter trains can get up to speed faster than long ones.

Extra Features

A few extra features were added in the spirit of polishing a simple mechanic into something that resembles a game.

Station Pickup

Periodically the stations in each town will fill up with demand and will show an orange alert bubble above them. If you bring the train to a full stop outside the station it will exchange passengers and remove the orange alert.

Day-Night Cycle

There is an approximately 8 minute day-night cycle that leverages an AnimationPlayer controlling a CanvasModulate as well as the visibility of some lights.

Birds

A tiny feature - driving quickly by invisible wildlife "area" nodes (or honking the horn while inside them) has a chance to spawn birds that fly away from the noise.

Demo

It just has one "level" and the only objective is to drive around. But still, I wanted to share it.

The demo is available to download for free on Itch.io.

This was shared on the Godot Subreddit.

You can play the demo in the browser here.

Published: October 8, 2021

Categories: gamedev