Game Development Reference
In-Depth Information
shot, "./img/laser-blue.png", 8, 32);
spriteComp.setCtx(canvas.getContext());
var strengthComp = new
Packt.Components.Strength(shot, 10, 0);
var physComp = new
Packt.Components.Physics(shot);
var mockMove = new
Packt.Components.Move(shot, 15);
shot.addComponent("sprite", spriteComp);
shot.addComponent("move", mockMove);
shot.addComponent("physics", physComp);
shot.addComponent("strength",
strengthComp);
shot.setOnUpdate(function() {
mockMove.setDirection(0, -1);
mockMove.update();
});
shots.push(shot);
}
timeLastShot = time;
}
};
// Return a list of active shots
this.getShots = function() {
return shots;
};
};
With all of our major components in place, we're ready to take a look at the other
classes in the game. Remember, though, that the whole purpose of using compon-
ents is to simplify development and to loosen the coupling between individual pieces
of functionality. Thus, if we wanted to add more components to the game, say, an
explosion effect component, for example, all we'd need to do is follow the same ba-
Search WWH ::




Custom Search