added angular throwing

This commit is contained in:
logsol 2014-12-25 00:33:00 +01:00
parent 9100215ceb
commit d24ab60756
12 changed files with 93 additions and 34 deletions

View file

@ -33,7 +33,7 @@ function(Parent, Nc, Parser, Settings) {
}; };
PlayerController.prototype.handActionRequest = function(options) { PlayerController.prototype.handActionRequest = function(options) {
if (options) this.player.handActionRequest(options.x, options.y); if (options) this.player.handActionRequest(options);
}; };
PlayerController.prototype.suicide = function() { PlayerController.prototype.suicide = function() {

View file

@ -13,7 +13,7 @@ function (Parent, Nc) {
Player.prototype = Object.create(Parent.prototype); Player.prototype = Object.create(Parent.prototype);
Player.prototype.handActionRequest = function(x, y) { Player.prototype.handActionRequest = function(options) {
if(!this.doll) return false; if(!this.doll) return false;
var item = null; var item = null;
@ -22,29 +22,25 @@ function (Parent, Nc) {
if (isHolding) { if (isHolding) {
item = this.holdingItem; item = this.holdingItem;
} else { } else {
item = this.doll.findCloseItem(x, y); item = this.doll.findCloseItem(options.x, options.y);
} }
if(item) { 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 = { options.playerId = this.id;
playerId: this.id, options.itemUid = item.uid;
itemUid: item.uid
}
if (isHolding) { if (isHolding) {
// throw // throw
if(item.isReleasingAllowed()) { if(item.isReleasingAllowed()) {
this.throw(x, y, item); this.throw(options, item);
options.action = "throw"; options.action = "throw";
options.x = x;
options.y = y;
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "handActionResponse", options); Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "handActionResponse", options);
} }
} else { } else {

View file

@ -105,7 +105,11 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) {
canvas.onmousedown = function(e) { canvas.onmousedown = function(e) {
if(!self.playerController.player.isHoldingSomething()) { 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 { } else {
self.swiper = new Swiper(); self.swiper = new Swiper();
} }
@ -121,8 +125,8 @@ function (Parent, KeyboardInput, DomController, Settings, Swiper) {
canvas.onmouseup = function(e) { canvas.onmouseup = function(e) {
if(self.swiper) { if(self.swiper) {
var xya = self.swiper.swipeEnd(e.x, e.y); var options = self.swiper.swipeEnd(e.x, e.y);
self.playerController.handActionRequest(xya.x, xya.y); self.playerController.handActionRequest(options);
self.swiper = null; self.swiper = null;
} }
} }

View 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;
});

View file

@ -67,8 +67,7 @@ function (Parent, Nc, KeyboardAndMouse, Gamepad) {
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "suicide"); Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "suicide");
}; };
PlayerController.prototype.handActionRequest = function(x, y) { PlayerController.prototype.handActionRequest = function(options) {
var options = {x:x, y:y};
Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "handActionRequest", options); Nc.trigger(Nc.ns.client.to.server.gameCommand.send, "handActionRequest", options);
}; };

View file

@ -75,7 +75,7 @@ function (Nc) {
} }
Swiper.prototype.swipeEnd = function(x, y) { Swiper.prototype.swipeEnd = function(x, y) {
var spin = this.angleSum; var angularVelocity = this.angleSum;
var length = this.lengthSum; var length = this.lengthSum;
var p0x = this.points[0].x; var p0x = this.points[0].x;
var p0y = this.points[0].y; var p0y = this.points[0].y;
@ -106,7 +106,7 @@ function (Nc) {
return { return {
x: direction.x * length / 100, x: direction.x * length / 100,
y: direction.y * length / 100, y: direction.y * length / 100,
spin: spin av: angularVelocity / 100
} }
} }

View file

@ -197,7 +197,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
if(item) { if(item) {
if(options.action == "throw") { if(options.action == "throw") {
player.throw(options.x, options.y, item); player.throw(options, item);
} else if(options.action == "grab") { } else if(options.action == "grab") {
player.grab(item); player.grab(item);
} }

View file

@ -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 }); Nc.trigger(Nc.ns.client.view.mesh.update, this.layerId, this.holdingArmMesh, { visible: true });
}; };
Doll.prototype.throw = function(item, x, y) { Doll.prototype.throw = function(item, options) {
Parent.prototype.throw.call(this, item, x, y); Parent.prototype.throw.call(this, item, options);
this.animatedMeshes = this.animatedMeshesContainer.withArms; this.animatedMeshes = this.animatedMeshesContainer.withArms;
this.setActionState(this.actionState, true); this.setActionState(this.actionState, true);
Nc.trigger(Nc.ns.client.view.mesh.update, this.layerId, this.holdingArmMesh, { visible: false }); Nc.trigger(Nc.ns.client.view.mesh.update, this.layerId, this.holdingArmMesh, { visible: false });

View file

@ -38,8 +38,8 @@ define(function() {
FLY_SPEED: 6.2, FLY_SPEED: 6.2,
JUMP_SPEED: 21, JUMP_SPEED: 21,
JUMP_STOP_DAMPING_FACTOR: 0.5, JUMP_STOP_DAMPING_FACTOR: 0.5,
MAX_THROW_FORCE: 18 * 3.5, MAX_THROW_FORCE: 28,
MAX_THROW_ANGULAR_VELOCITY: 0, MAX_THROW_ANGULAR_VELOCITY: 3,
MAX_RUNNING_WEIGHT: 9, MAX_RUNNING_WEIGHT: 9,
RESPAWN_TIME: 5, RESPAWN_TIME: 5,
HEALTH_DISPLAY_TIME: 2, HEALTH_DISPLAY_TIME: 2,

View file

@ -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.body.GetWorld().DestroyJoint(this.holdingJoint);
this.holdingJoint = null; this.holdingJoint = null;
this.holdingItem = null; this.holdingItem = null;
item.throw(x, y); item.throw(options);
}; };
Doll.prototype.isAnotherPlayerNearby = function() { Doll.prototype.isAnotherPlayerNearby = function() {

View file

@ -129,17 +129,17 @@ function (Parent, Box2D, Options, Settings, Exception, Nc) {
return this.body.GetWorldCenter(); return this.body.GetWorldCenter();
}; };
Item.prototype.throw = function(x, y) { Item.prototype.throw = function(options) {
var body = this.body; var body = this.body;
body.SetAwake(true); body.SetAwake(true);
var vector = new Box2D.Common.Math.b2Vec2( var vector = new Box2D.Common.Math.b2Vec2(
x * Settings.MAX_THROW_FORCE / this.options.weight, options.x * Settings.MAX_THROW_FORCE / this.options.weight,
-y * Settings.MAX_THROW_FORCE / this.options.weight -options.y * Settings.MAX_THROW_FORCE / this.options.weight
); );
this.body.SetLinearVelocity(vector); 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() { Item.prototype.destroy = function() {

View file

@ -87,9 +87,9 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
this.holdingItem = item; this.holdingItem = item;
}; };
Player.prototype.throw = function(x, y, item) { Player.prototype.throw = function(options, item) {
if(!this.isSpawned) return false; if(!this.isSpawned) return false;
this.doll.throw(item, x, y); this.doll.throw(item, options);
item.beingReleased(this); item.beingReleased(this);
this.holdingItem = null; this.holdingItem = null;
}; };
@ -99,7 +99,7 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
// FIXME: do something better then just respawn in GameController // FIXME: do something better then just respawn in GameController
if(this.holdingItem) { if(this.holdingItem) {
this.throw(0, 0, this.holdingItem) this.throw(0, 0, 0, this.holdingItem)
} }
// prepare for creating the ragdoll // 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); Nc.trigger(Nc.ns.core.game.gameObject.remove, 'animated', this);
if(this.holdingItem) { 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(); this.spectatorDoll.destroy();