|
function Bullet(size) {
Body.call(this);
this.size = 50 * size;
this.respectsBounds = false;
this.restitution = 2;
this.worldFriction = 0.01;
}
Bullet.prototype = new Body();
Bullet.prototype.constructor = Bullet;
Bullet.prototype.processInput = function(totalElapsed, elapsed, level, entities, keyboard) {
for(var i = 0; i < entities.length; ++i) {
var entity = entities[i];
if (entity != this && entity instanceof Enemy) {
if (Vector2D.distanceBetween(entity.position, this.position) < entity.size) {
for(var j = 0; j < 100; ++j) {
var fragment = new ExplosionFragment(3 + Math.random() * 4);
fragment.position = entity.position;
fragment.velocity = Vector2D.rotate(new Vector2D(Math.random() * 1000, 0), Math.random() * TWO_PI);
this.additionalEntities.push(fragment);
entity.isDead = true;
}
}
}
}
};
Bullet.prototype.update = function(totalElapsed, elapsed, level) {
Body.prototype.update.call(this, totalElapsed, elapsed, level);
if (this.lastCollision !== null) {
--this.size;
if (this.size < 1)
return true;
}
this.size -= elapsed * 4;
if (this.size < 1)
return true;
if (level.isOutsideBounds(this))
return true;
else
return false;
};
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Article videos
Oakmead Apps Android Games
21 Feb 2014: Best VB.NET Article of January 2014 - Second Prize
18 Oct 2013: Best VB.NET article of September 2013
23 Jun 2012: Best C++ article of May 2012
20 Apr 2012: Best VB.NET article of March 2012
22 Feb 2010: Best overall article of January 2010
22 Feb 2010: Best C# article of January 2010