Skip to content

game module explanation

Tylar edited this page Mar 28, 2015 · 2 revisions

The game is divided into sections in the /ng-modules/ directory. I'm currently calling these game modules/screen/section directives. These modules include models, views, and controls for each "unit" of gameplay. For demonstration purposes, the "main menu" is a gameplay module.

I know this sounds like things are way overcomplicated, but I think the benefit of being able to segment out game sections for development is worth it in this case, so hang in there and I think you'll learn to like it.

what is in a module?

Anything can be a module, but game modules can generally be thought of a "scenes".

how do I debug a module?

In order to debug a module without traversing the whole game to get there, you can just navigate to localhost:8000/ng-modules/yourModuleName/ and you should get a fully loaded game at your module.

how do modules transition to one another?

The main controller will show() your module when another modules asks for it by name via an event. Likewise, in order for you to switch to another module, you do something like $emit('switchToModule', 'main-menu')

How do I get to the game data?

To read from the "global" game you should use the "data" service inside the "game" module. To do this, add require('game') to your module's dependencies, and add "data" to your controller's list of services.

Adding "game" module as dependency:

var app = angular.module('game-module-name', [
    require('game'),
    // other required modules here
]);

Accessing the game.data service:

app.controller("oneOfMyModuleControllers", ['data', function(data){
    console.log(data.shipHealth);
}

The data attributes and other methods on the game class used by game.data are in ng-modules/game.coffee. Ideally, use methods of this class to do game-logic related computations.

Clone this wiki locally