|
function Player() {
Body.call(this);
this.standardForce = 20000;
this.renderShadows = false;
this.renderFieldOfView = false;
this.isOneDown = false;
this.isTwoDown = false;
}
Player.prototype = new Body();
Player.prototype.constructor = Player;
Player.prototype.processInput = function(totalElapsed, elapsed, level, 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.85 * this.standardForce / (1 + this.size)));
else
this.forces.push(Vector2D.mul(perpendicular, -0.85 * 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 (this.isOneDown && !keyboard.pressed.shadows) {
this.isOneDown = false;
}
if (!this.isOneDown && keyboard.pressed.shadows) {
this.renderShadows = !this.renderShadows;
this.isOneDown = true;
}
if (this.isTwoDown && !keyboard.pressed.fov) {
this.isTwoDown = false;
}
if (!this.isTwoDown && keyboard.pressed.fov) {
this.renderFieldOfView = !this.renderFieldOfView;
this.isTwoDown = 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