45 function TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean; |
45 function TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean; |
46 |
46 |
47 function TestCollisionX(Gear: PGear; Dir: LongInt): boolean; |
47 function TestCollisionX(Gear: PGear; Dir: LongInt): boolean; |
48 function TestCollisionY(Gear: PGear; Dir: LongInt): boolean; |
48 function TestCollisionY(Gear: PGear; Dir: LongInt): boolean; |
49 |
49 |
50 function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean; |
50 function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean; |
51 function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean; |
51 function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean; |
52 |
52 |
53 function calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean; |
53 function TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean; |
|
54 function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean; |
54 |
55 |
55 implementation |
56 implementation |
56 uses uConsts, uLandGraphics, uVariables, uDebug, uGears; |
57 uses uConsts, uLandGraphics, uVariables, uDebug, uGears; |
57 |
58 |
58 type TCollisionEntry = record |
59 type TCollisionEntry = record |
289 exit(false) |
290 exit(false) |
290 end |
291 end |
291 end |
292 end |
292 end; |
293 end; |
293 |
294 |
294 function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean; |
295 function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean; |
295 begin |
296 begin |
296 Gear^.X:= Gear^.X + ShiftX; |
297 Gear^.X:= Gear^.X + ShiftX; |
297 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
298 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
298 TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir); |
299 if withGear then |
|
300 TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir) |
|
301 else TestCollisionXwithXYShift:= TestCollisionX(Gear, Dir); |
299 Gear^.X:= Gear^.X - ShiftX; |
302 Gear^.X:= Gear^.X - ShiftX; |
300 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
303 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
301 end; |
304 end; |
302 function TestCollisionX(Gear: PGear; Dir: LongInt): boolean; |
305 function TestCollisionX(Gear: PGear; Dir: LongInt): boolean; |
303 var x, y, i: LongInt; |
306 var x, y, i: LongInt; |
335 until (x > i); |
338 until (x > i); |
336 end; |
339 end; |
337 TestCollisionY:= false |
340 TestCollisionY:= false |
338 end; |
341 end; |
339 |
342 |
340 function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean; |
343 function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean; |
341 begin |
344 begin |
342 Gear^.X:= Gear^.X + int2hwFloat(ShiftX); |
345 Gear^.X:= Gear^.X + int2hwFloat(ShiftX); |
343 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
346 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY); |
344 TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir); |
347 if withGear then TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir) |
|
348 else TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir); |
345 Gear^.X:= Gear^.X - int2hwFloat(ShiftX); |
349 Gear^.X:= Gear^.X - int2hwFloat(ShiftX); |
346 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
350 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY) |
347 end; |
351 end; |
348 |
352 |
349 |
353 function TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean; |
350 function calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean; |
354 var x, y: LongInt; |
|
355 TestWord: LongWord; |
|
356 begin |
|
357 if landOnly then |
|
358 TestWord:= 255 |
|
359 else |
|
360 TestWord:= 0; |
|
361 |
|
362 if x1 > x2 then |
|
363 begin |
|
364 x := x1; |
|
365 x1 := x2; |
|
366 x2 := x; |
|
367 end; |
|
368 |
|
369 if y1 > y2 then |
|
370 begin |
|
371 y := y1; |
|
372 y1 := y2; |
|
373 y2 := y; |
|
374 end; |
|
375 |
|
376 for y := y1 to y2 do |
|
377 for x := x1 to x2 do |
|
378 if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) |
|
379 and (Land[y, x] > TestWord) then |
|
380 exit(true); |
|
381 |
|
382 TestRectancleForObstacle:= false |
|
383 end; |
|
384 |
|
385 function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean; |
351 var ldx, ldy, rdx, rdy: LongInt; |
386 var ldx, ldy, rdx, rdy: LongInt; |
352 i, j, mx, my, li, ri, jfr, jto, tmpo : ShortInt; |
387 i, j, mx, my, li, ri, jfr, jto, tmpo : ShortInt; |
353 tmpx, tmpy: LongWord; |
388 tmpx, tmpy: LongWord; |
354 dx, dy, s: hwFloat; |
389 dx, dy, s: hwFloat; |
355 offset: Array[0..7,0..1] of ShortInt; |
390 offset: Array[0..7,0..1] of ShortInt; |