55 */
66
77var CONST = require ( './const' ) ;
8- var GetOverlapX = require ( './GetOverlapX' ) ;
98
109/**
1110 * Separates two overlapping bodies on the X-axis (horizontally).
@@ -26,25 +25,19 @@ var GetOverlapX = require('./GetOverlapX');
2625 *
2726 * @return {boolean } `true` if the two bodies overlap horizontally, otherwise `false`.
2827 */
29- var SeparateX = function ( body1 , body2 , overlapOnly , bias )
28+ var SeparateX = function ( collisionInfo )
3029{
31- // console.log('');
32- // console.log('%c frame ' + body1.world._frame + ' ', 'background-color: orange');
33- // console.log('body1:', body1.gameObject.name, 'vs body2:', body2.gameObject.name);
34- // console.log('pre-GetOverlap by = body1', body1.y, 'body2', body2.y);
35- // console.log('pre-GetOverlap gy = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
36-
37- var collisionInfo = GetOverlapX ( body1 , body2 , overlapOnly , bias ) ;
38-
39- // console.log(collisionInfo);
40- // console.log('post-GetOverlap by = body1', body1.y, 'body2', body2.y);
41- // console.log('post-GetOverlap gy = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
30+ var overlap = collisionInfo . overlapX ;
31+ var overlapOnly = collisionInfo . overlapOnly ;
4232
43- var overlap = collisionInfo . overlapY ;
44- var leftFace = collisionInfo . face === CONST . FACING_LEFT ;
33+ var leftFace = collisionInfo . faceX === CONST . FACING_LEFT ;
4534 var rightFace = ! leftFace ;
35+
4636 var intersects = collisionInfo . intersects ;
4737
38+ var body1 = collisionInfo . body1 ;
39+ var body2 = collisionInfo . body2 ;
40+
4841 var velocity1 = body1 . velocity ;
4942 var velocity2 = body2 . velocity ;
5043
@@ -54,7 +47,18 @@ var SeparateX = function (body1, body2, overlapOnly, bias)
5447 var body1Immovable = ( body1 . physicsType === CONST . STATIC_BODY || body1 . immovable ) ;
5548 var body2Immovable = ( body2 . physicsType === CONST . STATIC_BODY || body2 . immovable ) ;
5649
57- // console.log('body1 overlaps body2 across the', ((leftFace) ? 'left' : 'right'), 'by', overlap, 'px');
50+ console . log ( '' ) ;
51+ console . log ( '%c X frame ' + body1 . world . _frame + ' ' , 'background-color: orange' ) ;
52+ console . log ( 'body1:' , body1 . gameObject . name , 'vs body2:' , body2 . gameObject . name ) ;
53+
54+ // console.log('pre-GetOverlap by = body1', body1.y, 'body2', body2.y);
55+ // console.log('pre-GetOverlap gy = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
56+
57+ // console.log(collisionInfo);
58+ // console.log('post-GetOverlap by = body1', body1.y, 'body2', body2.y);
59+ // console.log('post-GetOverlap gy = body1', body1.gameObject.y, 'body2', body2.gameObject.y);
60+
61+ console . log ( 'body1 overlaps body2 across the' , ( ( leftFace ) ? 'left' : 'right' ) , 'by' , overlap , 'px' ) ;
5862
5963 // Can't separate two immovable bodies, or a body with its own custom separation logic
6064 if ( ! intersects || overlapOnly || ( body1Immovable && body2Immovable ) || body1 . customSeparateX || body2 . customSeparateX )
@@ -107,11 +111,11 @@ var SeparateX = function (body1, body2, overlapOnly, bias)
107111 nx1 = avg + nv1 * bounce1 . x ;
108112 nx2 = avg + nv2 * bounce2 . x ;
109113
110- // console.log('resolution 1');
111- // console.log('pre-impact v = body1', x1, 'body2', x2);
112- // console.log('post-impact v = body1', nx1, 'body2', nx2);
113- // console.log('pre-impact y = body1', body1.gameObject.y , 'body2', body2.gameObject.y );
114- // console.log('wb = body1', body1.worldBlocked.down , 'body2', body2.worldBlocked.down );
114+ console . log ( 'resolution 1' ) ;
115+ console . log ( 'pre-impact v = body1' , x1 , 'body2' , x2 ) ;
116+ console . log ( 'post-impact v = body1' , nx1 , 'body2' , nx2 ) ;
117+ console . log ( 'pre-impact x = body1' , body1 . gameObject . x , 'body2' , body2 . gameObject . x ) ;
118+
77EC
// console.log('wb = body1', body1.worldBlocked.right , 'body2', body2.worldBlocked.left );
115119
116120 // console.log('avg', avg);
117121 // console.log('nv', nv1, nv2);
@@ -131,7 +135,7 @@ var SeparateX = function (body1, body2, overlapOnly, bias)
131135 nx2 = x1 - x2 * bounce2 . x ;
132136 }
133137
134- // console.log('%cresolution 3 ', 'background-color: red; color: white');
138+ // console.log('%cresolution 2 ', 'background-color: red; color: white');
135139 // console.log('pre-impact v = body1', x1, 'body2', x2);
136140 // console.log('post-impact v = body1', nx1, 'body2', nx2);
137141 // console.log('pre-impact by = body1', body1.y, 'body2', body2.y);
@@ -172,10 +176,10 @@ var SeparateX = function (body1, body2, overlapOnly, bias)
172176 nx2 = 0 ;
173177 }
174178
175- var totalA = collisionInfo . share1 ;
176- var totalB = collisionInfo . share2 ;
179+ var totalA = collisionInfo . shareX1 ;
180+ var totalB = collisionInfo . shareX2 ;
177181
178- // console.log('split at', totalA, totalB, 'of', overlap);
182+ console . log ( 'split at' , totalA , totalB , 'of' , overlap ) ;
179183
180184 if ( totalA === 0 && totalB === 0 && overlap !== 0 )
181185 {
@@ -211,37 +215,37 @@ var SeparateX = function (body1, body2, overlapOnly, bias)
211215
212216 if ( leftFace )
213217 {
214- // The top of Body1 overlaps with the bottom of Body2
218+ // The left of Body1 overlaps with the right of Body2
215219 if ( body2 . isBlockedLeft ( ) )
216220 {
217- // console.log('nx1 < 0 topface up ', body1.y );
221+ console . log ( 'nx1 <> 0 leftface ' , body1 . x ) ;
218222 body1 . setBlockedLeft ( collisionInfo , body2 ) ;
219223 }
220224 else
221225 {
222- // console.log('nx1 < 0 topface add', body1.y );
223- body1 . y += body1 . getMoveX ( totalA ) ;
226+ console . log ( 'nx1 <> 0 leftface add' , body1 . x ) ;
227+ body1 . x += body1 . getMoveX ( totalA ) ;
224228 }
225229 }
226230 else if ( rightFace )
227231 {
228- // The bottom of Body1 overlaps with the top of Body2
232+ // The right of Body1 overlaps with the left of Body2
229233 if ( body2 . isBlockedRight ( ) )
230234 {
231- // console.log('nx1 < 0 bottomface down ', body1.y );
235+ console . log ( 'nx1 <> 0 rightface right ' , body1 . x ) ;
232236 body1 . setBlockedRight ( collisionInfo , body2 ) ;
233237 }
234238 else
235239 {
236- // console.log('nx1 < 0 bottomface add', body1.y );
237- body1 . y += body1 . getMoveX ( totalA ) ;
240+ console . log ( 'nx1 <> 0 rightface add' , body1 . x ) ;
241+ body1 . x += body1 . getMoveX ( totalA ) ;
238242 }
239243 }
240244
241245 // If Body1 cannot move up, it doesn't matter what new velocity it has.
242246 if ( body1 . sleeping && ( nx1 < 0 && body1 . isBlockedLeft ( ) ) || ( nx1 > 0 && body1 . isBlockedRight ( ) ) )
243247 {
244- // console.log('nx1 < 0 zero sleep');
248+ console . log ( 'nx1 <> 0 zero sleep' ) ;
245249 nx1 = 0 ;
246250 }
247251 }
@@ -254,13 +258,13 @@ var SeparateX = function (body1, body2, overlapOnly, bias)
254258 // The top of Body1 overlaps with the bottom of Body2
255259 if ( totalA !== 0 && ! body1 . isBlockedRight ( ) )
256260 {
257- // console.log('body1 stationary topface add', body1.y );
258- body1 . y += body1 . getMoveX ( totalA ) ;
261+ console . log ( 'body1 stationary leftface add' , body1 . x ) ;
262+ body1 . x += body1 . getMoveX ( totalA ) ;
259263 }
260264
261265 if ( body2 . isBlockedLeft ( ) )
262266 {
263- // console.log('body1 stationary topface up ', body1.y );
267+ console . log ( 'body1 stationary leftface left ' , body1 . x ) ;
264268 body1 . setBlockedLeft ( collisionInfo , body2 ) ;
265269 }
266270 }
@@ -269,13 +273,13 @@ var SeparateX = function (body1, body2, overlapOnly, bias)
269273 // The bottom of Body1 overlaps with the top of Body2
270274 if ( totalA !== 0 && ! body1 . isBlockedRight ( ) )
271275 {
272- // console.log('body1 stationary bottomface add', body1.y );
273- body1 . y += body1 . getMoveX ( totalA ) ;
276+ console . log ( 'body1 stationary rightface add' , body1 . x ) ;
277+ body1 . x += body1 . getMoveX ( totalA ) ;
274278 }
275279
276280 if ( body2 . isBlockedRight ( ) )
277281 {
278- // console.log('body1 stationary bottomface down', body1.y );
282+ console . log ( 'body1 stationary rightface down' , body1 . x ) ;
279283 body1 . setBlockedRight ( collisionInfo , body2 ) ;
280284 }
281285 }
@@ -291,34 +295,34 @@ var SeparateX = function (body1, body2, overlapOnly, bias)
291295 // The bottom of Body2 overlaps with the top of Body1
292296 if ( body1 . isBlockedRight ( ) )
293297 {
294- // console.log('nx2 < 0 topface down', body2.y );
298+ console . log ( 'nx2 <> 0 leftface down' , body2 . x ) ;
295299 body2 . setBlockedRight ( collisionInfo , body1 ) ;
296300 }
297301 else
298302 {
299- // console.log('nx2 < 0 topface add', body2.y );
300- body2 . y += body2 . getMoveX ( totalB ) ;
303+ console . log ( 'nx2 <> 0 leftface add' , body2 . x ) ;
304+ body2 . x += body2 . getMoveX ( totalB ) ;
301305 }
302306 }
303307 else if ( rightFace )
304308 {
305309 // The top of Body2 overlaps with the bottom of Body1
306310 if ( body1 . isBlockedLeft ( ) )
307311 {
308- // console.log('nx2 < 0 bottomface down', body2.y );
312+ console . log ( 'nx2 <> 0 rightface down' , body2 . x ) ;
309313 body2 . setBlockedLeft ( collisionInfo , body1 ) ;
310314 }
311315 else
312316 {
313- // console.log('nx2 < 0 bottomface add', body2.y );
314- body2 . y += body2 . getMoveX ( totalB ) ;
317+ console . log ( 'nx2 <> 0 rightface add' , body2 . x ) ;
318+ body2 . x += body2 . getMoveX ( totalB ) ;
315319 }
316320 }
317321
318322 // If Body2 cannot move up or down, it doesn't matter what new velocity it has
319323 if ( body2 . sleeping && ( nx2 < 0 && body2 . isBlockedLeft ( ) ) || ( nx2 > 0 && body2 . isBlockedRight ( ) ) )
320324 {
321- // console.log('nx2 < 0 zero sleep');
325+ console . log ( 'nx2 <> 0 zero sleep' ) ;
322326 nx2 = 0 ;
323327 }
324328 }
@@ -330,13 +334,13 @@ var SeparateX = function (body1, body2, overlapOnly, bias)
330334 // The bottom of Body2 overlaps with the top of Body1
331335 if ( totalB !== 0 && ! body2 . isBlockedRight ( ) )
332336 {
333- // console.log('body2 stationary topface add', body2.y );
334- body2 . y += body2 . getMoveX ( totalB ) ;
337+ console . log ( 'body2 stationary leftface add' , body2 . x ) ;
338+ body2 . x += body2 . getMoveX ( totalB ) ;
335339 }
336340
337341 if ( body1 . isBlockedRight ( ) )
338342 {
339- // console.log('body2 stationary topface down', body2.y );
343+ console . log ( 'body2 stationary leftface down' , body2 . x ) ;
340344 body2 . setBlockedRight ( collisionInfo , body1 ) ;
341345 }
342346 }
@@ -345,13 +349,13 @@ var SeparateX = function (body1, body2, overlapOnly, bias)
345349 // The top of Body2 overlaps with the bottom of Body1
346350 if ( totalB !== 0 && ! body2 . isBlockedLeft ( ) )
347351 {
348- // console.log('body2 stationary bottomface add', body2.y );
349- body2 . y += body2 . getMoveX ( totalB ) ;
352+ console . log ( 'body2 stationary rightface add' , body2 . x ) ;
353+ body2 . x += body2 . getMoveX ( totalB ) ;
350354 }
351355
352356 if ( body1 . isBlockedLeft ( ) )
353357 {
354- // console.log('body2 stationary bottomface down', body2.y );
358+ console . log ( 'body2 stationary rightface down' , body2 . x ) ;
355359 body2 . setBlockedLeft ( collisionInfo , body1 ) ;
356360 }
357361 }
0 commit comments