Game Development Reference
In-Depth Information
var timeLastShot = 0;
// Move all lasers forward, and remove any
lasers outsidethe screen
this.update = function() {
for (var i = 0, len = shots.length; i <
len; i++) {
try {
shots[i].update();
var shotPos = shots[i].getPosition();
if (shotPos.y < -100) {
shots.splice(i, 1);
}
} catch (e) {}
}
};
// Create a new laser entity, and assign all
of the components
// it will need in order to actually destroy
other ships
this.add = function(x, y) {
var time = Date.now();
// Don't add a new laser until at least
some time has passed,
// so that we don't fire too many lasers at
once
if (time - timeLastShot >= shotsPerSec) {
// Restrict the amount of lasers that can
be on the screenat once
if (shots.length < MAX_SHOTS) {
var shot = new
Packt.Entity(Packt.ENTITY_TYPES.BULLET, x, y);
var spriteComp = new
Packt.Components.Sprite(
Search WWH ::




Custom Search