319 |
319 |
320 function calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean; |
320 function calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean; |
321 var ldx, ldy, rdx, rdy: LongInt; |
321 var ldx, ldy, rdx, rdy: LongInt; |
322 i, j, mx, my, li, ri, jfr, jto, tmpo : ShortInt; |
322 i, j, mx, my, li, ri, jfr, jto, tmpo : ShortInt; |
323 tmpx, tmpy: LongWord; |
323 tmpx, tmpy: LongWord; |
324 dx, dy: hwFloat; |
324 dx, dy, s: hwFloat; |
325 offset: Array[0..7,0..1] of ShortInt; |
325 offset: Array[0..7,0..1] of ShortInt; |
326 |
326 |
327 begin |
327 begin |
328 dx:= Gear^.dX; |
328 dx:= Gear^.dX; |
329 dy:= Gear^.dY; |
329 dy:= Gear^.dY; |
330 |
330 |
331 // we start searching from the direction the gear center is at |
331 // we start searching from the direction the gear came from |
|
332 if (dx.QWordValue > _0_995.QWordValue ) |
|
333 or (dy.QWordValue > _0_995.QWordValue ) then |
|
334 begin // scale |
|
335 s := _1 / Distance(dx,dy); |
|
336 dx := s * dx; |
|
337 dy := s * dy; |
|
338 end; |
|
339 |
332 mx:= hwRound(Gear^.X-dx) - hwRound(Gear^.X); |
340 mx:= hwRound(Gear^.X-dx) - hwRound(Gear^.X); |
333 my:= hwRound(Gear^.Y-dy) - hwRound(Gear^.Y); |
341 my:= hwRound(Gear^.Y-dy) - hwRound(Gear^.Y); |
334 |
342 |
335 li:= -1; |
343 li:= -1; |
336 ri:= -1; |
344 ri:= -1; |
337 |
345 |
338 // go around collision pixel, checking for first/last collisions |
346 // go around collision pixel, checking for first/last collisions |
339 // this will determinate what angles will be tried to crawl along |
347 // this will determinate what angles will be tried to crawl along |
340 for i:= 0 to 7 do |
348 for i:= 0 to 7 do |
341 begin |
349 begin |
342 offset[i,0]:= mx; |
350 offset[i,0]:= mx; |
343 offset[i,1]:= my; |
351 offset[i,1]:= my; |
344 |
352 |
345 tmpx:= collisionX + mx; |
353 tmpx:= collisionX + mx; |
346 tmpy:= collisionY + my; |
354 tmpy:= collisionY + my; |
347 |
355 |
348 if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) then |
356 if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK) = 0) then |
349 if (Land[tmpy,tmpx] > TestWord) then |
357 if (Land[tmpy,tmpx] > TestWord) then |
350 begin |
358 begin |
351 // remember the index belonging to the first and last collision (if in 1st half) |
359 // remember the index belonging to the first and last collision (if in 1st half) |
352 if (i <> 0) then |
360 if (i <> 0) then |
353 begin |
361 begin |