mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixed input controllerism - fixes #28
This commit is contained in:
parent
a59a258ad6
commit
f5eacb6335
13 changed files with 163 additions and 223 deletions
70
app/Game/Client/Control/PlayerController.js
Executable file
70
app/Game/Client/Control/PlayerController.js
Executable file
|
|
@ -0,0 +1,70 @@
|
|||
define([
|
||||
"Game/Core/Control/PlayerController",
|
||||
"Game/Client/Control/KeyboardInput",
|
||||
"Game/Core/NotificationCenter"
|
||||
],
|
||||
|
||||
function (Parent, KeyboardInput, NotificationCenter) {
|
||||
|
||||
function PlayerController (me) {
|
||||
|
||||
Parent.call(this, me);
|
||||
|
||||
this.keyboardInput = new KeyboardInput(this);
|
||||
|
||||
var keys = {
|
||||
w:87,
|
||||
a:65,
|
||||
s:83,
|
||||
d:68,
|
||||
|
||||
up: 38,
|
||||
left: 37,
|
||||
down: 40,
|
||||
right: 39
|
||||
}
|
||||
|
||||
this.init(keys);
|
||||
}
|
||||
|
||||
PlayerController.prototype = Object.create(Parent.prototype);
|
||||
|
||||
PlayerController.prototype.init = function (keys) {
|
||||
|
||||
this.keyboardInput.registerKey(keys.a, 'moveLeft', 'stop');
|
||||
this.keyboardInput.registerKey(keys.left, 'moveLeft', 'stop');
|
||||
|
||||
this.keyboardInput.registerKey(keys.d, 'moveRight', 'stop');
|
||||
this.keyboardInput.registerKey(keys.right, 'moveRight', 'stop');
|
||||
|
||||
this.keyboardInput.registerKey(keys.w, 'jump');
|
||||
this.keyboardInput.registerKey(keys.up, 'jump');
|
||||
}
|
||||
|
||||
PlayerController.prototype.moveLeft = function () {
|
||||
Parent.prototype.moveLeft.call(this);
|
||||
NotificationCenter.trigger('sendGameCommand', 'moveLeft');
|
||||
}
|
||||
|
||||
PlayerController.prototype.moveRight = function () {
|
||||
Parent.prototype.moveRight.call(this);
|
||||
NotificationCenter.trigger('sendGameCommand', 'moveRight');
|
||||
}
|
||||
|
||||
PlayerController.prototype.stop = function () {
|
||||
Parent.prototype.stop.call(this);
|
||||
NotificationCenter.trigger('sendGameCommand', 'stop');
|
||||
}
|
||||
|
||||
PlayerController.prototype.jump = function () {
|
||||
Parent.prototype.jump.call(this);
|
||||
NotificationCenter.trigger('sendGameCommand', 'jump');
|
||||
}
|
||||
|
||||
PlayerController.prototype.update = function () {
|
||||
this.keyboardInput.update();
|
||||
Parent.prototype.update.call(this);
|
||||
}
|
||||
|
||||
return PlayerController;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue