Rotating Tower Foundations

Yesterday I posted my rotating tower platform
game demo along with a vague promise I’d write up some ‘how to’ articles…

At its heart, the demo is just a slightly more complex
version of my earlier tiny platformer. The biggest
changes are in how its rendered (obviously) and in its more advanced
collision detection…

… but before I get into depth on those topics (upcoming articles) I will
give a brief run down of the basic game foundations, including

The code structure

The game loop

Loading assets

The module pattern, constants and variables

These are common topics across most HTML5 games, and they should be familiar
to anyone who has read any of my previous game articles. If you wanted to build
a real production-ready game you would most likely use a framework to provide
some of these base foundations, but for prototypes and simple games it’s easy
enough to build them yourself.

The Code Structure

The javascript code for this demo is broken into 2 parts:

common.js - general purpose game foundation code

tower.js - rotating-tower specific game code

In addition, a small 3rd party component, fpsmeter.js is used for the FPS counter.

Much of common.js has been extracted from previous games and provides:

The Module Pattern, Constants and Variables

While the common.js module exposes its helpers using traditional javascript objects as
namespaces, the main tower.js module uses the module pattern
to keep its implementation private.

Since this game is simple, we can benefit from keeping it in a single module, allowing
classes to share common CONSTANTS and give global (within the module) access to helpful
utility methods and shared objects (like the camera, player, and renderer)

Next Time…

That was a very brief tour through the code structure of the rotating tower demo, looking at the game loop,
the asset loaders, and the module pattern of the main game code. This is common infrastructure required by all
games and is a repeat of some of the work from my previous games

Next time we will take a look at how a 2D platform game can be rendered as a (simulated) 3D rotating tower.