From 0a0b3e88497e93d8225afa1df4b480d5116d0b50 Mon Sep 17 00:00:00 2001 From: logsol Date: Tue, 9 Dec 2014 15:55:28 +0100 Subject: [PATCH] added simple mode --- .../Client/Control/Inputs/KeyboardAndMouse.js | 29 +++++++++++++++---- app/Game/Client/Me.js | 2 +- app/Game/Config/Settings.js | 1 + 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/Game/Client/Control/Inputs/KeyboardAndMouse.js b/app/Game/Client/Control/Inputs/KeyboardAndMouse.js index 74f9a2e..202b38a 100644 --- a/app/Game/Client/Control/Inputs/KeyboardAndMouse.js +++ b/app/Game/Client/Control/Inputs/KeyboardAndMouse.js @@ -15,6 +15,7 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) { this.y = 0; this.modifier = false; this.swiper = null; + this.lastLookDirection = 1; this.playerController = playerController; this.keyboardInit(); @@ -58,10 +59,10 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) { return self.playerController[methodName].bind(self.playerController); } - this.keyboardInput.registerKey(keys.a, bind2Pc('moveLeft'), bind2Pc('stop')); - this.keyboardInput.registerKey(keys.left, bind2Pc('moveLeft'), bind2Pc('stop')); - this.keyboardInput.registerKey(keys.d, bind2Pc('moveRight'), bind2Pc('stop')); - this.keyboardInput.registerKey(keys.right, bind2Pc('moveRight'), bind2Pc('stop')); + this.keyboardInput.registerKey(keys.a, this.moveLeft.bind(this), bind2Pc('stop')); + this.keyboardInput.registerKey(keys.left, this.moveLeft.bind(this), bind2Pc('stop')); + this.keyboardInput.registerKey(keys.d, this.moveRight.bind(this), bind2Pc('stop')); + this.keyboardInput.registerKey(keys.right, this.moveRight.bind(this), bind2Pc('stop')); this.keyboardInput.registerKey(keys.w, bind2Pc('jump'), bind2Pc('jumpStop')); this.keyboardInput.registerKey(keys.up, bind2Pc('jump'), bind2Pc('jumpStop')); this.keyboardInput.registerKey(keys.space, bind2Pc('jump'), bind2Pc('jumpStop')); @@ -82,6 +83,22 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) { ); }; + KeyboardAndMouse.prototype.moveLeft = function() { + if (!this.modifier) { + this.lastLookDirection = -1; + this.onXyChange(this.lastLookDirection * Settings.VIEWPORT_LOOK_AHEAD, 0); + } + this.playerController.moveLeft() + }; + + KeyboardAndMouse.prototype.moveRight = function() { + if (!this.modifier) { + this.lastLookDirection = 1; + this.onXyChange(this.lastLookDirection * Settings.VIEWPORT_LOOK_AHEAD, 0); + } + this.playerController.moveRight(); + }; + KeyboardAndMouse.prototype.mouseInit = function() { var canvas = DomController.getCanvas(); var self = this; @@ -141,6 +158,8 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) { this.y = -1; } + this.lastLookDirection = this.x >= 0 ? 1 : -1; + this.onXyChange(this.x, this.y); }; @@ -164,7 +183,7 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) { KeyboardAndMouse.prototype.deactivateModifier = function() { this.modifier = false; - this.x = 0.3; + this.x = this.lastLookDirection * Settings.VIEWPORT_LOOK_AHEAD; this.y = 0; this.onXyChange(this.x, this.y); }; diff --git a/app/Game/Client/Me.js b/app/Game/Client/Me.js index 60ae102..20c7ae0 100644 --- a/app/Game/Client/Me.js +++ b/app/Game/Client/Me.js @@ -11,7 +11,7 @@ function (Parent, Settings, Nc) { // View uses this to calculate center position this.lookAtXY = { - x: 0.3, + x: Settings.VIEWPORT_LOOK_AHEAD, y: 0 } diff --git a/app/Game/Config/Settings.js b/app/Game/Config/Settings.js index 1cb71ee..bd358bf 100755 --- a/app/Game/Config/Settings.js +++ b/app/Game/Config/Settings.js @@ -45,6 +45,7 @@ define(function() { HEALTH_DISPLAY_TIME: 2, RAGDOLL_DESTRUCTION_TIME: 20, VIEWPORT_SPEED_FACTOR: 640, + VIEWPORT_LOOK_AHEAD: 0.1, // restitution: bouncyness, friction: rubbing, density: mass TILE_FRICTION: 0.99,