Skip to content

Commit 70f6484

Browse files
committed
Flag swizzles ahoy
1 parent 932f70c commit 70f6484

1 file changed

Lines changed: 107 additions & 86 deletions

File tree

src/physics/arcade/SeparateY.js

Lines changed: 107 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
4040
var blocked1 = body1.blocked;
4141
var blocked2 = body2.blocked;
4242

43-
console.log('SY', overlap, 'faceTop?', faceTop);
43+
// console.log('----------> SY', overlap, 'faceTop?', faceTop);
4444

4545
// console.log('SY', body1.gameObject.name, body2.gameObject.name, overlap, 'faceTop?', faceTop);
4646

@@ -65,12 +65,54 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
6565

6666
if (blocked2.up)
6767
{
68+
// console.log('a1');
6869
body1.setBlockedUp();
6970
}
7071
else if (blocked1.up)
7172
{
73+
// console.log('a2');
7274
body2.setBlockedUp();
7375
}
76+
else if (blocked1.down)
77+
{
78+
// console.log('a3');
79+
body2.setBlockedDown();
80+
}
81+
else if (blocked2.down)
82+
{
83+
// console.log('a4');
84+
body1.setBlockedDown();
85+
}
86+
else if (body1Immovable)
87+
{
88+
if (v2 < 0)
89+
{
90+
// console.log('a5');
91+
body2.setBlockedUp();
92+
}
93+
else if (v2 > 0)
94+
{
95+
// console.log('a6');
96+
body2.setBlockedDown();
97+
}
98+
}
99+
else if (body2Immovable)
100+
{
101+
if (v1 < 0)
102+
{
103+
// console.log('a7');
104+
body1.setBlockedUp();
105+
}
106+
else if (v1 > 0)
107+
{
108+
// console.log('a8');
109+
body1.setBlockedDown();
110+
}
111+
}
112+
else
113+
{
114+
console.log('buma', blocked1.up, blocked2.up, blocked1.down, blocked2.down);
115+
}
74116
}
75117
else
76118
{
@@ -79,27 +121,53 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
79121

80122
if (blocked2.down)
81123
{
82-
console.log('b1');
124+
// console.log('b1');
83125
body1.setBlockedDown();
84126
}
85127
else if (blocked1.down)
86128
{
87-
console.log('b2');
129+
// console.log('b2');
88130
body2.setBlockedDown();
89131
}
90132
else if (blocked1.up)
91133
{
92-
console.log('b3');
134+
// console.log('b3');
93135
body2.setBlockedUp();
94136
}
95137
else if (blocked2.up)
96138
{
97-
console.log('b4');
139+
// console.log('b4');
98140
body1.setBlockedUp();
99141
}
142+
else if (body1Immovable)
143+
{
144+
if (v2 < 0)
145+
{
146+
// console.log('b5');
147+
body2.setBlockedUp();
148+
}
149+
else if (v2 > 0)
150+
{
151+
// console.log('b6');
152+
body2.setBlockedDown();
153+
}
154+
}
155+
else if (body2Immovable)
156+
{
157+
if (v1 < 0)
158+
{
159+
// console.log('b7');
160+
body1.setBlockedUp();
161+
}
162+
else if (v1 > 0)
163+
{
164+
// console.log('b8');
165+
body1.setBlockedDown();
166+
}
167+
}
100168
else
101169
{
102-
console.log('bum', blocked1.up, blocked2.up);
170+
console.log('bumb', blocked1.up, blocked2.up, blocked1.down, blocked2.down);
103171
}
104172
}
105173

@@ -110,36 +178,32 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
110178
{
111179
// Neither body is immovable, so they get an equal amount of separation and a new velocity based on mass
112180
// Share the overlap equally if both bodies are unblocked
113-
114-
overlap *= 0.5;
115-
var d1 = body1.getMoveY(-overlap);
116-
var d2 = body2.getMoveY(overlap);
117-
118-
body1.y -= d1;
119-
body2.y += d2;
120-
121-
// body1.y -= body1.getMoveY(overlap);
122-
// body2.y += body2.getMoveY(overlap);
123181

124182
if (faceBottom && blocked2.down)
125183
{
126184
body1.bottom = body2.y;
127-
console.log('a', d1, d2);
185+
// console.log('a');
128186
}
129187
else if (faceTop && blocked1.down)
130188
{
131189
body2.bottom = body1.y;
132-
console.log('b', d1, d2);
190+
// console.log('b');
133191
}
134192
else if (faceBottom && blocked1.up)
135193
{
136194
body2.y = body1.bottom;
137-
console.log('c', d1, d2, body1.bottom, body2.y);
195+
// console.log('c', body1.bottom, body2.y);
138196
}
139197
else if (faceTop && blocked2.up)
140198
{
141199
body1.y = body2.bottom;
142-
console.log('d', d1, d2);
200+
// console.log('d');
201+
}
202+
else
203+
{
204+
overlap *= 0.5;
205+
body1.y -= body1.getMoveY(overlap);
206+
body2.y += body2.getMoveY(overlap);
143207
}
144208

145209
var nv1 = Math.sqrt((v2 * v2 * body2.mass) / body1.mass) * ((v2 > 0) ? 1 : -1);
@@ -152,51 +216,20 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
152216
velocity1.y = avg + nv1 * body1.bounce.y;
153217
velocity2.y = avg + nv2 * body2.bounce.y;
154218
}
155-
156-
157-
/*
158-
if (!body1Immovable && !body2Immovable)
159-
{
160-
// Neither body is immovable, so they get an equal amount of separation and a new velocity based on mass
161-
// Share the overlap equally if both bodies are unblocked
162-
163-
var diff1 = body1.getMoveY(overlap * 0.5);
164-
165-
body1.y -= diff1;
166-
body2.y += body2.getMoveY((overlap - diff1));
167-
168-
// -2 -5 false block vs. mush
169-
// 2 5 true mush vs. block
170-
171-
console.log('p2', diff1, overlap, 'bottom?', overlapBottom);
172-
173-
var nv1 = Math.sqrt((v2 * v2 * body2.mass) / body1.mass) * ((v2 > 0) ? 1 : -1);
174-
var nv2 = Math.sqrt((v1 * v1 * body1.mass) / body2.mass) * ((v1 > 0) ? 1 : -1);
175-
var avg = (nv1 + nv2) * 0.5;
176-
177-
nv1 -= avg;
178-
nv2 -= avg;
179-
180-
velocity1.y = avg + nv1 * body1.bounce.y;
181-
velocity2.y = avg + nv2 * body2.bounce.y;
182-
}
183-
else if (!body1Immovable)
219+
else if (body1Immovable)
184220
{
185-
// Body2 is immovable, but Body1 can move, so it gets all the separation unless blocked
186-
body1.y -= body1.getMoveY(overlap);
187-
188-
velocity1.y = v2 - v1 * body1.bounce.y;
221+
// Body1 is immovable, but Body2 can move, so it gets all the separation
189222

190-
// This is special case code that handles things like horizontal moving platforms you can ride
191-
if (body2.moves)
223+
if (faceBottom)
192224
{
193-
body1.x += body1.getMoveX((body2.deltaX()) * body2.friction.x, true);
225+
body2.y = body1.bottom;
226+
// console.log('a');
227+
}
228+
else
229+
{
230+
body2.bottom = body1.y;
231+
// console.log('b');
194232
}
195-
}
196-
else if (!body2Immovable)
197-
{
198-
// Body1 is immovable, but Body2 can move, so it gets all the separation unless blocked
199-
body2.y += body2.getMoveY(overlap);
200233

201234
velocity2.y = v1 - v2 * body2.bounce.y;
202235

@@ -206,41 +239,29 @@ var SeparateY = function (body1, body2, overlapOnly, bias)
206239
body2.x += body2.getMoveX((body1.deltaX()) * body1.friction.x, true);
207240
}
208241
}
209-
210-
// It's possible both bodies were equally immovable, in which case neither of them have moved
211-
212-
// Set flags
213-
if (overlapBottom)
242+
else if (body2Immovable)
214243
{
215-
// body1 was moving down prior to the collision
216-
body1.setTouchingDown();
217-
body2.setTouchingUp();
244+
// Body2 is immovable, but Body1 can move, so it gets all the separation
218245

219-
if (blocked2.down)
246+
if (faceBottom)
220247
{
221-
body1.setBlockedDown();
248+
body1.bottom = body2.y;
249+
// console.log('a');
222250
}
223-
else if (blocked1.down)
251+
else
224252
{
225-
body2.setBlockedDown();
253+
body1.y = body2.bottom;
254+
// console.log('b');
226255
}
227-
}
228-
else
229-
{
230-
// body1 was moving up prior to the collision
231-
body1.setTouchingUp();
232-
body2.setTouchingDown();
233256

234-
if (blocked2.up)
235-
{
236-
body1.setBlockedUp();
237-
}
238-
else if (blocked1.up)
257+
velocity1.y = v2 - v1 * body1.bounce.y;
258+
259+
// This is special case code that handles things like horizontal moving platforms you can ride
260+
if (body2.moves)
239261
{
240-
body2.setBlockedUp();
262+
body1.x += body1.getMoveX((body2.deltaX()) * body2.friction.x, true);
241263
}
242264
}
243-
*/
244265

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

0 commit comments

Comments
 (0)