Canvas game
Simon Willison said that he thought it wouldn't be long until someone made a MMO in Javascript using the canvas tag - and it's been something that stuck in my head. Last night I did a bit of playing around and came up with the basic framework for a minimal real time strategy game in pure javascript.
This is the first prototype of the idea. The thing on the left that looks like a pie chart is a Hatchery, it spawns blobs that go and eat the fungis. I'm thinking of building a minimal RTS based upon the Zerg class of Starcraft.
Technology
- Jquery for event normalization
- Underscore.js for enumeration mixins (.map, .reduce, etc...)
- Canvas for drawing everything
Challenges
The movement logic and drawing logic have to be seperated, so that eventually all the logic can run on a node.js server, and just send a json update of each of the blobs state every 300ms. In the meantime, the web browser has to be able to move and draw the blobs every 30ms. I have decided to do this by having a base class that handles:
- Position
- Motion vector
- Spatial lookups
The spatial lookups are particularly interesting - because the logic loop of the game is O(N^2) complexity where N is the number of blobs in the game, and it involves many distance calculations (each with a square root). These spatial lookups can be significantly sped up by using a two dimensional tree acceleration structure. My goal is to create a module for node.js that reimplements the slow parts of the base class in performant C++ if I get to the stage where the server can't handle all the game logic.