November 2011
Intermediate to advanced
348 pages
7h 2m
English
In this recipe, we'll create a Model class which is responsible for initializing and updating the hero, the bad guys, the level, and the health bar. These objects can be seen as the "data" of our game.
Follow these steps to create the model for Canvas Hero:
Model constructor:/*
* Game model
*
* The model is responsible for initializing and
* updating the hero, level, bad guys, and health bar
*/
function Model(controller){
this.controller = controller;
this.healthBar = null;
this.hero = null;
this.level = null;
this.badGuys = []; // array of bad guys
this.heroCanvasPos = {};
}removeDefeatedBadGuys() method which loops through the bad guy array and then removes the ones that are no longer ...Read now
Unlock full access