Game Development Reference
In-Depth Information
has include creating a new enemy entity and adding it to a list of active entities that
it stores, updating each entity individually, and removing any dead entities from the
entity list it manages.
// Namespace the enemy manager object
var Packt = Packt || {};
Packt.EnemyManager = function(canvas) {
var entities = new Array();
var canvas = canvas;
var worldWidth = canvas.getWidth();
var worldHeight = canvas.getHeight();
// By returning the list of active enemies to
the client code,
// we can pass on the responsibility of
rendering each entity,
// as well as allow other components to
interact with theentities
this.getEntities = function() {
return entities;
};
// Create a new entity at a certain screen
location, along
// with a list of components
function addEnemies(x, y, components) {
var entity = new
Packt.Entity(Packt.ENTITY_TYPES.SHIP, x || 0,y
|| -100);
for (var c in components) {
entity.addComponent(c, components[c]);
};
var strengthComp = new
Packt.Components.Strength(entity, 0.5, 25);
var physComp = new
Packt.Components.Physics(entity);
Search WWH ::




Custom Search