From 197c4072c198d041a74d183587bcaf9cc2f024cb Mon Sep 17 00:00:00 2001 From: logsol Date: Thu, 25 Dec 2014 15:00:10 +0100 Subject: [PATCH] fixed drop error. added carrier velocity --- app/Game/Client/Control/Swiper.js | 19 ++++++++++++++----- app/Game/Core/GameObjects/Doll.js | 7 ++++++- app/Game/Core/GameObjects/Item.js | 6 +++--- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/Game/Client/Control/Swiper.js b/app/Game/Client/Control/Swiper.js index 84c4d68..37eed8c 100644 --- a/app/Game/Client/Control/Swiper.js +++ b/app/Game/Client/Control/Swiper.js @@ -77,6 +77,15 @@ function (Nc) { Swiper.prototype.swipeEnd = function(x, y) { var angularVelocity = this.angleSum; var length = this.lengthSum; + + if (this.points.length < 1) { + return { + x: 0, + y: 0, + av: 0 + } + } + var p0x = this.points[0].x; var p0y = this.points[0].y; var sumx = 0; @@ -103,11 +112,11 @@ function (Nc) { this.lengthSum = 0; this.points = []; - return { - x: direction.x * length / 100, - y: direction.y * length / 100, - av: angularVelocity / 100 - } + return { + x: direction.x * length / 100, + y: direction.y * length / 100, + av: angularVelocity / 100 + } } Swiper.prototype.destroy = function() { diff --git a/app/Game/Core/GameObjects/Doll.js b/app/Game/Core/GameObjects/Doll.js index 6537ce1..9f620f4 100755 --- a/app/Game/Core/GameObjects/Doll.js +++ b/app/Game/Core/GameObjects/Doll.js @@ -359,7 +359,12 @@ function (Parent, Box2D, Settings, CollisionDetector, Item, Nc) { this.holdingJoint = null; this.holdingItem = null; - item.throw(options); + var dollVelocity = { + x: this.body.GetLinearVelocity().x + y: this.body.GetLinearVelocity().y + }; + + item.throw(options, dollVelocity); }; Doll.prototype.isAnotherPlayerNearby = function() { diff --git a/app/Game/Core/GameObjects/Item.js b/app/Game/Core/GameObjects/Item.js index c2fcd10..6584931 100644 --- a/app/Game/Core/GameObjects/Item.js +++ b/app/Game/Core/GameObjects/Item.js @@ -129,13 +129,13 @@ function (Parent, Box2D, Options, Settings, Exception, Nc) { return this.body.GetWorldCenter(); }; - Item.prototype.throw = function(options) { + Item.prototype.throw = function(options, carrierVelocity) { var body = this.body; body.SetAwake(true); var vector = new Box2D.Common.Math.b2Vec2( - options.x * Settings.MAX_THROW_FORCE / this.options.weight, - -options.y * Settings.MAX_THROW_FORCE / this.options.weight + options.x * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.x, + -options.y * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.y ); this.body.SetLinearVelocity(vector);