mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
gameCommand implementation
This commit is contained in:
parent
6219a82fbd
commit
c4c48ab821
10 changed files with 62 additions and 39 deletions
|
|
@ -1,4 +1,10 @@
|
|||
define(["Game/Core/Control/InputController", "Game/Client/Control/KeyboardInput"], function (InputController, KeyboardInput) {
|
||||
define([
|
||||
"Game/Core/Control/InputController",
|
||||
"Game/Client/Control/KeyboardInput",
|
||||
"Game/Core/NotificationCenter"
|
||||
],
|
||||
|
||||
function (InputController, KeyboardInput, NotificationCenter) {
|
||||
|
||||
function KeyboardController (me, gameController) {
|
||||
|
||||
|
|
@ -42,22 +48,22 @@ define(["Game/Core/Control/InputController", "Game/Client/Control/KeyboardInput"
|
|||
|
||||
KeyboardController.prototype.moveLeft = function () {
|
||||
this.inputController.moveLeft();
|
||||
this.gameController.sendGameCommand('moveLeft');
|
||||
NotificationCenter.trigger('sendGameCommand', 'moveLeft');
|
||||
}
|
||||
|
||||
KeyboardController.prototype.moveRight = function () {
|
||||
this.inputController.moveRight();
|
||||
this.gameController.sendGameCommand('moveRight');
|
||||
NotificationCenter.trigger('sendGameCommand', 'moveRight');
|
||||
}
|
||||
|
||||
KeyboardController.prototype.stop = function () {
|
||||
this.inputController.stop();
|
||||
this.gameController.sendGameCommand('stop');
|
||||
NotificationCenter.trigger('sendGameCommand', 'stop');
|
||||
}
|
||||
|
||||
KeyboardController.prototype.jump = function () {
|
||||
this.inputController.jump();
|
||||
this.gameController.sendGameCommand('jump');
|
||||
NotificationCenter.trigger('sendGameCommand', 'jump');
|
||||
}
|
||||
|
||||
KeyboardController.prototype.jumped = function () {
|
||||
|
|
@ -70,7 +76,7 @@ define(["Game/Core/Control/InputController", "Game/Client/Control/KeyboardInput"
|
|||
|
||||
KeyboardController.prototype.duck = function () {
|
||||
this.inputController.duck();
|
||||
this.gameController.sendGameCommand('duck');
|
||||
NotificationCenter.trigger('sendGameCommand', 'duck');
|
||||
}
|
||||
|
||||
KeyboardController.prototype.standUp = function () {
|
||||
|
|
@ -79,7 +85,7 @@ define(["Game/Core/Control/InputController", "Game/Client/Control/KeyboardInput"
|
|||
|
||||
KeyboardController.prototype.activateShift = function () {
|
||||
this.inputController.activateShift();
|
||||
this.gameController.sendGameCommand('activateShift');
|
||||
NotificationCenter.trigger('sendGameCommand', 'activateShift');
|
||||
}
|
||||
|
||||
KeyboardController.prototype.deactivateShift = function () {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ function (Parent, PhysicsEngine, ViewController, KeyboardController, Notificatio
|
|||
|
||||
GameController.prototype = Object.create(Parent.prototype);
|
||||
|
||||
GameController.prototype.destruct = function() {
|
||||
//destroy box2d world etc.
|
||||
};
|
||||
|
||||
GameController.prototype.getMe = function () {
|
||||
return this.me;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
define([
|
||||
"Game/Core/Protocol/Helper",
|
||||
"Game/Client/GameController",
|
||||
"Game/Core/User"
|
||||
"Game/Core/User",
|
||||
"Game/Core/NotificationCenter"
|
||||
],
|
||||
|
||||
function (ProtocolHelper, GameController, User) {
|
||||
function (ProtocolHelper, GameController, User, NotificationCenter) {
|
||||
|
||||
function Networker (socketLink) {
|
||||
this.socketLink = socketLink;
|
||||
|
|
@ -29,6 +30,7 @@ function (ProtocolHelper, GameController, User) {
|
|||
self.onDisconnect();
|
||||
});
|
||||
|
||||
NotificationCenter.on("sendGameCommand", this.sendGameCommand, this);
|
||||
}
|
||||
|
||||
Networker.prototype.onConnect = function () {
|
||||
|
|
@ -123,6 +125,11 @@ function (ProtocolHelper, GameController, User) {
|
|||
}
|
||||
}
|
||||
|
||||
Networker.prototype.sendGameCommand = function(command, options) {
|
||||
var message = ProtocolHelper.encodeCommand(command, options);
|
||||
this.sendCommand('gameCommand', message);
|
||||
};
|
||||
|
||||
return Networker;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue