fixed input controllerism - fixes #28

This commit is contained in:
Logsol 2013-07-30 18:13:39 +02:00
parent a59a258ad6
commit f5eacb6335
13 changed files with 163 additions and 223 deletions

View file

@ -1,59 +0,0 @@
define(function () {
function InputController (player) {
this.player = player;
this._shift;
this._isJumping;
}
InputController.prototype.moveLeft = function () {
this.player.move(-1);
}
InputController.prototype.moveRight = function () {
this.player.move(1);
}
InputController.prototype.stop = function () {
this.player.stop();
}
InputController.prototype.jump = function () {
this._isJumping = true;
this.player.jump();
}
InputController.prototype.jumped = function () {
this._isJumping = false;
}
InputController.prototype.jumping = function () {
if (this._isJumping) {
this.player.jumping();
}
}
InputController.prototype.duck = function () {
this.player.duck();
}
InputController.prototype.standUp = function () {
this.player.standUp();
}
InputController.prototype.activateShift = function () {
this._shift = true;
}
InputController.prototype.deactivateShift = function () {
this._shift = false;
}
InputController.prototype.update = function () {
}
return InputController;
});

View file

@ -0,0 +1,40 @@
define(function () {
function PlayerController (player) {
this.player = player;
this._shift;
this._isJumping;
this._walkingDirectionStatus = 0;
}
PlayerController.prototype.moveLeft = function () {
this.player.move(-1);
this._walkingDirectionStatus = -1;
}
PlayerController.prototype.moveRight = function () {
this.player.move(1);
this._walkingDirectionStatus = 1;
}
PlayerController.prototype.stop = function () {
this.player.stop();
this._walkingDirectionStatus = 0;
}
PlayerController.prototype.jump = function () {
this._isJumping = true;
this.player.jump();
}
PlayerController.prototype.update = function () {
//console.log(this._walkingDirectionStatus)
if(this._walkingDirectionStatus != 0) {
this.player.move(this._walkingDirectionStatus);
}
}
return PlayerController;
});

View file

@ -112,10 +112,12 @@ function (Box2D, Settings, CollisionDetector) {
// to prevent higher jumping running uphill, etc.
}
/*
Doll.prototype.jumping = function () {
var vector = new Box2D.Common.Math.b2Vec2(0, -0.05);
this.body.ApplyImpulse(vector, this.body.GetPosition());
}
*/
Doll.prototype.destroy = function () {
this.body.GetWorld().DestroyBody(this.body);

View file

@ -15,7 +15,7 @@ function (Doll, Settings) {
this.lookDirection = 1;
this.moveDirection = 0;
this.isSpawned = false;
this.playerController = null;
}
Player.prototype.spawn = function (x, y) {
@ -177,11 +177,19 @@ function (Doll, Settings) {
if (!this.doll.getBody().IsAwake() && !this.isStanding()) {
this.setStanding(true);
}
if(this.playerController) {
this.playerController.update();
}
}
Player.prototype.destroy = function () {
this.doll.destroy();
}
Player.prototype.setPlayerController = function(playerController) {
this.playerController = playerController;
}
return Player;
});