A simple Tower D game written in NodeJS
Event Model: In order to process a ton of stuff that's going on, I've utilized a simple event-based model controlled by the 'world' (found in /world.js). When you start the server, it automagically instantiates a new 'world' and makes it global.
World is responsible for loading the initial objects into the world and from there, each object emits and listens to its own set of events.
I'll let the code do the talking:
@maps.push new map json.map
@emit 'load', _map for _map in @maps
# any class listening to world.on 'load' now has access to _map
@mobs.spawn [0, 0]
# a mob will now emit a spawn event, causing all others to react
towers.js `world.on 'load', (obj) -> # Ignore all other towers and maps if type == 'mob' # Check targets each time a mob moves
obj.on 'move', (obj, loc) -> @checkTargets obj, (res) -> ## Shoot some shit!~`
I'm still exploring this pattern so it may change dramatically, but it's the best I've got for now :D