author | nemo |
Sun, 26 Aug 2012 10:15:28 -0400 | |
changeset 7609 | 7663a5c614cb |
parent 7608 | 94d071054a23 |
child 7610 | 682e21112867 |
permissions | -rw-r--r-- |
7594 | 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 |
unit uGearsHandlersRope; |
|
21 |
interface |
|
22 |
||
23 |
uses uTypes; |
|
24 |
||
25 |
procedure doStepRope(Gear: PGear); |
|
26 |
||
27 |
implementation |
|
28 |
uses uConsts, uFloat, uCollisions, uVariables, uGearsList, uSound, uGearsUtils, |
|
29 |
uAmmos, uDebug, uUtils, uGearsHedgehog, uGearsRender; |
|
30 |
||
31 |
procedure doStepRopeAfterAttack(Gear: PGear); |
|
32 |
var |
|
33 |
HHGear: PGear; |
|
34 |
begin |
|
35 |
HHGear := Gear^.Hedgehog^.Gear; |
|
36 |
if ((HHGear^.State and gstHHDriven) = 0) |
|
37 |
or (CheckGearDrowning(HHGear)) |
|
38 |
or (TestCollisionYwithGear(HHGear, 1) <> 0) then |
|
39 |
begin |
|
40 |
DeleteGear(Gear); |
|
41 |
isCursorVisible := false; |
|
42 |
ApplyAmmoChanges(HHGear^.Hedgehog^); |
|
43 |
exit |
|
44 |
end; |
|
45 |
||
46 |
HedgehogChAngle(HHGear); |
|
47 |
||
48 |
if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then |
|
49 |
SetLittle(HHGear^.dX); |
|
50 |
||
51 |
if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then |
|
52 |
HHGear^.dY := _0; |
|
53 |
HHGear^.X := HHGear^.X + HHGear^.dX; |
|
54 |
HHGear^.Y := HHGear^.Y + HHGear^.dY; |
|
55 |
HHGear^.dY := HHGear^.dY + cGravity; |
|
56 |
||
57 |
if (GameFlags and gfMoreWind) <> 0 then |
|
58 |
HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density; |
|
59 |
||
60 |
if (Gear^.Message and gmAttack) <> 0 then |
|
61 |
begin |
|
62 |
Gear^.X := HHGear^.X; |
|
63 |
Gear^.Y := HHGear^.Y; |
|
64 |
||
65 |
ApplyAngleBounds(Gear^.Hedgehog^, amRope); |
|
66 |
||
67 |
Gear^.dX := SignAs(AngleSin(HHGear^.Angle), HHGear^.dX); |
|
68 |
Gear^.dY := -AngleCos(HHGear^.Angle); |
|
69 |
Gear^.Friction := _4_5 * cRopePercent; |
|
70 |
Gear^.Elasticity := _0; |
|
71 |
Gear^.State := Gear^.State and (not gsttmpflag); |
|
72 |
Gear^.doStep := @doStepRope; |
|
73 |
end |
|
74 |
end; |
|
75 |
||
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
76 |
procedure unstickHog(Gear, HHGear: PGear); |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
77 |
var i: LongInt; |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
78 |
stuck: Boolean; |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
79 |
begin |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
80 |
if (TestCollisionYwithGear(HHGear, 1) <> 0) and (TestCollisionYwithGear(HHGear, -1) = 0) then |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
81 |
begin |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
82 |
i:= 1; |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
83 |
repeat |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
84 |
begin |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
85 |
inc(i); |
7609 | 86 |
stuck:= TestCollisionYwithGear(HHGear, 1) <> 0; |
87 |
if stuck then HHGear^.Y:= HHGear^.Y-_1 |
|
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
88 |
end |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
89 |
until (i = 8) or not stuck; |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
90 |
// experiment in simulating something the shoppa players apparently expect |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
91 |
if Gear^.Message and gmDown <> 0 then |
7609 | 92 |
begin |
93 |
//HHGear^.dY:= HHGear^.dY / 16; |
|
94 |
HHGear^.dY:= _0; |
|
95 |
HHGear^.dX:= HHGear^.dX * 2 |
|
96 |
end; |
|
7606
adb1198ade36
another shot in the dark. let's assume they expect to control their direction as well. this might be the *wrong* direction...
nemo
parents:
7605
diff
changeset
|
97 |
if Gear^.Message and gmRight <> 0 then |
adb1198ade36
another shot in the dark. let's assume they expect to control their direction as well. this might be the *wrong* direction...
nemo
parents:
7605
diff
changeset
|
98 |
HHGear^.dX.isNegative:= false |
adb1198ade36
another shot in the dark. let's assume they expect to control their direction as well. this might be the *wrong* direction...
nemo
parents:
7605
diff
changeset
|
99 |
else if Gear^.Message and gmLeft <> 0 then |
adb1198ade36
another shot in the dark. let's assume they expect to control their direction as well. this might be the *wrong* direction...
nemo
parents:
7605
diff
changeset
|
100 |
HHGear^.dX.isNegative:= true |
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
101 |
end |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
102 |
else if (TestCollisionYwithGear(HHGear, -1) <> 0) and (TestCollisionYwithGear(HHGear, 1) = 0) then |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
103 |
begin |
7609 | 104 |
i:= 1; |
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
105 |
repeat |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
106 |
begin |
7609 | 107 |
inc(i); |
108 |
stuck:= TestCollisionYwithGear(HHGear, -1) <> 0; |
|
109 |
if stuck then HHGear^.Y:= HHGear^.Y+_1 |
|
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
110 |
end |
7609 | 111 |
until (i = 8) or not stuck; |
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
112 |
if Gear^.Message and gmDown <> 0 then |
7609 | 113 |
begin |
114 |
//HHGear^.dY:= HHGear^.dY / 16; |
|
115 |
HHGear^.dY.QWordValue:= 0; |
|
116 |
HHGear^.dX:= HHGear^.dX * 2 |
|
117 |
end; |
|
7606
adb1198ade36
another shot in the dark. let's assume they expect to control their direction as well. this might be the *wrong* direction...
nemo
parents:
7605
diff
changeset
|
118 |
if Gear^.Message and gmRight <> 0 then |
7609 | 119 |
HHGear^.dX.isNegative:= true |
120 |
else if Gear^.Message and gmLeft <> 0 then |
|
7606
adb1198ade36
another shot in the dark. let's assume they expect to control their direction as well. this might be the *wrong* direction...
nemo
parents:
7605
diff
changeset
|
121 |
HHGear^.dX.isNegative:= false |
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
122 |
end; |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
123 |
if TestCollisionXwithGear(HHGear, 1) and not TestCollisionXwithGear(HHGear, -1) then |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
124 |
begin |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
125 |
i:= 1; |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
126 |
repeat |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
127 |
begin |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
128 |
inc(i); |
7609 | 129 |
stuck:= TestCollisionXwithGear(HHGear, 1); |
130 |
if stuck then HHGear^.X:= HHGear^.X-_1 |
|
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
131 |
end |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
132 |
until (i = 8) or not stuck; |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
133 |
if Gear^.Message and gmDown <> 0 then |
7609 | 134 |
begin |
135 |
//HHGear^.dX:= HHGear^.dX / 16; |
|
136 |
HHGear^.dX.QWordValue:= 0; |
|
137 |
HHGear^.dY:= HHGear^.dY * 2 |
|
138 |
end; |
|
139 |
if Gear^.Message and gmRight <> 0 then |
|
140 |
HHGear^.dX.isNegative:= true |
|
141 |
else if Gear^.Message and gmLeft <> 0 then |
|
142 |
HHGear^.dX.isNegative:= false |
|
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
143 |
end |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
144 |
else if TestCollisionXwithGear(HHGear, -1) and not TestCollisionXwithGear(HHGear, 1) then |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
145 |
begin |
7609 | 146 |
i:= 1; |
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
147 |
repeat |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
148 |
begin |
7609 | 149 |
inc(i); |
150 |
stuck:= TestCollisionXwithGear(HHGear, -1); |
|
151 |
if stuck then HHGear^.X:= HHGear^.X+_1 |
|
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
152 |
end |
7609 | 153 |
until (i = 8) or not stuck; |
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
154 |
if Gear^.Message and gmDown <> 0 then |
7609 | 155 |
begin |
156 |
//HHGear^.dX:= HHGear^.dX / 16; |
|
157 |
HHGear^.dX.QWordValue:= 0; |
|
158 |
HHGear^.dY:= HHGear^.dY * 2 |
|
159 |
end; |
|
160 |
if Gear^.Message and gmRight <> 0 then |
|
161 |
HHGear^.dX.isNegative:= false |
|
162 |
else if Gear^.Message and gmLeft <> 0 then |
|
163 |
HHGear^.dX.isNegative:= true |
|
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
164 |
end |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
165 |
end; |
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
166 |
|
7594 | 167 |
procedure RopeDeleteMe(Gear, HHGear: PGear); |
168 |
begin |
|
169 |
PlaySound(sndRopeRelease); |
|
7602
a620319d377e
Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents:
7601
diff
changeset
|
170 |
HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue div Gear^.stepFreq; |
a620319d377e
Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents:
7601
diff
changeset
|
171 |
HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue div Gear^.stepFreq; |
7594 | 172 |
with HHGear^ do |
173 |
begin |
|
174 |
Message := Message and (not gmAttack); |
|
175 |
State := (State or gstMoving) and (not gstWinner); |
|
176 |
end; |
|
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
177 |
unstickHog(Gear, HHGear); |
7594 | 178 |
DeleteGear(Gear) |
179 |
end; |
|
180 |
||
181 |
procedure RopeWaitCollision(Gear, HHGear: PGear); |
|
182 |
begin |
|
183 |
PlaySound(sndRopeRelease); |
|
184 |
with HHGear^ do |
|
185 |
begin |
|
186 |
Message := Message and (not gmAttack); |
|
187 |
State := State or gstMoving; |
|
188 |
end; |
|
7605
10e88fbb5fdb
hack for shoppa players, take 2. take into account sides, and a guess that a "slide" involves no upward movement
nemo
parents:
7604
diff
changeset
|
189 |
unstickHog(Gear, HHGear); |
7594 | 190 |
RopePoints.Count := 0; |
191 |
Gear^.Elasticity := _0; |
|
7602
a620319d377e
Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents:
7601
diff
changeset
|
192 |
Gear^.doStep := @doStepRopeAfterAttack; |
a620319d377e
Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents:
7601
diff
changeset
|
193 |
HHGear^.dX.QWordValue:= HHGear^.dX.QWordValue div Gear^.stepFreq; |
a620319d377e
Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents:
7601
diff
changeset
|
194 |
HHGear^.dY.QWordValue:= HHGear^.dY.QWordValue div Gear^.stepFreq; |
a620319d377e
Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents:
7601
diff
changeset
|
195 |
Gear^.stepFreq := 1 |
7594 | 196 |
end; |
197 |
||
198 |
procedure doStepRopeWork(Gear: PGear); |
|
199 |
var |
|
200 |
HHGear: PGear; |
|
7595
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
201 |
len, tx, ty, nx, ny, ropeDx, ropeDy, mdX, mdY, t: hwFloat; |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
202 |
lx, ly, cd, i: LongInt; |
7594 | 203 |
haveCollision, |
204 |
haveDivided: boolean; |
|
205 |
||
206 |
begin |
|
207 |
if GameTicks mod 8 <> 0 then exit; |
|
208 |
||
209 |
HHGear := Gear^.Hedgehog^.Gear; |
|
7595
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
210 |
haveCollision:= false; |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
211 |
if (Gear^.Message and gmLeft <> 0) and (not TestCollisionXwithGear(HHGear, -1)) then |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
212 |
HHGear^.dX := HHGear^.dX - _0_0128 |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
213 |
else haveCollision:= true; |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
214 |
|
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
215 |
if (Gear^.Message and gmRight <> 0) and (not TestCollisionXwithGear(HHGear, 1)) then |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
216 |
HHGear^.dX := HHGear^.dX + _0_0128 |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
217 |
else haveCollision:= true; |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
218 |
|
7594 | 219 |
|
220 |
if ((HHGear^.State and gstHHDriven) = 0) |
|
221 |
or (CheckGearDrowning(HHGear)) or (Gear^.PortalCounter <> 0) then |
|
222 |
begin |
|
223 |
RopeDeleteMe(Gear, HHGear); |
|
224 |
exit |
|
225 |
end; |
|
226 |
||
227 |
// vector between hedgehog and rope attaching point |
|
228 |
ropeDx := HHGear^.X - Gear^.X; |
|
229 |
ropeDy := HHGear^.Y - Gear^.Y; |
|
230 |
||
231 |
if TestCollisionYwithGear(HHGear, 1) = 0 then |
|
232 |
begin |
|
233 |
||
234 |
// depending on the rope vector we know which X-side to check for collision |
|
235 |
// in order to find out if the hog can still be moved by gravity |
|
236 |
if ropeDx.isNegative = RopeDy.IsNegative then |
|
237 |
cd:= -1 |
|
238 |
else |
|
239 |
cd:= 1; |
|
240 |
||
241 |
// apply gravity if there is no obstacle |
|
242 |
if not TestCollisionXwithGear(HHGear, cd) then |
|
243 |
HHGear^.dY := HHGear^.dY + cGravity * 64; |
|
244 |
||
245 |
if (GameFlags and gfMoreWind) <> 0 then |
|
246 |
// apply wind if there's no obstacle |
|
247 |
if not TestCollisionXwithGear(HHGear, hwSign(cWindSpeed)) then |
|
248 |
HHGear^.dX := HHGear^.dX + cWindSpeed * 64 / HHGear^.Density; |
|
7595
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
249 |
end |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
250 |
else haveCollision:= true; |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
251 |
|
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
252 |
if ((Gear^.Message and gmDown) <> 0) and (Gear^.Elasticity < Gear^.Friction) then |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
253 |
if not (TestCollisionXwithGear(HHGear, hwSign(ropeDx)) |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
254 |
or (TestCollisionYwithGear(HHGear, hwSign(ropeDy)) <> 0)) then |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
255 |
Gear^.Elasticity := Gear^.Elasticity + _2_4 |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
256 |
else haveCollision:= true; |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
257 |
|
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
258 |
if ((Gear^.Message and gmUp) <> 0) and (Gear^.Elasticity > _30) then |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
259 |
if not (TestCollisionXwithGear(HHGear, -hwSign(ropeDx)) |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
260 |
or (TestCollisionYwithGear(HHGear, -hwSign(ropeDy)) <> 0)) then |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
261 |
Gear^.Elasticity := Gear^.Elasticity - _2_4 |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
262 |
else haveCollision:= true; |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
263 |
|
7604 | 264 |
(* |
265 |
I am not so sure this is useful. Disabling |
|
7595
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
266 |
if haveCollision then |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
267 |
begin |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
268 |
if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) and not TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
269 |
HHGear^.dX.isNegative:= not HHGear^.dX.isNegative; |
bbac3c0f0c68
Hey. How's this? It makes it harder to get stuck in the vertical rope position, prevents the wall trick, and also I think makes it easier to unglue a horizontal rope?
nemo
parents:
7594
diff
changeset
|
270 |
if (TestCollisionYwithGear(HHGear, hwSign(HHGear^.dY)) <> 0) and (TestCollisionYwithGear(HHGear, -hwSign(HHGear^.dY)) = 0) then |
7596 | 271 |
HHGear^.dY.isNegative:= not HHGear^.dY.isNegative; |
7594 | 272 |
end; |
7604 | 273 |
*) |
7594 | 274 |
|
275 |
mdX := ropeDx + HHGear^.dX; |
|
276 |
mdY := ropeDy + HHGear^.dY; |
|
277 |
len := _1 / Distance(mdX, mdY); |
|
278 |
// rope vector plus hedgehog direction vector normalized |
|
279 |
mdX := mdX * len; |
|
280 |
mdY := mdY * len; |
|
281 |
||
282 |
// for visual purposes only |
|
283 |
Gear^.dX := mdX; |
|
284 |
Gear^.dY := mdY; |
|
285 |
||
286 |
///// |
|
287 |
tx := HHGear^.X; |
|
288 |
ty := HHGear^.Y; |
|
289 |
||
290 |
HHGear^.X := Gear^.X + mdX * Gear^.Elasticity; |
|
291 |
HHGear^.Y := Gear^.Y + mdY * Gear^.Elasticity; |
|
292 |
||
293 |
HHGear^.dX := HHGear^.X - tx; |
|
294 |
HHGear^.dY := HHGear^.Y - ty; |
|
295 |
//// |
|
296 |
||
297 |
||
298 |
haveDivided := false; |
|
299 |
// check whether rope needs dividing |
|
300 |
||
301 |
len := Gear^.Elasticity - _5; |
|
302 |
nx := Gear^.X + mdX * len; |
|
303 |
ny := Gear^.Y + mdY * len; |
|
304 |
tx := mdX * _2_4; // should be the same as increase step |
|
305 |
ty := mdY * _2_4; |
|
306 |
||
307 |
while len > _3 do |
|
308 |
begin |
|
309 |
lx := hwRound(nx); |
|
310 |
ly := hwRound(ny); |
|
311 |
if ((ly and LAND_HEIGHT_MASK) = 0) and ((lx and LAND_WIDTH_MASK) = 0) and ((Land[ly, lx] and $FF00) <> 0) then |
|
312 |
begin |
|
313 |
ny := _1 / Distance(ropeDx, ropeDy); |
|
314 |
// old rope pos |
|
315 |
nx := ropeDx * ny; |
|
316 |
ny := ropeDy * ny; |
|
317 |
||
318 |
with RopePoints.ar[RopePoints.Count] do |
|
319 |
begin |
|
320 |
X := Gear^.X; |
|
321 |
Y := Gear^.Y; |
|
322 |
if RopePoints.Count = 0 then |
|
323 |
RopePoints.HookAngle := DxDy2Angle(Gear^.dY, Gear^.dX); |
|
324 |
b := (nx * HHGear^.dY) > (ny * HHGear^.dX); |
|
325 |
dLen := len |
|
326 |
end; |
|
327 |
||
328 |
with RopePoints.rounded[RopePoints.Count] do |
|
329 |
begin |
|
330 |
X := hwRound(Gear^.X); |
|
331 |
Y := hwRound(Gear^.Y); |
|
332 |
end; |
|
333 |
||
334 |
Gear^.X := Gear^.X + nx * len; |
|
335 |
Gear^.Y := Gear^.Y + ny * len; |
|
336 |
inc(RopePoints.Count); |
|
337 |
TryDo(RopePoints.Count <= MAXROPEPOINTS, 'Rope points overflow', true); |
|
338 |
Gear^.Elasticity := Gear^.Elasticity - len; |
|
339 |
Gear^.Friction := Gear^.Friction - len; |
|
340 |
haveDivided := true; |
|
341 |
break |
|
342 |
end; |
|
343 |
nx := nx - tx; |
|
344 |
ny := ny - ty; |
|
345 |
||
346 |
// len := len - _2_4 // should be the same as increase step |
|
347 |
len.QWordValue := len.QWordValue - _2_4.QWordValue; |
|
348 |
end; |
|
349 |
||
350 |
if not haveDivided then |
|
351 |
if RopePoints.Count > 0 then // check whether the last dividing point could be removed |
|
352 |
begin |
|
353 |
tx := RopePoints.ar[Pred(RopePoints.Count)].X; |
|
354 |
ty := RopePoints.ar[Pred(RopePoints.Count)].Y; |
|
355 |
mdX := tx - Gear^.X; |
|
356 |
mdY := ty - Gear^.Y; |
|
357 |
if RopePoints.ar[Pred(RopePoints.Count)].b xor (mdX * (ty - HHGear^.Y) > (tx - HHGear^.X) * mdY) then |
|
358 |
begin |
|
359 |
dec(RopePoints.Count); |
|
360 |
Gear^.X := RopePoints.ar[RopePoints.Count].X; |
|
361 |
Gear^.Y := RopePoints.ar[RopePoints.Count].Y; |
|
362 |
Gear^.Elasticity := Gear^.Elasticity + RopePoints.ar[RopePoints.Count].dLen; |
|
363 |
Gear^.Friction := Gear^.Friction + RopePoints.ar[RopePoints.Count].dLen; |
|
364 |
||
365 |
// restore hog position |
|
366 |
len := _1 / Distance(mdX, mdY); |
|
367 |
mdX := mdX * len; |
|
368 |
mdY := mdY * len; |
|
369 |
||
370 |
HHGear^.X := Gear^.X - mdX * Gear^.Elasticity; |
|
371 |
HHGear^.Y := Gear^.Y - mdY * Gear^.Elasticity; |
|
372 |
end |
|
373 |
end; |
|
374 |
||
375 |
haveCollision := false; |
|
376 |
if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then |
|
377 |
begin |
|
378 |
HHGear^.dX := -_0_6 * HHGear^.dX; |
|
379 |
haveCollision := true |
|
380 |
end; |
|
381 |
if TestCollisionYwithGear(HHGear, hwSign(HHGear^.dY)) <> 0 then |
|
382 |
begin |
|
383 |
HHGear^.dY := -_0_6 * HHGear^.dY; |
|
384 |
haveCollision := true |
|
385 |
end; |
|
386 |
||
387 |
if haveCollision and (Gear^.Message and (gmLeft or gmRight) <> 0) and (Gear^.Message and (gmUp or gmDown) <> 0) then |
|
388 |
begin |
|
389 |
HHGear^.dX := SignAs(hwAbs(HHGear^.dX) + _1_6, HHGear^.dX); |
|
390 |
HHGear^.dY := SignAs(hwAbs(HHGear^.dY) + _1_6, HHGear^.dY) |
|
391 |
end; |
|
392 |
||
393 |
len := hwSqr(HHGear^.dX) + hwSqr(HHGear^.dY); |
|
394 |
if len > _49 then |
|
395 |
begin |
|
396 |
len := _7 / hwSqrt(len); |
|
397 |
HHGear^.dX := HHGear^.dX * len; |
|
398 |
HHGear^.dY := HHGear^.dY * len; |
|
399 |
end; |
|
400 |
||
401 |
haveCollision:= ((hwRound(Gear^.Y) and LAND_HEIGHT_MASK) = 0) and ((hwRound(Gear^.X) and LAND_WIDTH_MASK) = 0) and ((Land[hwRound(Gear^.Y), hwRound(Gear^.X)]) <> 0); |
|
402 |
||
403 |
if not haveCollision then |
|
404 |
begin |
|
405 |
// backup gear location |
|
406 |
tx:= Gear^.X; |
|
407 |
ty:= Gear^.Y; |
|
408 |
||
409 |
if RopePoints.Count > 0 then |
|
410 |
begin |
|
411 |
// set gear location to the remote end of the rope, the attachment point |
|
412 |
Gear^.X:= RopePoints.ar[0].X; |
|
413 |
Gear^.Y:= RopePoints.ar[0].Y; |
|
414 |
end; |
|
415 |
||
416 |
CheckCollision(Gear); |
|
417 |
// if we haven't found any collision yet then check the other side too |
|
418 |
if (Gear^.State and gstCollision) = 0 then |
|
419 |
begin |
|
420 |
Gear^.dX.isNegative:= not Gear^.dX.isNegative; |
|
421 |
Gear^.dY.isNegative:= not Gear^.dY.isNegative; |
|
422 |
CheckCollision(Gear); |
|
423 |
Gear^.dX.isNegative:= not Gear^.dX.isNegative; |
|
424 |
Gear^.dY.isNegative:= not Gear^.dY.isNegative; |
|
425 |
end; |
|
426 |
||
427 |
haveCollision:= (Gear^.State and gstCollision) <> 0; |
|
428 |
||
429 |
// restore gear location |
|
430 |
Gear^.X:= tx; |
|
431 |
Gear^.Y:= ty; |
|
432 |
end; |
|
433 |
||
434 |
// if the attack key is pressed, lose rope contact as well |
|
435 |
if (Gear^.Message and gmAttack) <> 0 then |
|
436 |
haveCollision:= false; |
|
437 |
||
438 |
if not haveCollision then |
|
439 |
begin |
|
440 |
if (Gear^.State and gsttmpFlag) <> 0 then |
|
441 |
begin |
|
442 |
if Gear^.Hedgehog^.CurAmmoType <> amParachute then |
|
443 |
RopeWaitCollision(Gear, HHGear) |
|
444 |
else |
|
445 |
RopeDeleteMe(Gear, HHGear) |
|
446 |
end |
|
447 |
end |
|
448 |
else |
|
449 |
if (Gear^.State and gsttmpFlag) = 0 then |
|
450 |
Gear^.State := Gear^.State or gsttmpFlag; |
|
451 |
end; |
|
452 |
||
453 |
procedure RopeRemoveFromAmmo(Gear, HHGear: PGear); |
|
454 |
begin |
|
455 |
if (Gear^.State and gstAttacked) = 0 then |
|
456 |
begin |
|
457 |
OnUsedAmmo(HHGear^.Hedgehog^); |
|
458 |
Gear^.State := Gear^.State or gstAttacked |
|
459 |
end; |
|
460 |
ApplyAmmoChanges(HHGear^.Hedgehog^) |
|
461 |
end; |
|
462 |
||
463 |
procedure doStepRopeAttach(Gear: PGear); |
|
464 |
var |
|
465 |
HHGear: PGear; |
|
466 |
tx, ty, tt: hwFloat; |
|
467 |
begin |
|
468 |
Gear^.X := Gear^.X - Gear^.dX; |
|
469 |
Gear^.Y := Gear^.Y - Gear^.dY; |
|
470 |
Gear^.Elasticity := Gear^.Elasticity + _1; |
|
471 |
||
472 |
HHGear := Gear^.Hedgehog^.Gear; |
|
473 |
DeleteCI(HHGear); |
|
474 |
||
475 |
if (HHGear^.State and gstMoving) <> 0 then |
|
476 |
begin |
|
477 |
if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then |
|
478 |
SetLittle(HHGear^.dX); |
|
479 |
if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then |
|
480 |
HHGear^.dY := _0; |
|
481 |
||
482 |
HHGear^.X := HHGear^.X + HHGear^.dX; |
|
483 |
Gear^.X := Gear^.X + HHGear^.dX; |
|
484 |
||
485 |
if TestCollisionYwithGear(HHGear, 1) <> 0 then |
|
486 |
begin |
|
487 |
CheckHHDamage(HHGear); |
|
488 |
HHGear^.dY := _0 |
|
489 |
//HHGear^.State:= HHGear^.State and (not (gstHHJumping or gstHHHJump)); |
|
490 |
end |
|
491 |
else |
|
492 |
begin |
|
493 |
HHGear^.Y := HHGear^.Y + HHGear^.dY; |
|
494 |
Gear^.Y := Gear^.Y + HHGear^.dY; |
|
495 |
HHGear^.dY := HHGear^.dY + cGravity; |
|
496 |
if (GameFlags and gfMoreWind) <> 0 then |
|
497 |
HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density |
|
498 |
end; |
|
499 |
||
500 |
tt := Gear^.Elasticity; |
|
501 |
tx := _0; |
|
502 |
ty := _0; |
|
503 |
while tt > _20 do |
|
504 |
begin |
|
505 |
if ((hwRound(Gear^.Y+ty) and LAND_HEIGHT_MASK) = 0) and ((hwRound(Gear^.X+tx) and LAND_WIDTH_MASK) = 0) and ((Land[hwRound(Gear^.Y+ty), hwRound(Gear^.X+tx)] and $FF00) <> 0) then |
|
506 |
begin |
|
507 |
Gear^.X := Gear^.X + tx; |
|
508 |
Gear^.Y := Gear^.Y + ty; |
|
509 |
Gear^.Elasticity := tt; |
|
510 |
Gear^.doStep := @doStepRopeWork; |
|
7602
a620319d377e
Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents:
7601
diff
changeset
|
511 |
Gear^.stepFreq:= 8; |
7594 | 512 |
PlaySound(sndRopeAttach); |
513 |
with HHGear^ do |
|
514 |
begin |
|
515 |
dX.QWordValue:= dX.QWordValue shl 3; |
|
516 |
dY.QWordValue:= dY.QWordValue shl 3; |
|
517 |
State := State and (not (gstAttacking or gstHHJumping or gstHHHJump)); |
|
518 |
Message := Message and (not gmAttack) |
|
519 |
end; |
|
520 |
||
521 |
RopeRemoveFromAmmo(Gear, HHGear); |
|
522 |
||
523 |
tt := _0; |
|
524 |
exit |
|
525 |
end; |
|
526 |
tx := tx + Gear^.dX + Gear^.dX; |
|
527 |
ty := ty + Gear^.dY + Gear^.dY; |
|
528 |
tt := tt - _2; |
|
529 |
end; |
|
530 |
end; |
|
531 |
||
7601 | 532 |
if Gear^.Elasticity < _20 then Gear^.CollisionMask:= $FF00 |
533 |
else Gear^.CollisionMask:= $FF7F; |
|
7594 | 534 |
CheckCollision(Gear); |
535 |
||
536 |
if (Gear^.State and gstCollision) <> 0 then |
|
537 |
if Gear^.Elasticity < _10 then |
|
538 |
Gear^.Elasticity := _10000 |
|
539 |
else |
|
540 |
begin |
|
541 |
Gear^.doStep := @doStepRopeWork; |
|
7602
a620319d377e
Fix throwing things off rope, also make throwing things a bit more generic and gear density dependent (so you can throw mines further, and also throw dynamite a little).
nemo
parents:
7601
diff
changeset
|
542 |
Gear^.stepFreq:= 8; |
7594 | 543 |
PlaySound(sndRopeAttach); |
544 |
with HHGear^ do |
|
545 |
begin |
|
546 |
dX.QWordValue:= dX.QWordValue shl 3; |
|
547 |
dY.QWordValue:= dY.QWordValue shl 3; |
|
548 |
State := State and (not (gstAttacking or gstHHJumping or gstHHHJump)); |
|
549 |
Message := Message and (not gmAttack) |
|
550 |
end; |
|
551 |
||
552 |
RopeRemoveFromAmmo(Gear, HHGear); |
|
553 |
||
554 |
exit |
|
555 |
end; |
|
556 |
||
557 |
if (Gear^.Elasticity > Gear^.Friction) |
|
558 |
or ((Gear^.Message and gmAttack) = 0) |
|
559 |
or ((HHGear^.State and gstHHDriven) = 0) |
|
560 |
or (HHGear^.Damage > 0) then |
|
561 |
begin |
|
562 |
with Gear^.Hedgehog^.Gear^ do |
|
563 |
begin |
|
564 |
State := State and (not gstAttacking); |
|
565 |
Message := Message and (not gmAttack) |
|
566 |
end; |
|
567 |
DeleteGear(Gear); |
|
568 |
exit; |
|
569 |
end; |
|
570 |
if CheckGearDrowning(HHGear) then DeleteGear(Gear) |
|
571 |
end; |
|
572 |
||
573 |
procedure doStepRope(Gear: PGear); |
|
574 |
begin |
|
575 |
Gear^.dX := - Gear^.dX; |
|
576 |
Gear^.dY := - Gear^.dY; |
|
577 |
Gear^.doStep := @doStepRopeAttach; |
|
578 |
PlaySound(sndRopeShot) |
|
579 |
end; |
|
580 |
||
581 |
end. |