|
1 (* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation; version 2 of the License |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
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 |
|
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 *) |
|
18 |
|
19 {$INCLUDE "options.inc"} |
|
20 |
|
21 unit uGearsHandlers; |
|
22 interface |
|
23 |
|
24 uses uTypes; |
|
25 |
|
26 procedure cakeStep(Gear: PGear); |
|
27 |
|
28 implementation |
|
29 |
|
30 uses SDLh, uFloat, uCollisions; |
|
31 |
|
32 const dirs: array[0..3] of TPoint = ((X: 0; Y: -1), (X: 1; Y: 0),(X: 0; Y: 1),(X: -1; Y: 0)); |
|
33 |
|
34 procedure PrevAngle(Gear: PGear; dA: LongInt); inline; |
|
35 begin |
|
36 Gear^.Angle := (LongInt(Gear^.Angle) + 4 - dA) mod 4 |
|
37 end; |
|
38 |
|
39 procedure NextAngle(Gear: PGear; dA: LongInt); inline; |
|
40 begin |
|
41 Gear^.Angle := (LongInt(Gear^.Angle) + 4 + dA) mod 4 |
|
42 end; |
|
43 |
|
44 procedure cakeStep(Gear: PGear); |
|
45 var |
|
46 xx, yy, xxn, yyn: LongInt; |
|
47 dA: LongInt; |
|
48 tdx, tdy: hwFloat; |
|
49 begin |
|
50 dA := hwSign(Gear^.dX); |
|
51 xx := dirs[Gear^.Angle].x; |
|
52 yy := dirs[Gear^.Angle].y; |
|
53 xxn := dirs[(LongInt(Gear^.Angle) + 4 + dA) mod 4].x; |
|
54 yyn := dirs[(LongInt(Gear^.Angle) + 4 + dA) mod 4].y; |
|
55 |
|
56 if (xx = 0) then |
|
57 if TestCollisionYwithGear(Gear, yy) <> 0 then |
|
58 PrevAngle(Gear, dA) |
|
59 else |
|
60 begin |
|
61 Gear^.Tag := 0; |
|
62 Gear^.Y := Gear^.Y + int2hwFloat(yy); |
|
63 if not TestCollisionXwithGear(Gear, xxn) then |
|
64 begin |
|
65 Gear^.X := Gear^.X + int2hwFloat(xxn); |
|
66 NextAngle(Gear, dA) |
|
67 end; |
|
68 end; |
|
69 |
|
70 if (yy = 0) then |
|
71 if TestCollisionXwithGear(Gear, xx) then |
|
72 PrevAngle(Gear, dA) |
|
73 else |
|
74 begin |
|
75 Gear^.Tag := 0; |
|
76 Gear^.X := Gear^.X + int2hwFloat(xx); |
|
77 if TestCollisionYwithGear(Gear, yyn) = 0 then |
|
78 begin |
|
79 Gear^.Y := Gear^.Y + int2hwFloat(yyn); |
|
80 NextAngle(Gear, dA) |
|
81 end; |
|
82 end; |
|
83 end; |
|
84 |
|
85 end. |