mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
Adds forward walking on shift
The state of the shift modifier is now distributed across the network. Walking speeds and animation states are being updated according to it. Fixes #130
This commit is contained in:
parent
062402db58
commit
b798e6acac
5 changed files with 39 additions and 9 deletions
|
|
@ -216,6 +216,7 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) {
|
||||||
|
|
||||||
KeyboardAndMouse.prototype.activateModifier = function() {
|
KeyboardAndMouse.prototype.activateModifier = function() {
|
||||||
this.modifier = true;
|
this.modifier = true;
|
||||||
|
this.playerController.activateModifier();
|
||||||
};
|
};
|
||||||
|
|
||||||
KeyboardAndMouse.prototype.deactivateModifier = function() {
|
KeyboardAndMouse.prototype.deactivateModifier = function() {
|
||||||
|
|
@ -223,6 +224,7 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) {
|
||||||
this.x = this.lastLookDirection * Settings.VIEWPORT_LOOK_AHEAD;
|
this.x = this.lastLookDirection * Settings.VIEWPORT_LOOK_AHEAD;
|
||||||
this.y = 0;
|
this.y = 0;
|
||||||
this.onXyChange(this.x, this.y);
|
this.onXyChange(this.x, this.y);
|
||||||
|
this.playerController.deactivateModifier();
|
||||||
};
|
};
|
||||||
return KeyboardAndMouse;
|
return KeyboardAndMouse;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,18 @@ function (Parent, Nc, KeyboardAndMouse, Gamepad, PointerLockManager) {
|
||||||
Nc.trigger(Nc.ns.client.game.zoomReset, false);
|
Nc.trigger(Nc.ns.client.game.zoomReset, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PlayerController.prototype.activateModifier = function() {
|
||||||
|
if (!this.isPlayerInputAllowed()) return;
|
||||||
|
Parent.prototype.activateModifier.call(this);
|
||||||
|
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "activateModifier");
|
||||||
|
};
|
||||||
|
|
||||||
|
PlayerController.prototype.deactivateModifier = function() {
|
||||||
|
if (!this.isPlayerInputAllowed()) return;
|
||||||
|
Parent.prototype.deactivateModifier.call(this);
|
||||||
|
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "deactivateModifier");
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Client overwrite - allow player input if PointerLock is locked to canvas
|
* Client overwrite - allow player input if PointerLock is locked to canvas
|
||||||
* and is not in between games
|
* and is not in between games
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,7 @@ define([
|
||||||
function () {
|
function () {
|
||||||
|
|
||||||
function PlayerController (player) {
|
function PlayerController (player) {
|
||||||
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
||||||
this._shift;
|
|
||||||
this._isJumping;
|
|
||||||
this._walkingDirectionStatus = 0;
|
this._walkingDirectionStatus = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,7 +27,6 @@ function () {
|
||||||
|
|
||||||
PlayerController.prototype.jump = function () {
|
PlayerController.prototype.jump = function () {
|
||||||
if(!this.isPlayerInputAllowed()) return;
|
if(!this.isPlayerInputAllowed()) return;
|
||||||
this._isJumping = true;
|
|
||||||
this.player.jump();
|
this.player.jump();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,6 +39,16 @@ function () {
|
||||||
if(options) this.player.lookAt(options.x, options.y);
|
if(options) this.player.lookAt(options.x, options.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlayerController.prototype.activateModifier = function() {
|
||||||
|
if (!this.isPlayerInputAllowed()) return;
|
||||||
|
this.player.activateModifier();
|
||||||
|
};
|
||||||
|
|
||||||
|
PlayerController.prototype.deactivateModifier = function() {
|
||||||
|
if (!this.isPlayerInputAllowed()) return;
|
||||||
|
this.player.deactivateModifier();
|
||||||
|
};
|
||||||
|
|
||||||
PlayerController.prototype.update = function () {
|
PlayerController.prototype.update = function () {
|
||||||
if(this._walkingDirectionStatus != 0) {
|
if(this._walkingDirectionStatus != 0) {
|
||||||
this.player.move(this._walkingDirectionStatus);
|
this.player.move(this._walkingDirectionStatus);
|
||||||
|
|
|
||||||
|
|
@ -228,14 +228,14 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc, Asser
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Doll.prototype.move = function (direction) {
|
Doll.prototype.move = function (direction, modifierActivated) {
|
||||||
|
|
||||||
this.moveDirection = direction;
|
this.moveDirection = direction;
|
||||||
var speed;
|
var speed;
|
||||||
var isHoldingHeavyItem = this.holdingItem && this.holdingItem.options.weight > Settings.MAX_RUNNING_WEIGHT;
|
var isHoldingHeavyItem = this.holdingItem && this.holdingItem.options.weight > Settings.MAX_RUNNING_WEIGHT;
|
||||||
|
|
||||||
switch(true) {
|
switch(true) {
|
||||||
case direction == this.lookDirection && this.isStanding() && !isHoldingHeavyItem:
|
case direction == this.lookDirection && this.isStanding() && !isHoldingHeavyItem && !modifierActivated:
|
||||||
speed = Settings.RUN_SPEED;
|
speed = Settings.RUN_SPEED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -264,7 +264,7 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc, Asser
|
||||||
if(this.isStanding()) {
|
if(this.isStanding()) {
|
||||||
if(this.moveDirection == this.lookDirection) {
|
if(this.moveDirection == this.lookDirection) {
|
||||||
|
|
||||||
if(isHoldingHeavyItem) {
|
if(isHoldingHeavyItem || modifierActivated) {
|
||||||
this.setActionState("walk");
|
this.setActionState("walk");
|
||||||
} else {
|
} else {
|
||||||
this.setActionState("run");
|
this.setActionState("run");
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ function (Doll, PlayerController, Settings, Nc, Exception, ColorConverter, Spect
|
||||||
this.inBetweenRounds = true;
|
this.inBetweenRounds = true;
|
||||||
this.spectatorDoll = new SpectatorDoll(this.physicsEngine, "spectatorDoll-" + this.id, this);
|
this.spectatorDoll = new SpectatorDoll(this.physicsEngine, "spectatorDoll-" + this.id, this);
|
||||||
this.revealedGameController = revealedGameController;
|
this.revealedGameController = revealedGameController;
|
||||||
|
this.modifierActivated = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.prototype.getNickname = function() {
|
Player.prototype.getNickname = function() {
|
||||||
|
|
@ -66,7 +67,7 @@ function (Doll, PlayerController, Settings, Nc, Exception, ColorConverter, Spect
|
||||||
|
|
||||||
Player.prototype.move = function (direction) {
|
Player.prototype.move = function (direction) {
|
||||||
if(!this.spawned) return false;
|
if(!this.spawned) return false;
|
||||||
this.doll.move(direction);
|
this.doll.move(direction, this.modifierActivated);
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.prototype.stop = function () {
|
Player.prototype.stop = function () {
|
||||||
|
|
@ -90,6 +91,16 @@ function (Doll, PlayerController, Settings, Nc, Exception, ColorConverter, Spect
|
||||||
this.doll.lookAt(x, y);
|
this.doll.lookAt(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Player.prototype.activateModifier = function () {
|
||||||
|
if(!this.spawned) return false;
|
||||||
|
this.modifierActivated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player.prototype.deactivateModifier = function () {
|
||||||
|
if(!this.spawned) return false;
|
||||||
|
this.modifierActivated = false;
|
||||||
|
}
|
||||||
|
|
||||||
Player.prototype.grab = function(item) {
|
Player.prototype.grab = function(item) {
|
||||||
if(!this.spawned) return false;
|
if(!this.spawned) return false;
|
||||||
this.doll.grab(item);
|
this.doll.grab(item);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue