Skip to content

Commit 06acf49

Browse files
committed
Refactored getMoveY
1 parent 026c204 commit 06acf49

1 file changed

Lines changed: 34 additions & 18 deletions

File tree

src/physics/arcade/Body.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ var Body = new Class({
12541254
{
12551255
var collisionInfo = blockers[i];
12561256

1257-
console.log('CI', collisionInfo.body1.gameObject.name, collisionInfo.body2.gameObject.name);
1257+
// console.log('CI', collisionInfo.body1.gameObject.name, collisionInfo.body2.gameObject.name);
12581258

12591259
if (collisionInfo.body1 === this)
12601260
{
@@ -1265,6 +1265,8 @@ var Body = new Class({
12651265
return collisionInfo.body1;
12661266
}
12671267
}
1268+
1269+
return null;
12681270
},
12691271

12701272
wake: function ()
@@ -1490,10 +1492,12 @@ var Body = new Class({
14901492

14911493
if (this._sleep >= this.sleepIterations)
14921494
{
1493-
console.log(this.world._frame, 'slept by checkSleep');
1495+
console.log(this.world._frame, 'checkSleep sending ...');
14941496

14951497
this.sleep(true);
14961498

1499+
console.log(this.world._frame, 'slept by checkSleep');
1500+
14971501
var gameObject = this.gameObject;
14981502

14991503
gameObject.x = this.x;
@@ -2498,38 +2502,50 @@ var Body = new Class({
24982502

24992503
getMoveY: function (amount)
25002504
{
2501-
if (amount === 0 || amount < 0 && this.isBlockedUp() || amount > 0 && this.isBlockedDown())
2505+
var diff = amount;
2506+
var bounds = this.world.bounds;
2507+
2508+
if (amount === 0)
25022509
{
2503-
// If it's already blocked, or zero, it can't go anywhere
2504-
return 0;
2510+
return diff;
25052511
}
2512+
else if (amount < 0 && this.isBlockedUp())
2513+
{
2514+
bounds = this.getBlocker(this.blockers.up);
25062515

2507-
if (this.collideWorldBounds)
2516+
if (bounds && this.y + amount < bounds.y)
2517+
{
2518+
diff = amount - ((this.y + amount) - bounds.y);
2519+
}
2520+
}
2521+
else if (amount > 0 && this.isBlockedDown())
2522+
{
2523+
bounds = this.getBlocker(this.blockers.down);
2524+
2525+
if (bounds && this.bottom + amount > bounds.bottom)
2526+
{
2527+
diff = amount - ((this.bottom + amount) - bounds.bottom);
2528+
}
2529+
}
2530+
else if (this.collideWorldBounds)
25082531
{
2509-
var worldBounds = this.world.bounds;
25102532
var worldCollision = this.world.checkCollision;
25112533

2512-
if (amount < 0 && worldCollision.up && this.y + amount < worldBounds.y)
2534+
if (amount < 0 && worldCollision.up && this.y + amount < bounds.y)
25132535
{
2514-
var diff1 = amount - ((this.y + amount) - worldBounds.y);
2536+
diff = amount - ((this.y + amount) - bounds.y);
25152537

25162538
this.setWorldBlockedUp(true);
2517-
2518-
return diff1;
25192539
}
2520-
else if (amount > 0 && worldCollision.down && this.bottom + amount > worldBounds.bottom)
2540+
else if (amount > 0 && worldCollision.down && this.bottom + amount > bounds.bottom)
25212541
{
2522-
var diff2 = amount - ((this.bottom + amount) - worldBounds.bottom);
2523-
2524-
// console.log(this.world._frame, 'via check get move y');
2542+
diff = amount - ((this.bottom + amount) - bounds.bottom);
25252543

25262544
this.setWorldBlockedDown(true);
2527-
2528-
return diff2;
25292545
}
25302546
}
25312547

2532-
return amount;
2548+
return diff;
25332549
},
25342550

25352551
/**

0 commit comments

Comments
 (0)