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

@ -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;
}
}

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

View file

@ -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
}
}

View file

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

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