Skip to content

Commit 89e33ae

Browse files
committed
Testing. Please do not use this build, it will break AP.
1 parent 9db9511 commit 89e33ae

4 files changed

Lines changed: 304 additions & 114 deletions

File tree

src/physics/arcade/Body.js

Lines changed: 112 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -666,13 +666,22 @@ var Body = new Class({
666666
this.wasTouching = { none: true, up: false, down: false, left: false, right: false };
667667

668668
/**
669-
* Whether this Body is colliding with a tile or the world boundary.
669+
* Whether this Body is blocked from moving in a given direction.
670670
*
671671
* @name Phaser.Physics.Arcade.Body#blocked
672672
* @type {Phaser.Physics.Arcade.Types.ArcadeBodyCollision}
673673
* @since 3.0.0
674674
*/
675-
this.blocked = { none: true, up: false, down: false, left: false, right: false };
675+
this.blocked = { none: true, up: false, down: false, left: false, right: false, x: 0, y: 0 };
676+
677+
/**
678+
* Whether this Body is colliding with a tile or the world boundary.
679+
*
680+
* @name Phaser.Physics.Arcade.Body#worldBlocked
681+
* @type {Phaser.Physics.Arcade.Types.ArcadeBodyCollision}
682+
* @since 3.17.0
683+
*/
684+
this.worldBlocked = { up: false, down: false, left: false, right: false };
676685

677686
/**
678687
* Whether to automatically synchronize this Body's dimensions to the dimensions of its Game Object's visual bounds.
@@ -718,17 +727,6 @@ var Body = new Class({
718727
*/
719728
this.physicsType = CONST.DYNAMIC_BODY;
720729

721-
/**
722-
* Whether the Body's position needs updating from its Game Object.
723-
*
724-
* @name Phaser.Physics.Arcade.Body#_reset
725-
* @type {boolean}
726-
* @private
727-
* @default true
728-
* @since 3.0.0
729-
*/
730-
this._reset = true;
731-
732730
/**
733731
* Cached horizontal scale of the Body's Game Object.
734732
*
@@ -875,24 +873,28 @@ var Body = new Class({
875873
*/
876874
preUpdate: function ()
877875
{
876+
var wasTouching = this.wasTouching;
877+
var touching = this.touching;
878+
var blocked = this.blocked;
879+
var worldBlocked = this.worldBlocked;
880+
878881
// Store and reset collision flags
879-
this.wasTouching.none = this.touching.none;
880-
this.wasTouching.up = this.touching.up;
881-
this.wasTouching.down = this.touching.down;
882-
this.wasTouching.left = this.touching.left;
883-
this.wasTouching.right = this.touching.right;
884-
885-
this.touching.none = true;
886-
this.touching.up = false;
887-
this.touching.down = false;
888-
this.touching.left = false;
889-
this.touching.right = false;
890-
891-
this.blocked.none = true;
892-
this.blocked.up = false;
893-
this.blocked.down = false;
894-
this.blocked.left = false;
895-
this.blocked.right = false;
882+
wasTouching.none = touching.none;
883+
wasTouching.up = touching.up;
884+
wasTouching.down = touching.down;
885+
wasTouching.left = touching.left;
886+
wasTouching.right = touching.right;
887+
888+
touching.none = true;
889+
touching.up = false;
890+
touching.down = false;
891+
touching.left = false;
892+
touching.right = false;
893+
894+
worldBlocked.left = false;
895+
worldBlocked.right = false;
896+
worldBlocked.up = false;
897+
worldBlocked.down = false;
896898

897899
this.overlapR = 0;
898900
this.overlapX = 0;
@@ -908,17 +910,27 @@ var Body = new Class({
908910
this.position.x = sprite.x + sprite.scaleX * (this.offset.x - sprite.displayOriginX);
909911
this.position.y = sprite.y + sprite.scaleY * (this.offset.y - sprite.displayOriginY);
910912

911-
this.updateCenter();
913+
if (this.collideWorldBounds)
914+
{
915+
this.checkWorldBounds();
916+
}
917+
else
918+
{
919+
this.updateCenter();
920+
}
921+
922+
blocked.up = worldBlocked.up;
923+
blocked.down = worldBlocked.down;
924+
blocked.left = worldBlocked.left;
925+
blocked.right = worldBlocked.right;
926+
blocked.none = (!blocked.up && !blocked.down && !blocked.left && !blocked.right);
912927

913928
this.rotation = sprite.rotation;
914929

915930
this.preRotation = this.rotation;
916931

917-
if (this._reset)
918-
{
919-
this.prev.x = this.position.x;
920-
this.prev.y = this.position.y;
921-
}
932+
this.prev.x = this.position.x;
933+
this.prev.y = this.position.y;
922934
},
923935

924936
/**
@@ -937,57 +949,65 @@ var Body = new Class({
937949
*/
938950
update: function (delta)
939951
{
952+
console.log(this.gameObject.name, 'upd');
953+
940954
if (this.moves)
941955
{
942956
this.world.updateMotion(this, delta);
943957

944-
var vx = this.velocity.x;
945-
var vy = this.velocity.y;
958+
var velocity = this.velocity;
946959

947-
this.newVelocity.set(vx * delta, vy * delta);
960+
var nx = velocity.x * delta;
961+
var ny = velocity.y * delta;
948962

949-
this.position.add(this.newVelocity);
963+
if (nx !== 0)
964+
{
965+
this.position.x += this.getMoveX(nx);
966+
}
967+
968+
if (ny !== 0)
969+
{
970+
this.position.y += this.getMoveY(ny);
971+
}
950972

951973
this.updateCenter();
952974

953-
this.angle = Math.atan2(vy, vx);
954-
this.speed = Math.sqrt(vx * vx + vy * vy);
975+
this.angle = Math.atan2(velocity.y, velocity.x);
976+
this.speed = Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y);
955977
}
956978

957979
// Calculate the delta
958980
this._dx = this.position.x - this.prev.x;
959981
this._dy = this.position.y - this.prev.y;
960982

961983
// World Bounds check
962-
if (this.collideWorldBounds && this.checkWorldBounds())
984+
if (this.collideWorldBounds)
963985
{
964986
var bx = (this.worldBounce) ? -this.worldBounce.x : -this.bounce.x;
965987
var by = (this.worldBounce) ? -this.worldBounce.y : -this.bounce.y;
966-
var blocked = this.blocked;
967-
968-
if (blocked.left || blocked.right)
988+
var worldBlocked = this.worldBlocked;
989+
990+
if ((worldBlocked.left || worldBlocked.right))
969991
{
970992
if (bx !== 0)
971993
{
972994
// Reverse the velocity for the bounce and flip the delta
973-
this.velocity.x *= bx;
974-
this._dx *= -1;
995+
velocity.x *= bx;
975996
}
976997
}
977998

978-
if (blocked.up || blocked.down)
999+
if ((worldBlocked.up || worldBlocked.down))
9791000
{
9801001
if (by !== 0)
9811002
{
9821003
// Reverse the velocity for the bounce and flip the delta
983-
this.velocity.y *= by;
984-
this._dy *= -1;
1004+
velocity.y *= by;
9851005
}
9861006
}
9871007

9881008
if (this.onWorldBounds)
9891009
{
990-
this.world.emit(Events.WORLD_BOUNDS, this, this.blocked.up, this.blocked.down, this.blocked.left, this.blocked.right);
1010+
this.world.emit(Events.WORLD_BOUNDS, this, worldBlocked.up, worldBlocked.down, worldBlocked.left, worldBlocked.right);
9911011
}
9921012
}
9931013

@@ -1005,8 +1025,16 @@ var Body = new Class({
10051025
*/
10061026
postUpdate: function ()
10071027
{
1008-
var dx = this.position.x - this.prev.x;
1009-
var dy = this.position.y - this.prev.y;
1028+
// var dx = this.position.x - this.prev.x;
1029+
// var dy = this.position.y - this.prev.y;
1030+
1031+
var gameObject = this.gameObject;
1032+
1033+
var px = gameObject.x + gameObject.scaleX * (this.offset.x - gameObject.displayOriginX);
1034+
var py = gameObject.y + gameObject.scaleY * (this.offset.y - gameObject.displayOriginY);
1035+
1036+
var dx = this.position.x - px;
1037+
var dy = this.position.y - py;
10101038

10111039
if (this.moves)
10121040
{
@@ -1036,13 +1064,11 @@ var Body = new Class({
10361064
dy = my;
10371065
}
10381066
}
1039-
1040-
this.gameObject.x += dx;
1041-
this.gameObject.y += dy;
1042-
1043-
this._reset = true;
10441067
}
10451068

1069+
gameObject.x += dx;
1070+
gameObject.y += dy;
1071+
10461072
if (dx < 0)
10471073
{
10481074
this.facing = CONST.FACING_LEFT;
@@ -1066,7 +1092,7 @@ var Body = new Class({
10661092

10671093
if (this.allowRotation)
10681094
{
1069-
this.gameObject.angle += this.deltaZ();
1095+
gameObject.angle += this.deltaZ();
10701096
}
10711097

10721098
this.prev.x = this.position.x;
@@ -1083,6 +1109,8 @@ var Body = new Class({
10831109
*/
10841110
checkWorldBounds: function ()
10851111
{
1112+
var worldBlocked = this.worldBlocked;
1113+
10861114
var pos = this.position;
10871115
var bounds = this.world.bounds;
10881116
var check = this.world.checkCollision;
@@ -1092,26 +1120,26 @@ var Body = new Class({
10921120
{
10931121
set = true;
10941122
pos.x = bounds.x;
1095-
this.setBlockedLeft();
1123+
worldBlocked.left = true;
10961124
}
10971125
else if (this.right >= bounds.right && check.right)
10981126
{
10991127
set = true;
11001128
pos.x = bounds.right - this.width;
1101-
this.setBlockedRight();
1129+
worldBlocked.right = true;
11021130
}
11031131

11041132
if (pos.y <= bounds.y && check.up)
11051133
{
11061134
set = true;
11071135
pos.y = bounds.y;
1108-
this.setBlockedUp();
1136+
worldBlocked.up = true;
11091137
}
11101138
else if (this.bottom >= bounds.bottom && check.down)
11111139
{
11121140
set = true;
11131141
pos.y = bounds.bottom - this.height;
1114-
this.setBlockedDown();
1142+
worldBlocked.down = true;
11151143
}
11161144

11171145
if (set)
@@ -1766,10 +1794,8 @@ var Body = new Class({
17661794
return this;
17671795
},
17681796

1769-
getMoveX: function (amount, setBlocked)
1797+
getMoveX: function (amount)
17701798
{
1771-
if (setBlocked === undefined) { setBlocked = false; }
1772-
17731799
var blocked = this.blocked;
17741800

17751801
if (amount < 0 && blocked.left || amount > 0 && blocked.right)
@@ -1783,26 +1809,25 @@ var Body = new Class({
17831809
var pos = this.position;
17841810
var bounds = this.world.bounds;
17851811
var check = this.world.checkCollision;
1812+
var worldBlocked = this.worldBlocked;
17861813

17871814
if (amount < 0 && check.left && pos.x + amount < bounds.x)
17881815
{
1789-
this.setBlockedLeft();
1816+
worldBlocked.left = true;
17901817
return amount - ((pos.x + amount) - bounds.x);
17911818
}
17921819
else if (amount > 0 && check.right && this.right + amount > bounds.right)
17931820
{
1794-
this.setBlockedRight();
1821+
worldBlocked.right = true;
17951822
return amount - ((this.right + amount) - bounds.right);
17961823
}
17971824
}
17981825

17991826
return amount;
18001827
},
18011828

1802-
getMoveY: function (amount, setBlocked)
1829+
getMoveY: function (amount)
18031830
{
1804-
if (setBlocked === undefined) { setBlocked = false; }
1805-
18061831
var blocked = this.blocked;
18071832

18081833
if (amount < 0 && blocked.up || amount > 0 && blocked.down)
@@ -1816,15 +1841,18 @@ var Body = new Class({
18161841
var pos = this.position;
18171842
var bounds = this.world.bounds;
18181843
var check = this.world.checkCollision;
1844+
var worldBlocked = this.worldBlocked;
18191845

18201846
if (amount < 0 && check.up && pos.y + amount < bounds.y)
18211847
{
1822-
this.setBlockedUp();
1848+
worldBlocked.up = true;
1849+
blocked.up = true;
18231850
return amount - ((pos.y + amount) - bounds.y);
18241851
}
18251852
else if (amount > 0 && check.down && this.bottom + amount > bounds.bottom)
18261853
{
1827-
this.setBlockedDown();
1854+
worldBlocked.down = true;
1855+
blocked.down = true;
18281856
return amount - ((this.bottom + amount) - bounds.bottom);
18291857
}
18301858
}
@@ -2270,14 +2298,18 @@ var Body = new Class({
22702298
*
22712299
* @name Phaser.Physics.Arcade.Body#right
22722300
* @type {number}
2273-
* @readonly
22742301
* @since 3.0.0
22752302
*/
22762303
right: {
22772304

22782305
get: function ()
22792306
{
22802307
return this.position.x + this.width;
2308+
},
2309+
2310+
set: function (value)
2311+
{
2312+
this.position.x = value - this.width;
22812313
}
22822314

22832315
},
@@ -2304,14 +2336,18 @@ var Body = new Class({
23042336
*
23052337
* @name Phaser.Physics.Arcade.Body#bottom
23062338
* @type {number}
2307-
* @readonly
23082339
* @since 3.0.0
23092340
*/
23102341
bottom: {
23112342

23122343
get: function ()
23132344
{
23142345
return this.position.y + this.height;
2346+
},
2347+
2348+
set: function (value)
2349+
{
2350+
this.position.y = value - this.height;
23152351
}
23162352

23172353
}

0 commit comments

Comments
 (0)