Game Development Reference
In-Depth Information
var size = sprite.getSize() || {width: 0,
height: 0};
return {
x: pos.x,
y: pos.y,
width: size.width,
height: size.height
};
};
};
The last two components used in the game are very simple and are slightly more
unique to this particular type of game than the other components. These components
are the Strength component and the LaserGun component, which gives entities
the ability to shoot laser beams at other entities.
The Strength component isolates the management of the player's own energy as
well as all enemy ships and everybody's lasers. This component is used to determ-
ine if an entity is still alive and how much damage it can cause on other entities upon
contact. If an entity is no longer alive (if its strength has gotten below zero) then it is
removed from the game altogether, as is the case with lasers every time they collide
with another entity.
var Packt = Packt || {};
Packt.Components = Packt.Components || {};
Packt.Components.Strength = function(pEntity,
pHP, pEnergy) {
var entity = pEntity;
var hp = pHP;
var energy = pEnergy;
// This is how much damage the entity causes
to other entities
// upon collision between the two
this.getHP = function() {
return hp;
Search WWH ::




Custom Search