mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
Pushing to carry on debugging at home
This commit is contained in:
parent
0a87a0bdef
commit
dc31e39e01
3 changed files with 160 additions and 56 deletions
|
@ -8,6 +8,7 @@ var CircleContains = require('../../geom/circle/Contains');
|
|||
var Class = require('../../utils/Class');
|
||||
var CONST = require('./const');
|
||||
var Events = require('./events');
|
||||
var FuzzyEqual = require('../../math/fuzzy/Equal');
|
||||
var FuzzyLessThan = require('../../math/fuzzy/LessThan');
|
||||
var FuzzyGreaterThan = require('../../math/fuzzy/GreaterThan');
|
||||
var RadToDeg = require('../../math/RadToDeg');
|
||||
|
@ -685,6 +686,15 @@ var Body = new Class({
|
|||
*/
|
||||
this.blocked = { none: true, up: false, down: false, left: false, right: false, by: null };
|
||||
|
||||
/**
|
||||
* Whether this Body was blocked from moving in a given direction during the last step.
|
||||
*
|
||||
* @name Phaser.Physics.Arcade.Body#wasBlocked
|
||||
* @type {Phaser.Physics.Arcade.Types.ArcadeBodyCollision}
|
||||
* @since 3.17.0
|
||||
*/
|
||||
this.wasBlocked = { none: true, up: false, down: false, left: false, right: false };
|
||||
|
||||
/**
|
||||
* Whether this Body is colliding with a tile or the world boundary.
|
||||
*
|
||||
|
@ -884,24 +894,25 @@ var Body = new Class({
|
|||
*/
|
||||
preUpdate: function ()
|
||||
{
|
||||
var wasTouching = this.wasTouching;
|
||||
console.log('preUpdate', this.wasBlocked.down);
|
||||
|
||||
var touching = this.touching;
|
||||
var blocked = this.blocked;
|
||||
var worldBlocked = this.worldBlocked;
|
||||
|
||||
// Store and reset collision flags
|
||||
wasTouching.none = touching.none;
|
||||
wasTouching.up = touching.up;
|
||||
wasTouching.down = touching.down;
|
||||
wasTouching.left = touching.left;
|
||||
wasTouching.right = touching.right;
|
||||
|
||||
touching.none = true;
|
||||
touching.up = false;
|
||||
touching.down = false;
|
||||
touching.left = false;
|
||||
touching.right = false;
|
||||
|
||||
blocked.by = null;
|
||||
blocked.none = true;
|
||||
blocked.up = false;
|
||||
blocked.down = false;
|
||||
blocked.left = false;
|
||||
blocked.right = false;
|
||||
|
||||
worldBlocked.none = true;
|
||||
worldBlocked.left = false;
|
||||
worldBlocked.right = false;
|
||||
|
@ -922,22 +933,21 @@ var Body = new Class({
|
|||
this.position.x = sprite.x + sprite.scaleX * (this.offset.x - sprite.displayOriginX);
|
||||
this.position.y = sprite.y + sprite.scaleY * (this.offset.y - sprite.displayOriginY);
|
||||
|
||||
if (this.collideWorldBounds)
|
||||
if (this.collideWorldBounds && this.checkWorldBounds())
|
||||
{
|
||||
this.checkWorldBounds();
|
||||
console.log('preUpdate cwb', worldBlocked.down, 'was', this.wasBlocked.down);
|
||||
|
||||
blocked.up = worldBlocked.up;
|
||||
blocked.down = worldBlocked.down;
|
||||
blocked.left = worldBlocked.left;
|
||||
blocked.right = worldBlocked.right;
|
||||
blocked.none = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.updateCenter();
|
||||
}
|
||||
|
||||
blocked.by = null;
|
||||
blocked.up = worldBlocked.up;
|
||||
blocked.down = worldBlocked.down;
|
||||
blocked.left = worldBlocked.left;
|
||||
blocked.right = worldBlocked.right;
|
||||
blocked.none = (!blocked.up && !blocked.down && !blocked.left && !blocked.right);
|
||||
|
||||
this.rotation = sprite.rotation;
|
||||
|
||||
this.preRotation = this.rotation;
|
||||
|
@ -962,6 +972,8 @@ var Body = new Class({
|
|||
*/
|
||||
update: function (delta)
|
||||
{
|
||||
console.log('update', this.wasBlocked.down);
|
||||
|
||||
var velocity = this.velocity;
|
||||
var position = this.position;
|
||||
|
||||
|
@ -973,6 +985,8 @@ var Body = new Class({
|
|||
position.y += this.getMoveY(velocity.y * delta);
|
||||
}
|
||||
|
||||
console.log('update2', this.worldBlocked.down, 'was', this.wasBlocked.down);
|
||||
|
||||
// Calculate the delta
|
||||
this._dx = position.x - this.prev.x;
|
||||
this._dy = position.y - this.prev.y;
|
||||
|
@ -980,27 +994,63 @@ var Body = new Class({
|
|||
var worldBlocked = this.worldBlocked;
|
||||
|
||||
// World Bounds check
|
||||
if (this.collideWorldBounds && !worldBlocked.none)
|
||||
if (this.collideWorldBounds)
|
||||
{
|
||||
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
|
||||
console.log('update3', this.wasBlocked.down, 'w', this.worldBlocked.down, 'n', this.worldBlocked.none);
|
||||
|
||||
if ((worldBlocked.left && velocity.x < 0) || (worldBlocked.right && velocity.x > 0))
|
||||
var wasBlocked = this.wasBlocked;
|
||||
|
||||
if (!worldBlocked.none)
|
||||
{
|
||||
velocity.x *= bx;
|
||||
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
|
||||
|
||||
// if ((worldBlocked.left && velocity.x < 0) || (worldBlocked.right && velocity.x > 0))
|
||||
// {
|
||||
// velocity.x *= bx;
|
||||
// }
|
||||
|
||||
console.log(worldBlocked.down, wasBlocked.down);
|
||||
|
||||
if (worldBlocked.down && velocity.y > 0)
|
||||
{
|
||||
velocity.y *= by;
|
||||
|
||||
// vy should now be negative
|
||||
|
||||
console.log('down', velocity.y, this._dy, wasBlocked.down);
|
||||
|
||||
// if (this._dy < -this.minBounceVelocity.y)
|
||||
// {
|
||||
// velocity.y = 0;
|
||||
// }
|
||||
}
|
||||
else if (worldBlocked.up && velocity.y < 0)
|
||||
{
|
||||
// vy should now be positive
|
||||
velocity.y *= by;
|
||||
|
||||
console.log('up', velocity.y, this._dy, wasBlocked.up);
|
||||
|
||||
// if (this._dy < this.minBounceVelocity.y)
|
||||
// {
|
||||
// velocity.y = 0;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
if ((worldBlocked.down && velocity.y > 0) || (worldBlocked.up && velocity.y < 0))
|
||||
{
|
||||
velocity.y *= by;
|
||||
}
|
||||
|
||||
|
||||
if (this.onWorldBounds)
|
||||
{
|
||||
this.world.emit(Events.WORLD_BOUNDS, this, worldBlocked.up, worldBlocked.down, worldBlocked.left, worldBlocked.right);
|
||||
}
|
||||
|
||||
wasBlocked.none = worldBlocked.none;
|
||||
wasBlocked.up = worldBlocked.up;
|
||||
wasBlocked.down = worldBlocked.down;
|
||||
wasBlocked.left = worldBlocked.left;
|
||||
wasBlocked.right = worldBlocked.right;
|
||||
}
|
||||
|
||||
this.updateCenter();
|
||||
|
@ -1086,6 +1136,26 @@ var Body = new Class({
|
|||
gameObject.angle += this.deltaZ();
|
||||
}
|
||||
|
||||
// Store collision flags
|
||||
var wasTouching = this.wasTouching;
|
||||
var wasBlocked = this.wasBlocked;
|
||||
var touching = this.touching;
|
||||
var worldBlocked = this.worldBlocked;
|
||||
|
||||
wasTouching.none = touching.none;
|
||||
wasTouching.up = touching.up;
|
||||
wasTouching.down = touching.down;
|
||||
wasTouching.left = touching.left;
|
||||
wasTouching.right = touching.right;
|
||||
|
||||
console.log('postUpdate', worldBlocked.down, 'was', wasBlocked.down);
|
||||
|
||||
// wasBlocked.none = worldBlocked.none;
|
||||
// wasBlocked.up = worldBlocked.up;
|
||||
// wasBlocked.down = worldBlocked.down;
|
||||
// wasBlocked.left = worldBlocked.left;
|
||||
// wasBlocked.right = worldBlocked.right;
|
||||
|
||||
this.prev.x = this.position.x;
|
||||
this.prev.y = this.position.y;
|
||||
},
|
||||
|
@ -1900,14 +1970,20 @@ var Body = new Class({
|
|||
|
||||
if (amount < 0 && check.up && pos.y + amount < bounds.y)
|
||||
{
|
||||
worldBlocked.none = false;
|
||||
worldBlocked.up = true;
|
||||
|
||||
blocked.up = true;
|
||||
|
||||
return amount - ((pos.y + amount) - bounds.y);
|
||||
}
|
||||
else if (amount > 0 && check.down && this.bottom + amount > bounds.bottom)
|
||||
{
|
||||
worldBlocked.none = false;
|
||||
worldBlocked.down = true;
|
||||
|
||||
blocked.down = true;
|
||||
|
||||
return amount - ((this.bottom + amount) - bounds.bottom);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
|
||||
var overlap = result[0];
|
||||
var faceTop = result[1];
|
||||
var faceBottom = !faceTop;
|
||||
// var faceBottom = !faceTop;
|
||||
|
||||
var velocity1 = body1.velocity;
|
||||
var velocity2 = body2.velocity;
|
||||
|
@ -83,9 +83,12 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
var ny1 = v1;
|
||||
var ny2 = v2;
|
||||
|
||||
if (!body1Immovable && !body2Immovable)
|
||||
var body1BlockedY = (blocked1.up || blocked1.down);
|
||||
var body2BlockedY = (blocked2.up || blocked2.down);
|
||||
|
||||
if (!body1Immovable && !body1BlockedY && !body2Immovable && !body2BlockedY)
|
||||
{
|
||||
// Neither body is immovable, so they get a new velocity based on mass
|
||||
// Neither body is immovable or blocked, so they get a new velocity based on mass
|
||||
var mass1 = body1.mass;
|
||||
var mass2 = body2.mass;
|
||||
|
||||
|
@ -100,27 +103,58 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
ny1 = avg + nv1 * body1.bounce.y;
|
||||
ny2 = avg + nv2 * body2.bounce.y;
|
||||
}
|
||||
else if (body1Immovable)
|
||||
else if (body1BlockedY || body1Immovable)
|
||||
{
|
||||
// Body1 is immovable, so carries on at the same speed regardless, adjust body2 speed
|
||||
// ny2 = v1 - v2 * body2.bounce.y;
|
||||
ny2 = v1 - v2;
|
||||
// Body1 is blocked or never changes speed, so adjust body2 speed
|
||||
ny2 = v1 - v2 * body2.bounce.y;
|
||||
}
|
||||
else if (body2Immovable)
|
||||
else if (body2BlockedY || body2Immovable)
|
||||
{
|
||||
// Body2 is immovable, so carries on at the same speed regardless, adjust body1 speed
|
||||
// ny1 = v2 - v1 * body1.bounce.y;
|
||||
ny1 = v2 - v1;
|
||||
// Body2 is blocked or never changes speed, so adjust body1 speed
|
||||
ny1 = v2 - v1 * body1.bounce.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Both bodies are equally blocked
|
||||
console.log('Both bodies are equally blocked, kill velocity?');
|
||||
}
|
||||
|
||||
// Velocities calculated, time to work out what moves where
|
||||
|
||||
if (overlap !== 0)
|
||||
{
|
||||
// var p1 = (faceBottom) ? body1.bottom - body2.y : body2.bottom - body1.y;
|
||||
// console.log('impact', v1, v2, 'overlap', overlap, p1);
|
||||
|
||||
var share = overlap * 0.5;
|
||||
var amount1 = body1.getMoveY(share);
|
||||
var amount2 = body2.getMoveY(-share);
|
||||
|
||||
if (amount1 !== share)
|
||||
{
|
||||
// console.log('diff1', share, amount1, amount2);
|
||||
amount2 -= (share - amount1);
|
||||
}
|
||||
else if (amount2 !== -share)
|
||||
{
|
||||
// console.log('diff2', share, amount1, amount2);
|
||||
amount1 += (share + amount2);
|
||||
}
|
||||
|
||||
body1.y += amount1;
|
||||
body2.y += amount2;
|
||||
|
||||
// var p2 = (faceBottom) ? body1.bottom - body2.y : body2.bottom - body1.y;
|
||||
// console.log('post-impact', p2);
|
||||
}
|
||||
|
||||
// -------------------------------------------
|
||||
// 1) Bail out if nothing is blocking anything
|
||||
// -------------------------------------------
|
||||
|
||||
if (blocked1.none && blocked2.none)
|
||||
if (!body1BlockedY && !body2BlockedY)
|
||||
{
|
||||
/*
|
||||
if (overlap !== 0)
|
||||
{
|
||||
// var p1 = (faceBottom) ? body1.bottom - body2.y : body2.bottom - body1.y;
|
||||
|
@ -153,26 +187,13 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
|
|||
// }
|
||||
|
||||
// console.log('----------------------------------');
|
||||
*/
|
||||
|
||||
velocity1.y = ny1;
|
||||
velocity2.y = ny2;
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (blocked1.none)
|
||||
{
|
||||
// Body2 is blocked from moving, so Body1 needs to move
|
||||
|
||||
}
|
||||
else if (blocked2.none)
|
||||
{
|
||||
// Body1 is blocked from moving, so Body2 needs to move
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nothing can move anywhere!
|
||||
}
|
||||
|
||||
// -------------------------------------------
|
||||
// 2) Body1 motion checks
|
||||
|
|
|
@ -913,6 +913,8 @@ var World = new Class({
|
|||
return;
|
||||
}
|
||||
|
||||
console.log('------->');
|
||||
|
||||
// Update all active bodies
|
||||
var body;
|
||||
var bodies = this.bodies.entries;
|
||||
|
@ -946,6 +948,11 @@ var World = new Class({
|
|||
this.step(fixedDelta);
|
||||
}
|
||||
|
||||
if (stepsThisFrame > 1)
|
||||
{
|
||||
console.log('extra step');
|
||||
}
|
||||
|
||||
this.stepsLastFrame = stepsThisFrame;
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue