mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
In order to not provide deep exposure to PlayerController, we refactored it so that it is not visible anymore outside Player. Also we renamed isInBetweenGames to inBetweenRounds. Moved creation of PlayerController from GameController(s) to The channel Player and client Me.
68 lines
No EOL
1.7 KiB
JavaScript
Executable file
68 lines
No EOL
1.7 KiB
JavaScript
Executable file
define([
|
|
],
|
|
|
|
function () {
|
|
|
|
function PlayerController (player) {
|
|
|
|
this.player = player;
|
|
|
|
this._shift;
|
|
this._isJumping;
|
|
this._walkingDirectionStatus = 0;
|
|
|
|
this.inBetweenRounds = false;
|
|
}
|
|
|
|
PlayerController.prototype.moveLeft = function () {
|
|
if(!this.isPlayerInputAllowed()) return;
|
|
this.player.move(-1);
|
|
this._walkingDirectionStatus = -1;
|
|
}
|
|
|
|
PlayerController.prototype.moveRight = function () {
|
|
if(!this.isPlayerInputAllowed()) return;
|
|
this.player.move(1);
|
|
this._walkingDirectionStatus = 1;
|
|
}
|
|
|
|
PlayerController.prototype.stop = function () {
|
|
this.player.stop();
|
|
this._walkingDirectionStatus = 0;
|
|
}
|
|
|
|
PlayerController.prototype.jump = function () {
|
|
if(!this.isPlayerInputAllowed()) return;
|
|
this._isJumping = true;
|
|
this.player.jump();
|
|
}
|
|
|
|
PlayerController.prototype.jumpStop = function () {
|
|
this.player.jumpStop();
|
|
}
|
|
|
|
PlayerController.prototype.lookAt = function (options) {
|
|
if(!this.isPlayerInputAllowed()) return;
|
|
if(options) this.player.lookAt(options.x, options.y);
|
|
}
|
|
|
|
PlayerController.prototype.setInBetweenRounds = function(inBetweenRounds) {
|
|
this.inBetweenRounds = !!inBetweenRounds;
|
|
};
|
|
|
|
PlayerController.prototype.isPlayerInputAllowed = function() {
|
|
return !this.inBetweenRounds;
|
|
};
|
|
|
|
PlayerController.prototype.update = function () {
|
|
if(this._walkingDirectionStatus != 0) {
|
|
this.player.move(this._walkingDirectionStatus);
|
|
}
|
|
}
|
|
|
|
PlayerController.prototype.destroy = function() {
|
|
// extend if necessary
|
|
};
|
|
|
|
return PlayerController;
|
|
}); |