mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added angular throwing
This commit is contained in:
parent
9100215ceb
commit
d24ab60756
12 changed files with 93 additions and 34 deletions
|
|
@ -33,7 +33,7 @@ function(Parent, Nc, Parser, Settings) {
|
|||
};
|
||||
|
||||
PlayerController.prototype.handActionRequest = function(options) {
|
||||
if (options) this.player.handActionRequest(options.x, options.y);
|
||||
if (options) this.player.handActionRequest(options);
|
||||
};
|
||||
|
||||
PlayerController.prototype.suicide = function() {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ function (Parent, Nc) {
|
|||
|
||||
Player.prototype = Object.create(Parent.prototype);
|
||||
|
||||
Player.prototype.handActionRequest = function(x, y) {
|
||||
Player.prototype.handActionRequest = function(options) {
|
||||
if(!this.doll) return false;
|
||||
|
||||
var item = null;
|
||||
|
|
@ -22,29 +22,25 @@ function (Parent, Nc) {
|
|||
if (isHolding) {
|
||||
item = this.holdingItem;
|
||||
} else {
|
||||
item = this.doll.findCloseItem(x, y);
|
||||
item = this.doll.findCloseItem(options.x, options.y);
|
||||
}
|
||||
|
||||
if(item) {
|
||||
this.handAction(x, y, isHolding, item);
|
||||
this.handAction(options, isHolding, item);
|
||||
}
|
||||
}
|
||||
|
||||
Player.prototype.handAction = function(x, y, isHolding, item) {
|
||||
Player.prototype.handAction = function(options, isHolding, item) {
|
||||
|
||||
var options = {
|
||||
playerId: this.id,
|
||||
itemUid: item.uid
|
||||
}
|
||||
options.playerId = this.id;
|
||||
options.itemUid = item.uid;
|
||||
|
||||
if (isHolding) {
|
||||
// throw
|
||||
if(item.isReleasingAllowed()) {
|
||||
this.throw(x, y, item);
|
||||
this.throw(options, item);
|
||||
|
||||
options.action = "throw";
|
||||
options.x = x;
|
||||
options.y = y;
|
||||
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "handActionResponse", options);
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -105,7 +105,11 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) {
|
|||
|
||||
canvas.onmousedown = function(e) {
|
||||
if(!self.playerController.player.isHoldingSomething()) {
|
||||
self.playerController.handActionRequest(self.x, self.y);
|
||||
var options = {
|
||||
x: self.x,
|
||||
y: self.y
|
||||
};
|
||||
self.playerController.handActionRequest(options);
|
||||
} else {
|
||||
self.swiper = new Swiper();
|
||||
}
|
||||
|
|
@ -121,8 +125,8 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) {
|
|||
|
||||
canvas.onmouseup = function(e) {
|
||||
if(self.swiper) {
|
||||
var xya = self.swiper.swipeEnd(e.x, e.y);
|
||||
self.playerController.handActionRequest(xya.x, xya.y);
|
||||
var options = self.swiper.swipeEnd(e.x, e.y);
|
||||
self.playerController.handActionRequest(options);
|
||||
self.swiper = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
55
app/Game/Client/Control/KeyboardInput.js
Executable file
55
app/Game/Client/Control/KeyboardInput.js
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
define([
|
||||
"Game/Client/Control/Key"
|
||||
],
|
||||
|
||||
function (Key) {
|
||||
|
||||
function KeyboardInput () {
|
||||
this._registry = {};
|
||||
this.init();
|
||||
}
|
||||
|
||||
KeyboardInput.prototype.init = function () {
|
||||
// Using window is ok here because it only runs in the browser
|
||||
window.onkeydown = this._onKeyDown.bind(this);
|
||||
window.onkeyup = this._onKeyUp.bind(this);
|
||||
}
|
||||
|
||||
KeyboardInput.prototype.registerKey = function (keyCode, onKeyDown, onKeyUp) {
|
||||
var key = new Key();
|
||||
if(onKeyDown) key.setKeyDownFunction(onKeyDown);
|
||||
if(onKeyUp) key.setKeyUpFunction(onKeyUp);
|
||||
this._registry[keyCode] = key;
|
||||
}
|
||||
|
||||
KeyboardInput.prototype._getKeyByKeyCode = function (keyCode) {
|
||||
return this._registry[keyCode];
|
||||
}
|
||||
|
||||
KeyboardInput.prototype._onKeyDown = function (e) {
|
||||
var key = this._getKeyByKeyCode(e.keyCode);
|
||||
|
||||
if (key && !key.getActive()) {
|
||||
var callback = key.getKeyDownFunction();
|
||||
if(callback) callback();
|
||||
key.setActive(true);
|
||||
}
|
||||
|
||||
// Prevent tab from changing focus
|
||||
if(e.keyCode == 9) return false;
|
||||
}
|
||||
|
||||
KeyboardInput.prototype._onKeyUp = function (e) {
|
||||
var key = this._getKeyByKeyCode(e.keyCode);
|
||||
if (key && key.getActive()) {
|
||||
var callback = key.getKeyUpFunction();
|
||||
if(callback) callback();
|
||||
key.setActive(false);
|
||||
}
|
||||
|
||||
// Prevent tab from changing focus
|
||||
if(e.keyCode == 9) return false;
|
||||
}
|
||||
|
||||
return KeyboardInput;
|
||||
});
|
||||
|
|
@ -67,8 +67,7 @@ function (Parent, Nc, KeyboardAndMouse, Gamepad) {
|
|||
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "suicide");
|
||||
};
|
||||
|
||||
PlayerController.prototype.handActionRequest = function(x, y) {
|
||||
var options = {x:x, y:y};
|
||||
PlayerController.prototype.handActionRequest = function(options) {
|
||||
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "handActionRequest", options);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ function (Nc) {
|
|||
}
|
||||
|
||||
Swiper.prototype.swipeEnd = function(x, y) {
|
||||
var spin = this.angleSum;
|
||||
var angularVelocity = this.angleSum;
|
||||
var length = this.lengthSum;
|
||||
var p0x = this.points[0].x;
|
||||
var p0y = this.points[0].y;
|
||||
|
|
@ -106,7 +106,7 @@ function (Nc) {
|
|||
return {
|
||||
x: direction.x * length / 100,
|
||||
y: direction.y * length / 100,
|
||||
spin: spin
|
||||
av: angularVelocity / 100
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
|
||||
if(item) {
|
||||
if(options.action == "throw") {
|
||||
player.throw(options.x, options.y, item);
|
||||
player.throw(options, item);
|
||||
} else if(options.action == "grab") {
|
||||
player.grab(item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,8 +230,8 @@ function (Parent, Settings, Nc, Exception, ColorConverter, Layer) {
|
|||
Nc.trigger(Nc.ns.client.view.mesh.update, this.layerId, this.holdingArmMesh, { visible: true });
|
||||
};
|
||||
|
||||
Doll.prototype.throw = function(item, x, y) {
|
||||
Parent.prototype.throw.call(this, item, x, y);
|
||||
Doll.prototype.throw = function(item, options) {
|
||||
Parent.prototype.throw.call(this, item, options);
|
||||
this.animatedMeshes = this.animatedMeshesContainer.withArms;
|
||||
this.setActionState(this.actionState, true);
|
||||
Nc.trigger(Nc.ns.client.view.mesh.update, this.layerId, this.holdingArmMesh, { visible: false });
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ define(function() {
|
|||
FLY_SPEED: 6.2,
|
||||
JUMP_SPEED: 21,
|
||||
JUMP_STOP_DAMPING_FACTOR: 0.5,
|
||||
MAX_THROW_FORCE: 18 * 3.5,
|
||||
MAX_THROW_ANGULAR_VELOCITY: 0,
|
||||
MAX_THROW_FORCE: 28,
|
||||
MAX_THROW_ANGULAR_VELOCITY: 3,
|
||||
MAX_RUNNING_WEIGHT: 9,
|
||||
RESPAWN_TIME: 5,
|
||||
HEALTH_DISPLAY_TIME: 2,
|
||||
|
|
|
|||
|
|
@ -354,12 +354,12 @@ function (Parent, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
}
|
||||
};
|
||||
|
||||
Doll.prototype.throw = function(item, x, y) {
|
||||
Doll.prototype.throw = function(item, options) {
|
||||
this.body.GetWorld().DestroyJoint(this.holdingJoint);
|
||||
this.holdingJoint = null;
|
||||
this.holdingItem = null;
|
||||
|
||||
item.throw(x, y);
|
||||
item.throw(options);
|
||||
};
|
||||
|
||||
Doll.prototype.isAnotherPlayerNearby = function() {
|
||||
|
|
|
|||
|
|
@ -129,17 +129,17 @@ function (Parent, Box2D, Options, Settings, Exception, Nc) {
|
|||
return this.body.GetWorldCenter();
|
||||
};
|
||||
|
||||
Item.prototype.throw = function(x, y) {
|
||||
Item.prototype.throw = function(options) {
|
||||
var body = this.body;
|
||||
body.SetAwake(true);
|
||||
|
||||
var vector = new Box2D.Common.Math.b2Vec2(
|
||||
x * Settings.MAX_THROW_FORCE / this.options.weight,
|
||||
-y * Settings.MAX_THROW_FORCE / this.options.weight
|
||||
options.x * Settings.MAX_THROW_FORCE / this.options.weight,
|
||||
-options.y * Settings.MAX_THROW_FORCE / this.options.weight
|
||||
);
|
||||
this.body.SetLinearVelocity(vector);
|
||||
|
||||
body.SetAngularVelocity(Settings.MAX_THROW_ANGULAR_VELOCITY * x);
|
||||
body.SetAngularVelocity(-options.av * Settings.MAX_THROW_ANGULAR_VELOCITY);
|
||||
};
|
||||
|
||||
Item.prototype.destroy = function() {
|
||||
|
|
|
|||
|
|
@ -87,9 +87,9 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
|
|||
this.holdingItem = item;
|
||||
};
|
||||
|
||||
Player.prototype.throw = function(x, y, item) {
|
||||
Player.prototype.throw = function(options, item) {
|
||||
if(!this.isSpawned) return false;
|
||||
this.doll.throw(item, x, y);
|
||||
this.doll.throw(item, options);
|
||||
item.beingReleased(this);
|
||||
this.holdingItem = null;
|
||||
};
|
||||
|
|
@ -99,7 +99,7 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
|
|||
|
||||
// FIXME: do something better then just respawn in GameController
|
||||
if(this.holdingItem) {
|
||||
this.throw(0, 0, this.holdingItem)
|
||||
this.throw(0, 0, 0, this.holdingItem)
|
||||
}
|
||||
|
||||
// prepare for creating the ragdoll
|
||||
|
|
@ -144,7 +144,12 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
|
|||
Nc.trigger(Nc.ns.core.game.gameObject.remove, 'animated', this);
|
||||
|
||||
if(this.holdingItem) {
|
||||
this.throw(0, 0, this.holdingItem);
|
||||
var options = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
av: 0
|
||||
};
|
||||
this.throw(options, this.holdingItem);
|
||||
}
|
||||
|
||||
this.spectatorDoll.destroy();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue