13 * |
13 * |
14 * You should have received a copy of the GNU General Public License |
14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software |
15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
17 *) |
17 *) |
|
18 |
|
19 procedure doStepPerPixel(Gear: PGear; step: TGearStepProcedure; onlyCheckIfChanged: boolean); |
|
20 var |
|
21 dX, dY, sX, sY: hwFloat; |
|
22 i, steps: LongWord; |
|
23 caller: TGearStepProcedure; |
|
24 begin |
|
25 dX:= Gear^.dX; |
|
26 dY:= Gear^.dY; |
|
27 steps:= max(abs(hwRound(Gear^.X+dX)-hwRound(Gear^.X)), abs(hwRound(Gear^.Y+dY)-hwRound(Gear^.Y))); |
|
28 |
|
29 // Gear is still on the same Pixel it was before |
|
30 if steps < 1 then |
|
31 begin |
|
32 if onlyCheckIfChanged then |
|
33 begin |
|
34 Gear^.X := Gear^.X + dX; |
|
35 Gear^.Y := Gear^.Y + dY; |
|
36 EXIT; |
|
37 end |
|
38 else |
|
39 steps := 1; |
|
40 end; |
|
41 |
|
42 if steps > 1 then |
|
43 begin |
|
44 sX:= dX / steps; |
|
45 sY:= dY / steps; |
|
46 end |
|
47 else |
|
48 begin |
|
49 sX:= dX; |
|
50 sY:= dY; |
|
51 end; |
|
52 |
|
53 caller:= Gear^.doStep; |
|
54 |
|
55 for i:= 1 to steps do |
|
56 begin |
|
57 Gear^.X := Gear^.X + sX; |
|
58 Gear^.Y := Gear^.Y + sY; |
|
59 step(Gear); |
|
60 if (Gear^.doStep <> caller) |
|
61 or ((Gear^.State and gstCollision) <> 0) |
|
62 or ((Gear^.State and gstMoving) = 0) then |
|
63 break; |
|
64 end; |
|
65 end; |
18 |
66 |
19 procedure makeHogsWorry(x, y: hwFloat; r: LongInt); |
67 procedure makeHogsWorry(x, y: hwFloat; r: LongInt); |
20 var |
68 var |
21 gi: PGear; |
69 gi: PGear; |
22 d: LongInt; |
70 d: LongInt; |
3291 iterator^.dY := s * iterator^.dX; |
3339 iterator^.dY := s * iterator^.dX; |
3292 end; |
3340 end; |
3293 end; |
3341 end; |
3294 end; |
3342 end; |
3295 |
3343 |
3296 procedure doStepMovingPortal(Gear: PGear); |
3344 procedure doStepMovingPortal_real(Gear: PGear); |
3297 var |
3345 var |
3298 x, y, tx, ty: LongInt; |
3346 x, y, tx, ty: LongInt; |
3299 //, bx, by, tangle: LongInt; |
|
3300 s: hwFloat; |
3347 s: hwFloat; |
3301 |
3348 |
3302 procedure loadNewPortalBall(oldPortal: PGear; destroyGear: Boolean); |
3349 procedure loadNewPortalBall(oldPortal: PGear; destroyGear: Boolean); |
3303 var |
3350 var |
3304 flags: LongWord; |
3351 flags: LongWord; |
3320 |
3367 |
3321 if destroyGear then oldPortal^.Timer:= 0; |
3368 if destroyGear then oldPortal^.Timer:= 0; |
3322 end; |
3369 end; |
3323 |
3370 |
3324 begin |
3371 begin |
3325 if (Gear^.Timer < 1) |
|
3326 or (PHedgehog(Gear^.Hedgehog) <> CurrentHedgehog) then |
|
3327 begin |
|
3328 deleteGear(Gear); |
|
3329 EXIT; |
|
3330 end; |
|
3331 |
|
3332 doPortalColorSwitch(); |
|
3333 |
|
3334 Gear^.X := Gear^.X + Gear^.dX; |
|
3335 Gear^.Y := Gear^.Y + Gear^.dY; |
|
3336 x := hwRound(Gear^.X); |
3372 x := hwRound(Gear^.X); |
3337 y := hwRound(Gear^.Y); |
3373 y := hwRound(Gear^.Y); |
3338 tx := 0; |
3374 tx := 0; |
3339 ty := 0; |
3375 ty := 0; |
3340 // avoid compiler hints |
3376 // avoid compiler hints |
3341 |
3377 |
3342 if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] > 255) then |
3378 if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] > 255) then |
3343 begin |
3379 begin |
|
3380 Gear^.State := Gear^.State or gstCollision; |
|
3381 Gear^.State := Gear^.State and not gstMoving; |
3344 if not calcSlopeTangent(Gear, x, y, tx, ty, 255) |
3382 if not calcSlopeTangent(Gear, x, y, tx, ty, 255) |
3345 or (DistanceI(tx,ty) < _12) then // reject shots at too irregular terrain |
3383 or (DistanceI(tx,ty) < _12) then // reject shots at too irregular terrain |
3346 begin |
3384 begin |
3347 loadNewPortalBall(Gear, true); |
3385 loadNewPortalBall(Gear, true); |
3348 EXIT; |
3386 EXIT; |
3369 loadNewPortalBall(Gear, true); |
3407 loadNewPortalBall(Gear, true); |
3370 end |
3408 end |
3371 else if (y > cWaterLine) or (y < -LAND_WIDTH) |
3409 else if (y > cWaterLine) or (y < -LAND_WIDTH) |
3372 or (x > 2*LAND_WIDTH) or (x < -LAND_WIDTH) then |
3410 or (x > 2*LAND_WIDTH) or (x < -LAND_WIDTH) then |
3373 loadNewPortalBall(Gear, true); |
3411 loadNewPortalBall(Gear, true); |
|
3412 end; |
|
3413 |
|
3414 procedure doStepMovingPortal(Gear: PGear); |
|
3415 begin |
|
3416 doPortalColorSwitch(); |
|
3417 doStepPerPixel(Gear, @doStepMovingPortal_real, true); |
|
3418 if (Gear^.Timer < 1) |
|
3419 or (PHedgehog(Gear^.Hedgehog) <> CurrentHedgehog) then |
|
3420 deleteGear(Gear); |
3374 end; |
3421 end; |
3375 |
3422 |
3376 procedure doStepPortalShot(newPortal: PGear); |
3423 procedure doStepPortalShot(newPortal: PGear); |
3377 var |
3424 var |
3378 iterator: PGear; |
3425 iterator: PGear; |
3420 end; |
3467 end; |
3421 iterator^.PortalCounter:= 0; |
3468 iterator^.PortalCounter:= 0; |
3422 iterator := iterator^.NextGear |
3469 iterator := iterator^.NextGear |
3423 end; |
3470 end; |
3424 end; |
3471 end; |
|
3472 newPortal^.State := newPortal^.State and not gstCollision; |
|
3473 newPortal^.State := newPortal^.State or gstMoving; |
3425 newPortal^.doStep := @doStepMovingPortal; |
3474 newPortal^.doStep := @doStepMovingPortal; |
3426 end; |
3475 end; |
3427 |
3476 |
3428 procedure doStepPiano(Gear: PGear); |
3477 procedure doStepPiano(Gear: PGear); |
3429 var |
3478 var |