Permalink
Browse files

update of client data by server

  • Loading branch information...
1 parent 2cb401b commit c8d0a484890d17158d800a1e431f0055414fe3b9 Jeena Paradies committed Jul 13, 2012
View
@@ -2,7 +2,7 @@ define(["Chuck/Processors/ClientProcessor"], function(ClientProcessor) {
function ClientGame(networker, id) {
this.networker = networker;
- this.processor = new ClientProcessor();
+ this.processor = new ClientProcessor(this);
this.processor.spawnMeWithId(id);
}
@@ -15,7 +15,11 @@ define(["Chuck/Processors/ClientProcessor"], function(ClientProcessor) {
};
ClientGame.prototype.processGameCommand = function(command, options){
- console.log('(not implemented) processGameCommand:', command, options);
+ this.processor.processGameCommand(command, options);
+ }
+
+ ClientGame.prototype.sendGameCommand = function(command, options) {
+ this.networker.sendGameCommand(command, options);
}
ClientGame.prototype.destruct = function(){
@@ -1,17 +1,11 @@
-define(["Chuck/Control/KeyboardInput"], function(KeyboardInput){
+define(["Chuck/Control/InputController", "Chuck/Control/KeyboardInput"], function(InputController, KeyboardInput){
- function InputControlUnit(me) {
+ function InputControlUnit(me, clientProcessor) {
- this._keyboardInput = new KeyboardInput(this);
- this._me = me;
+ this.clientProcessor = clientProcessor;
+ this.inputController = new InputController(me);
- this._shift;
- this._isJumping;
-
- this.KEY_LEFT = 65;
- this.KEY_RIGHT = 68;
- this.KEY_UP = 87;
- this.KEY_DOWN = 83;
+ this.keyboardInput = new KeyboardInput(this);
var keys = {
w:87,
@@ -30,67 +24,70 @@ define(["Chuck/Control/KeyboardInput"], function(KeyboardInput){
InputControlUnit.prototype.init = function(keys) {
- this._keyboardInput.registerKey(keys.a, 'moveLeft', 'stop', 'moveLeft');
- this._keyboardInput.registerKey(keys.left, 'moveLeft', 'stop', 'moveLeft');
+ this.keyboardInput.registerKey(keys.a, 'moveLeft', 'stop', 'moveLeft');
+ this.keyboardInput.registerKey(keys.left, 'moveLeft', 'stop', 'moveLeft');
- this._keyboardInput.registerKey(keys.d, 'moveRight', 'stop', 'moveRight');
- this._keyboardInput.registerKey(keys.right, 'moveRight', 'stop', 'moveRight');
+ this.keyboardInput.registerKey(keys.d, 'moveRight', 'stop', 'moveRight');
+ this.keyboardInput.registerKey(keys.right, 'moveRight', 'stop', 'moveRight');
- this._keyboardInput.registerKey(keys.w, 'jump', 'jumped', 'jumping');
- this._keyboardInput.registerKey(keys.up, 'jump', 'jumped', 'jumping');
+ this.keyboardInput.registerKey(keys.w, 'jump', 'jumped', 'jumping');
+ this.keyboardInput.registerKey(keys.up, 'jump', 'jumped', 'jumping');
- this._keyboardInput.registerKey(keys.s, 'duck', 'standUp', 'duck');
- this._keyboardInput.registerKey(keys.down, 'duck', 'standUp', 'duck');
+ this.keyboardInput.registerKey(keys.s, 'duck', 'standUp', 'duck');
+ this.keyboardInput.registerKey(keys.down, 'duck', 'standUp', 'duck');
- this._keyboardInput.registerKey(keys.s, 'activateShift', 'activateShift', 'deactivateShift');
- this._keyboardInput.registerKey(keys.down, 'activateShift', 'activateShift', 'deactivateShift');
+ this.keyboardInput.registerKey(keys.s, 'activateShift', 'activateShift', 'deactivateShift');
+ this.keyboardInput.registerKey(keys.down, 'activateShift', 'activateShift', 'deactivateShift');
}
InputControlUnit.prototype.moveLeft = function() {
- this._me.move(-1);
+ this.inputController.moveLeft();
+ this.clientProcessor.sendGameCommand('moveLeft');
}
InputControlUnit.prototype.moveRight = function() {
- this._me.move(1);
+ this.inputController.moveRight();
+ this.clientProcessor.sendGameCommand('moveRight');
}
InputControlUnit.prototype.stop = function() {
- this._me.stop();
+ this.inputController.stop();
+ this.clientProcessor.sendGameCommand('stop');
}
InputControlUnit.prototype.jump = function() {
- this._isJumping = true;
- this._me.jump();
+ this.inputController.jump();
+ this.clientProcessor.sendGameCommand('jump');
}
InputControlUnit.prototype.jumped = function() {
- this._isJumping = false;
+ this.inputController.jumped();
}
InputControlUnit.prototype.jumping = function() {
- if (this._isJumping) {
- this._me.jumping();
- }
+ this.inputController.jumping();
}
InputControlUnit.prototype.duck = function() {
- this._me.duck();
+ this.inputController.duck();
+ this.clientProcessor.sendGameCommand('duck');
}
InputControlUnit.prototype.standUp = function() {
- this._me.standUp();
+ this.inputController.standUp();
}
InputControlUnit.prototype.activateShift = function() {
- this._shift = true;
+ this.inputController.activateShift();
+ this.clientProcessor.sendGameCommand('activateShift');
}
InputControlUnit.prototype.deactivateShift = function() {
- this._shift = false;
+ this.inputController.deactivateShift();
}
InputControlUnit.prototype.update = function() {
- this._keyboardInput.update();
+ this.keyboardInput.update();
}
return InputControlUnit;
@@ -0,0 +1,59 @@
+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;
+});
@@ -18,6 +18,7 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
bodyDef.fixedRotation = true;
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
+ bodyDef.userData = 'player-' + this.id;
this._body = world.CreateBody(bodyDef);
@@ -31,14 +32,14 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -37 / Settings.RATIO));
fixtureDef.shape = headShape;
fixtureDef.isSensor = false;
- fixtureDef.userData = 'myHead' + this.id;
+ fixtureDef.userData = 'myHead-' + this.id;
this._body.CreateFixture(fixtureDef);
var bodyShape = new Box2D.Collision.Shapes.b2PolygonShape();
bodyShape.SetAsOrientedBox(5 / Settings.RATIO, 16 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -21 / Settings.RATIO));
fixtureDef.shape = bodyShape;
fixtureDef.isSensor = false;
- fixtureDef.userData = 'myBody' + this.id;
+ fixtureDef.userData = 'myBody-' + this.id;
this._body.CreateFixture(fixtureDef);
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
@@ -47,15 +48,15 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
fixtureDef.shape = legsShape;
fixtureDef.friction = Settings.PLAYER_FRICTION;
fixtureDef.isSensor = false;
- fixtureDef.userData = 'myLegs' + this.id;
+ fixtureDef.userData = 'myLegs-' + this.id;
this._legs = this._body.CreateFixture(fixtureDef);
var feetShape = new Box2D.Collision.Shapes.b2CircleShape();
feetShape.SetRadius(4 / Settings.RATIO);
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 0 / Settings.RATIO));
fixtureDef.shape = feetShape;
fixtureDef.isSensor = true;
- fixtureDef.userData = 'myFeet' + this.id;
+ fixtureDef.userData = 'myFeet-' + this.id;
this._body.CreateFixture(fixtureDef);
this._body.SetActive(false);
Oops, something went wrong.

0 comments on commit c8d0a48

Please sign in to comment.