Game Dev Session – Nerding Out on Robotron

Pre-Feature Cleanup of Joust and Robotron

Over the weekend, I made a serious dent in the technical debt for the other canvas games, Joust and Robotron.

Before I did any of that, I poked at Joust and attempted to find the upper limit on the number of simultaneous player objects (it’s about 200 before the slowdown is noticeable)! Added more colors to make it fun!

Then I spent the better part of Saturday converting the mess of functions of both games into objects. The core logic was left alone, but I did find a few functions to clean up. The diffs were pretty massive due to these restructurings, with nearly full rewrites of all files, but I’m happy with the result.

I took Joust a step further in the refactor direction and included a knobs-and-levers.js for default value fiddling.

Robotron: 13 changed files with 564 additions and 585 deletions

Joust: 15 changed files with 528 additions and 641 deletions

I had gone further in getting Joust up to speed than I had in Robotron, but I started reading Ready Player One by Ernest Cline and when I got to the part where Wade fires up Robotron I nerded out so bad I nearly jumped out of my chair. Obviously, this means I have to abandon my forward progress on Joust and focus all of my attention on Robotron instead.

Adding Gamepad Support to Robotron and Creating a Controls Library

In Robotron, I wanted to get the controls updated as soon as possible to be able to more easily share it with people as I worked on it.

The next step was to add gamepad functionality. At first, I copied Centipede‘s controls.js file right into Robotron, but as soon as I started making changes to it to get it to integrate with Robotron, I realized it was going to quickly become a nightmare to maintain the differences in controls between the two games. They are similar enough (the key differences are the size of the game piece boundaries, and the twin-stick shooter capability needed by Robotron), that I was able to find a common configuration for controls.js that would work for both games.

Having to maintain the file in one game whenever I make changes in the other is a pain, though, so I looked into how I could host controls.js outside of the two projects.

I thought I could just source it directly from GitLab, so I created a public canvas-libs project, got the link to the raw content of the controls.js file, and put that in my index.html. However, when I loaded the game, the browser rejected the plain/text format from the raw source.

Refused to execute script from '' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.

I did a little digging and found GitHack, which takes the raw text and serves it with the proper Content-Type header. This worked great.

I also applied version control to the canvas-libs project so I don’t break Centipede when I push to canvas-libs.

There’s still some work to be done to clean up the interface with the library. Right now it’s called twice from the main.js game loop (to capture the controller on load and to handle pausing), and once in the player object.

Next steps

Up next, I’ll be adding shooting capability to the right-stick of the gamepad for Robotron to utilize. I’ll also be doing some refactoring of Robotron to consolidate the various global vars into a knobsAndLevers object.

Leave a Reply