mirror of
https://github.com/photonstorm/phaser
synced 2024-11-25 06:00:41 +00:00
Fixed issue re: would bounce
This commit is contained in:
parent
24921d653b
commit
5b4b2d2fa9
1 changed files with 17 additions and 40 deletions
|
@ -8,6 +8,8 @@ var CircleContains = require('../../geom/circle/Contains');
|
||||||
var Class = require('../../utils/Class');
|
var Class = require('../../utils/Class');
|
||||||
var CONST = require('./const');
|
var CONST = require('./const');
|
||||||
var Events = require('./events');
|
var Events = require('./events');
|
||||||
|
var FuzzyLessThan = require('../../math/fuzzy/LessThan');
|
||||||
|
var FuzzyGreaterThan = require('../../math/fuzzy/GreaterThan');
|
||||||
var RadToDeg = require('../../math/RadToDeg');
|
var RadToDeg = require('../../math/RadToDeg');
|
||||||
var Rectangle = require('../../geom/rectangle/Rectangle');
|
var Rectangle = require('../../geom/rectangle/Rectangle');
|
||||||
var RectangleContains = require('../../geom/rectangle/Contains');
|
var RectangleContains = require('../../geom/rectangle/Contains');
|
||||||
|
@ -960,54 +962,38 @@ var Body = new Class({
|
||||||
*/
|
*/
|
||||||
update: function (delta)
|
update: function (delta)
|
||||||
{
|
{
|
||||||
|
var velocity = this.velocity;
|
||||||
|
|
||||||
if (this.moves)
|
if (this.moves)
|
||||||
{
|
{
|
||||||
this.world.updateMotion(this, delta);
|
this.world.updateMotion(this, delta);
|
||||||
|
|
||||||
var velocity = this.velocity;
|
|
||||||
|
|
||||||
this.position.x += this.getMoveX(velocity.x * delta);
|
this.position.x += this.getMoveX(velocity.x * delta);
|
||||||
this.position.y += this.getMoveY(velocity.y * delta);
|
this.position.y += this.getMoveY(velocity.y * delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate the delta
|
||||||
|
this._dx = this.position.x - this.prev.x;
|
||||||
|
this._dy = this.position.y - this.prev.y;
|
||||||
|
|
||||||
var worldBlocked = this.worldBlocked;
|
var worldBlocked = this.worldBlocked;
|
||||||
|
|
||||||
// World Bounds check
|
// World Bounds check
|
||||||
if (this.collideWorldBounds && !worldBlocked.none)
|
if (this.collideWorldBounds && !worldBlocked.none)
|
||||||
{
|
{
|
||||||
var worldBounds = this.world.bounds;
|
var bx = (this.worldBounce) ? -this.worldBounce.x : -this.bounce.x;
|
||||||
|
var by = (this.worldBounce) ? -this.worldBounce.y : -this.bounce.y;
|
||||||
var bx = (this.worldBounce) ? this.worldBounce.x : this.bounce.x;
|
|
||||||
var by = (this.worldBounce) ? this.worldBounce.y : this.bounce.y;
|
|
||||||
|
|
||||||
// Reverse the velocity for the bounce and flip the delta
|
// Reverse the velocity for the bounce
|
||||||
velocity.x *= -bx;
|
|
||||||
|
|
||||||
if (bx !== 0)
|
if ((worldBlocked.left && velocity.x < 0) || (worldBlocked.right && velocity.x > 0))
|
||||||
{
|
{
|
||||||
if (worldBlocked.left)
|
velocity.x *= bx;
|
||||||
{
|
|
||||||
this.x = worldBounds.x + (1 * bx);
|
|
||||||
}
|
|
||||||
else if (worldBlocked.right)
|
|
||||||
{
|
|
||||||
this.right = worldBounds.right - (1 * bx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reverse the velocity for the bounce and flip the delta
|
if ((worldBlocked.down && velocity.y > 0) || (worldBlocked.up && velocity.y < 0))
|
||||||
velocity.y *= -by;
|
|
||||||
|
|
||||||
if (by !== 0)
|
|
||||||
{
|
{
|
||||||
if (worldBlocked.up)
|
velocity.y *= by;
|
||||||
{
|
|
||||||
this.y = worldBounds.y + (1 * by);
|
|
||||||
}
|
|
||||||
else if (worldBlocked.down)
|
|
||||||
{
|
|
||||||
this.bottom = worldBounds.bottom - (1 * by);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.onWorldBounds)
|
if (this.onWorldBounds)
|
||||||
|
@ -1016,10 +1002,6 @@ var Body = new Class({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the delta
|
|
||||||
this._dx = this.position.x - this.prev.x;
|
|
||||||
this._dy = this.position.y - this.prev.y;
|
|
||||||
|
|
||||||
this.updateCenter();
|
this.updateCenter();
|
||||||
|
|
||||||
this.angle = Math.atan2(velocity.y, velocity.x);
|
this.angle = Math.atan2(velocity.y, velocity.x);
|
||||||
|
@ -1137,13 +1119,13 @@ var Body = new Class({
|
||||||
worldBlocked.right = true;
|
worldBlocked.right = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos.y <= bounds.y && check.up)
|
if (check.up && pos.y <= bounds.y)
|
||||||
{
|
{
|
||||||
set = true;
|
set = true;
|
||||||
pos.y = bounds.y;
|
pos.y = bounds.y;
|
||||||
worldBlocked.up = true;
|
worldBlocked.up = true;
|
||||||
}
|
}
|
||||||
else if (this.bottom >= bounds.bottom && check.down)
|
else if (check.down && this.bottom >= bounds.bottom)
|
||||||
{
|
{
|
||||||
set = true;
|
set = true;
|
||||||
pos.y = bounds.bottom - this.height;
|
pos.y = bounds.bottom - this.height;
|
||||||
|
@ -1159,11 +1141,6 @@ var Body = new Class({
|
||||||
return set;
|
return set;
|
||||||
},
|
},
|
||||||
|
|
||||||
getOverlapX: function (body, bias)
|
|
||||||
{
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the offset of the Body's position from its Game Object's position.
|
* Sets the offset of the Body's position from its Game Object's position.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue