Skip to content

Commit d942d28

Browse files
committed
Swap to use canMove and also new moveX/Y methods
1 parent 5242a62 commit d942d28

2 files changed

Lines changed: 62 additions & 61 deletions

File tree

src/physics/arcade/SeparateX.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var SeparateX = function (collisionInfo)
5151
// console.log('%c X frame ' + body1.world._frame + ' ', 'background-color: orange');
5252
// console.log('body1:', body1.gameObject.name, 'vs body2:', body2.gameObject.name);
5353
// console.log('pre-GetOverlap bx = body1', body1.x, 'body2', body2.x);
54-
console.log('x compare (PRE-SX):', body1.right, 'body2', body2.x, '=', (body1.right - body2.x));
54+
// console.log('x compare (PRE-SX):', body1.right, 'body2', body2.x, '=', (body1.right - body2.x));
5555

5656
// console.log('pre-GetOverlap by = body1', body1.y, 'body2', body2.y);
5757
// console.log('pre-GetOverlap gy = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
@@ -65,7 +65,7 @@ var SeparateX = function (collisionInfo)
6565
// Can't separate two immovable bodies, or a body with its own custom separation logic
6666
if (!intersects || overlapOnly || (body1Immovable && body2Immovable) || body1.customSeparateX || body2.customSeparateX)
6767
{
68-
console.log(this.world._frame, 'SeparateX aborted');
68+
// console.log(this.world._frame, 'SeparateX aborted');
6969

7070
// return true if there was some overlap, otherwise false.
7171
return ((intersects && overlap !== 0) || (body1.embedded && body2.embedded));
@@ -81,10 +81,10 @@ var SeparateX = function (collisionInfo)
8181
// At this point, the velocity from gravity, world rebounds, etc has been factored in.
8282
// The body is moving the direction it wants to, but may be blocked and rebound.
8383

84-
var moving1 = body1.movingX();
85-
var moving2 = body2.movingX();
84+
var canMove1 = body1.canMoveX();
85+
var canMove2 = body2.canMoveX();
8686

87-
if (moving1 && moving2)
87+
if (canMove1 && canMove2)
8888
{
8989
// Neither body is immovable, so they get a new velocity based on mass
9090
var mass1 = body1.mass;
@@ -124,7 +124,7 @@ var SeparateX = function (collisionInfo)
124124
// console.log('sqrt mult', bnx1, bnx2);
125125
// console.log('delta', body1.deltaY(), body2.deltaY());
126126
}
127-
else if (!moving1 && moving2)
127+
else if (!canMove1 && canMove2)
128128
{
129129
// Body1 is immovable, so adjust body2 speed
130130

@@ -145,7 +145,7 @@ var SeparateX = function (collisionInfo)
145145
// console.log('wb = body1', body1.worldBlocked.down, 'body2', body2.worldBlocked.down);
146146
// console.log('sleeping? = body1', body1.sleeping, 'body2', body2.sleeping);
147147
}
148-
else if (moving1 && !moving2)
148+
else if (canMove1 && !canMove2)
149149
{
150150
// Body2 is immovable, so adjust body1 speed
151151

@@ -220,40 +220,40 @@ var SeparateX = function (collisionInfo)
220220
// The left of Body1 overlaps with the right of Body2
221221
if (body2.isBlockedLeft())
222222
{
223-
console.log('nx1 <> 0 left block left', body1.x);
223+
// console.log('nx1 <> 0 left block left', body1.x);
224224
body1.setBlockedLeft(collisionInfo, body2);
225225
}
226226
else
227227
{
228-
console.log('nx1 <> 0 left add', body1.x);
229-
body1.x += body1.getMoveX(totalA);
228+
// console.log('nx1 <> 0 left add', body1.x);
229+
body1.moveX(totalA);
230230
}
231231
}
232232
else if (rightFace)
233233
{
234234
// The right of Body1 overlaps with the left of Body2
235235
if (body2.isBlockedRight())
236236
{
237-
console.log('nx1 <> 0 right block right', body1.x);
237+
// console.log('nx1 <> 0 right block right', body1.x);
238238
body1.setBlockedRight(collisionInfo, body2);
239239
}
240240
else
241241
{
242-
console.log('nx1 <> 0 right add', body1.x);
243-
body1.x += body1.getMoveX(totalA);
242+
// console.log('nx1 <> 0 right add', body1.x);
243+
body1.moveX(totalA);
244244
}
245245
}
246246

247247
// If Body1 cannot move up, it doesn't matter what new velocity it has.
248248
if (body1.sleeping && (nx1 < 0 && body1.isBlockedLeft()) || (nx1 > 0 && body1.isBlockedRight()))
249249
{
250-
console.log('nx1 <> 0 zero sleep');
250+
// console.log('nx1 <> 0 zero sleep');
251251
nx1 = 0;
252252
}
253253
}
254254
else if (body1.moves)
255255
{
256-
console.log('body1 stationary', body1.right);
256+
// console.log('body1 stationary', body1.right);
257257

258258
// Body1 is now stationary
259259

@@ -267,7 +267,7 @@ var SeparateX = function (collisionInfo)
267267
// if (totalA !== 0 && !body1.isBlockedRight())
268268
// {
269269
// console.log('body1 stationary leftface add', body1.x, 'totalA', totalA);
270-
body1.x += body1.getMoveX(totalA);
270+
body1.moveX(totalA);
271271
// }
272272

273273
if (body2.isBlockedLeft())
@@ -287,7 +287,7 @@ var SeparateX = function (collisionInfo)
287287
// if (totalA !== 0 && !body1.isBlockedLeft())
288288
// {
289289
// console.log('body1 stationary rightface add', body1.x);
290-
body1.x += body1.getMoveX(totalA);
290+
body1.moveX(totalA);
291291
// }
292292

293293
if (body2.isBlockedRight())
@@ -308,40 +308,40 @@ var SeparateX = function (collisionInfo)
308308
// The bottom of Body2 overlaps with the top of Body1
309309
if (body1.isBlockedRight())
310310
{
311-
console.log('nx2 <> 0 leftface down', body2.x);
311+
// console.log('nx2 <> 0 leftface down', body2.x);
312312
body2.setBlockedRight(collisionInfo, body1);
313313
}
314314
else
315315
{
316-
console.log('nx2 <> 0 leftface add', body2.x);
317-
body2.x += body2.getMoveX(totalB);
316+
// console.log('nx2 <> 0 leftface add', body2.x);
317+
body2.moveX(totalB);
318318
}
319319
}
320320
else if (rightFace)
321321
{
322322
// The top of Body2 overlaps with the bottom of Body1
323323
if (body1.isBlockedLeft())
324324
{
325-
console.log('nx2 <> 0 rightface down', body2.x);
325+
// console.log('nx2 <> 0 rightface down', body2.x);
326326
body2.setBlockedLeft(collisionInfo, body1);
327327
}
328328
else
329329
{
330-
console.log('nx2 <> 0 rightface add', body2.x);
331-
body2.x += body2.getMoveX(totalB);
330+
// console.log('nx2 <> 0 rightface add', body2.x);
331+
body2.moveX(totalB);
332332
}
333333
}
334334

335335
// If Body2 cannot move up or down, it doesn't matter what new velocity it has
336336
if (body2.sleeping && (nx2 < 0 && body2.isBlockedLeft()) || (nx2 > 0 && body2.isBlockedRight()))
337337
{
338-
console.log('nx2 <> 0 zero sleep');
338+
// console.log('nx2 <> 0 zero sleep');
339339
nx2 = 0;
340340
}
341341
}
342342
else if (body2.moves)
343343
{
344-
console.log('body2 stationary', body2.x);
344+
// console.log('body2 stationary', body2.x);
345345

346346
// Body2 is stationary
347347
if (leftFace)
@@ -354,7 +354,7 @@ var SeparateX = function (collisionInfo)
354354
// if (totalB !== 0 && !body2.isBlockedRight())
355355
// {
356356
// console.log('body2 stationary leftface add', body2.x);
357-
body2.x += body2.getMoveX(totalB);
357+
body2.moveX(totalB);
358358
// }
359359

360360
if (body1.isBlockedRight())
@@ -373,7 +373,7 @@ var SeparateX = function (collisionInfo)
373373
// if (totalB !== 0 && !body2.isBlockedLeft())
374374
// {
375375
// console.log('body2 stationary rightface add', body2.x);
376-
body2.x += body2.getMoveX(totalB);
376+
body2.moveX(totalB);
377377
// }
378378

379379
if (body1.isBlockedLeft())
@@ -434,7 +434,7 @@ var SeparateX = function (collisionInfo)
434434
// console.log('post-GetOverlap bx = body1', body1.x, 'body2', body2.x);
435435
// console.log('post-GetOverlap bs = body1', body1.right, 'body2', body2.right);
436436

437-
console.log('x compare (POST-SX):', body1.right, 'body2', body2.x, '=', (body1.right - body2.x));
437+
// console.log('x compare (POST-SX):', body1.right, 'body2', body2.x, '=', (body1.right - body2.x));
438438

439439
// If we got this far then there WAS overlap, and separation is complete, so return true
440440
return true;

src/physics/arcade/SeparateY.js

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ var SeparateY = function (collisionInfo)
4747
var body1Immovable = (body1.physicsType === CONST.STATIC_BODY || body1.immovable);
4848
var body2Immovable = (body2.physicsType === CONST.STATIC_BODY || body2.immovable);
4949

50+
// collisionInfo.dump();
51+
5052
// console.log('');
5153
// console.log('%c Y frame ' + body1.world._frame + ' ', 'background-color: pink');
5254
// console.log('body1:', body1.gameObject.name, 'vs body2:', body2.gameObject.name);
5355

54-
console.log('pre-GetOverlap by = body1', body1.y, 'body2', body2.y);
55-
console.log('pre-GetOverlap compare = body1', body1.bottom, 'body2', body2.y);
56-
console.log('pre-GetOverlap gy = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
56+
// console.log('pre-GetOverlap by = body1', body1.y, 'body2', body2.y);
57+
// console.log('pre-GetOverlap compare = body1', body1.bottom, 'body2', body2.y);
58+
// console.log('pre-GetOverlap gy = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
5759

5860
// console.log(collisionInfo);
5961
// console.log('post-GetOverlap by = body1', body1.y, 'body2', body2.y);
@@ -64,7 +66,7 @@ var SeparateY = function (collisionInfo)
6466
// Can't separate two immovable bodies, or a body with its own custom separation logic
6567
if (!intersects || overlapOnly || (body1Immovable && body2Immovable) || body1.customSeparateY || body2.customSeparateY)
6668
{
67-
console.log(this.world._frame, 'SeparateY aborted');
69+
// console.log(this.world._frame, 'SeparateY aborted');
6870

6971
// return true if there was some overlap, otherwise false.
7072
return ((intersects && overlap !== 0) || (body1.embedded && body2.embedded));
@@ -80,10 +82,10 @@ var SeparateY = function (collisionInfo)
8082
// At this point, the velocity from gravity, world rebounds, etc has been factored in.
8183
// The body is moving the direction it wants to, but may be blocked and rebound.
8284

83-
var moving1 = body1.movingY();
84-
var moving2 = body2.movingY();
85+
var canMove1 = body1.canMoveY();
86+
var canMove2 = body2.canMoveY();
8587

86-
if (moving1 && moving2)
88+
if (canMove1 && canMove2)
8789
{
8890
// Neither body is immovable, so they get a new velocity based on mass
8991
var mass1 = body1.mass;
@@ -123,7 +125,7 @@ var SeparateY = function (collisionInfo)
123125
// console.log('sqrt mult', bnv1, bnv2);
124126
// console.log('delta', body1.deltaY(), body2.deltaY());
125127
}
126-
else if (!moving1 && moving2)
128+
else if (!canMove1 && canMove2)
127129
{
128130
// Body1 is immovable, so adjust body2 speed
129131

@@ -144,7 +146,7 @@ var SeparateY = function (collisionInfo)
144146
// console.log('wb = body1', body1.worldBlocked.down, 'body2', body2.worldBlocked.down);
145147
// console.log('sleeping? = body1', body1.sleeping, 'body2', body2.sleeping);
146148
}
147-
else if (moving1 && !moving2)
149+
else if (canMove1 && !canMove2)
148150
{
149151
// Body2 is immovable, so adjust body1 speed
150152

@@ -157,7 +159,7 @@ var SeparateY = function (collisionInfo)
157159
ny1 = v2 - v1 * bounce1.y;
158160
}
159161

160-
// console.log('resolution 4');
162+
// console.log('%cresolution 4', 'background-color: red; color: white');
161163
// console.log('pre-impact v = body1', v1, 'body2', v2);
162164
// console.log('post-impact v = body1', ny1, 'body2', ny2);
163165
// console.log('pre-impact y = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
@@ -180,7 +182,7 @@ var SeparateY = function (collisionInfo)
180182
var totalA = collisionInfo.shareY1;
181183
var totalB = collisionInfo.shareY2;
182184

183-
console.log('split at', totalA, totalB, 'of', overlap);
185+
// console.log('split at', totalA, totalB, 'of', overlap);
184186

185187
if (totalA === 0 && totalB === 0 && overlap !== 0)
186188
{
@@ -225,7 +227,7 @@ var SeparateY = function (collisionInfo)
225227
else
226228
{
227229
// console.log('ny1 < 0 topface add', body1.y);
228-
body1.y += body1.getMoveY(totalA);
230+
body1.moveY(totalA);
229231
}
230232
}
231233
else if (bottomFace)
@@ -239,7 +241,7 @@ var SeparateY = function (collisionInfo)
239241
else
240242
{
241243
// console.log('ny1 < 0 bottomface add', body1.y);
242-
body1.y += body1.getMoveY(totalA);
244+
body1.moveY(totalA);
243245
}
244246
}
245247

@@ -257,11 +259,11 @@ var SeparateY = function (collisionInfo)
257259
if (topFace)
258260
{
259261
// The top of Body1 overlaps with the bottom of Body2
260-
if (totalA !== 0 && !body1.isBlockedDown())
261-
{
262+
// if (totalA !== 0 && !body1.isBlockedDown())
263+
// {
262264
// console.log('body1 stationary topface add', body1.y);
263-
body1.y += body1.getMoveY(totalA);
264-
}
265+
body1.moveY(totalA);
266+
// }
265267

266268
if (body2.isBlockedUp())
267269
{
@@ -272,11 +274,11 @@ var SeparateY = function (collisionInfo)
272274
else if (bottomFace)
273275
{
274276
// The bottom of Body1 overlaps with the top of Body2
275-
if (totalA !== 0 && !body1.isBlockedUp())
276-
{
277+
// if (totalA !== 0 && !body1.isBlockedUp())
278+
// {
277279
// console.log('body1 stationary bottomface add', body1.y);
278-
body1.y += body1.getMoveY(totalA);
279-
}
280+
body1.moveY(totalA);
281+
// }
280282

281283
if (body2.isBlockedDown())
282284
{
@@ -302,7 +304,7 @@ var SeparateY = function (collisionInfo)
302304
else
303305
{
304306
// console.log('ny2 < 0 topface add', body2.y);
305-
body2.y += body2.getMoveY(totalB);
307+
body2.moveY(totalB);
306308
}
307309
}
308310
else if (bottomFace)
@@ -316,7 +318,7 @@ var SeparateY = function (collisionInfo)
316318
else
317319
{
318320
// console.log('ny2 < 0 bottomface add', body2.y);
319-
body2.y += body2.getMoveY(totalB);
321+
body2.moveY(totalB);
320322
}
321323
}
322324

@@ -333,11 +335,11 @@ var SeparateY = function (collisionInfo)
333335
if (topFace)
334336
{
335337
// The bottom of Body2 overlaps with the top of Body1
336-
if (totalB !== 0 && !body2.isBlockedDown())
337-
{
338+
// if (totalB !== 0 && !body2.isBlockedDown())
339+
// {
338340
// console.log('body2 stationary topface add', body2.y);
339-
body2.y += body2.getMoveY(totalB);
340-
}
341+
body2.moveY(totalB);
342+
// }
341343

342344
if (body1.isBlockedDown())
343345
{
@@ -348,11 +350,11 @@ var SeparateY = function (collisionInfo)
348350
else if (bottomFace)
349351
{
350352
// The top of Body2 overlaps with the bottom of Body1
351-
if (totalB !== 0 && !body2.isBlockedUp())
352-
{
353+
// if (totalB !== 0 && !body2.isBlockedUp())
354+
// {
353355
// console.log('body2 stationary bottomface add', body2.y);
354-
body2.y += body2.getMoveY(totalB);
355-
}
356+
body2.moveY(totalB);
357+
// }
356358

357359
if (body1.isBlockedUp())
358360
{
@@ -409,8 +411,7 @@ var SeparateY = function (collisionInfo)
409411
velocity1.y = ny1;
410412
velocity2.y = ny2;
411413

412-
console.log('post-GetOverlap by = body1', body1.y, 'body2', body2.y);
413-
console.log('post-GetOverlap compare = body1', body1.bottom, 'body2', body2.y);
414+
// console.log('y compare (SY): ', body1.bottom, 'body2', body2.y, '=', (body1.bottom - body2.y));
414415

415416
// If we got this far then there WAS overlap, and separation is complete, so return true
416417
return true;

0 commit comments

Comments
 (0)