|
function Player() {
Body.call(this);
this.standardForce = 20000;
this.fireLossFactor = 0.01;
}
Player.prototype = new Body();
Player.prototype.constructor = Player;
Player.prototype.processInput = function(totalElapsed, elapsed, level, entities, keyboard) {
if (keyboard.pressed.forward)
this.forces.push(Vector2D.mul(this.lookDirection, this.standardForce / (1 + this.size)));
if (keyboard.pressed.backward)
this.forces.push(Vector2D.mul(this.lookDirection, -(this.standardForce / 2) / (1 + this.size)));
if (keyboard.pressed.left || keyboard.pressed.right) {
var perpendicular = Vector2D.cross(this.lookDirection);
if (keyboard.pressed.left)
this.forces.push(Vector2D.mul(perpendicular, 0.25 * this.standardForce / (1 + this.size)));
else
this.forces.push(Vector2D.mul(perpendicular, -0.25 * this.standardForce / (1 + this.size)));
}
if (keyboard.pressed.turnleft)
this.lookDirection = Vector2D.rotate(this.lookDirection, -(32 * elapsed / (1 + this.size)));
if (keyboard.pressed.turnright)
this.lookDirection = Vector2D.rotate(this.lookDirection, (32 * elapsed / (1 + this.size)));
if (keyboard.pressed.fire) {
var bullet = new Bullet(this.size * this.fireLossFactor);
this.size *= 1 - this.fireLossFactor;
bullet.lookDirection = new Vector2D(this.lookDirection.x, this.lookDirection.y);
bullet.position = Vector2D.add(Vector2D.mul(bullet.lookDirection, this.size), new Vector2D(this.position.x, this.position.y));
bullet.forces.push(Vector2D.mul(bullet.lookDirection, 50000));
this.additionalEntities.push(bullet);
}
if (this.size < 5) {
for(var j = 0; j < 200; ++j) {
var fragment = new ExplosionFragment(3 + Math.random() * 4);
fragment.position = this.position;
fragment.velocity = Vector2D.rotate(new Vector2D(Math.random() * 1000, 0), Math.random() * TWO_PI);
this.additionalEntities.push(fragment);
this.isDead = true;
}
}
};
|
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