author | unc0rr |
Sat, 23 Sep 2006 19:26:07 +0000 | |
changeset 161 | d8870bbf960e |
parent 154 | 5667e6f38704 |
child 162 | 4822f6face35 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
47 | 3 |
* Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*) |
|
33 |
||
34 |
unit uWorld; |
|
35 |
interface |
|
83 | 36 |
uses SDLh, uGears, uConsts; |
4 | 37 |
{$INCLUDE options.inc} |
38 |
const WorldDx: integer = -512; |
|
39 |
WorldDy: integer = -256; |
|
40 |
||
41 |
procedure InitWorld; |
|
42 |
procedure DrawWorld(Lag: integer; Surface: PSDL_Surface); |
|
108 | 43 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
79 | 44 |
procedure MoveCamera; |
4 | 45 |
|
46 |
{$IFDEF COUNTTICKS} |
|
47 |
var cntTicks: LongWord; |
|
48 |
{$ENDIF} |
|
49 |
var FollowGear: PGear = nil; |
|
6 | 50 |
WindBarWidth: integer = 0; |
161 | 51 |
bShowAmmoMenu: boolean = false; |
4 | 52 |
|
53 |
implementation |
|
161 | 54 |
uses uStore, uMisc, uTeams, uIO, uConsole, uKeys; |
4 | 55 |
const RealTicks: Longword = 0; |
56 |
Frames: Longword = 0; |
|
57 |
FPS: Longword = 0; |
|
58 |
CountTicks: Longword = 0; |
|
59 |
prevPoint: TPoint = (X: 0; Y: 0); |
|
161 | 60 |
|
4 | 61 |
type TCaptionStr = record |
83 | 62 |
Surf: PSDL_Surface; |
63 |
StorePos: Longword; |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
95
diff
changeset
|
64 |
Group: TCapGroup; |
4 | 65 |
EndTime: LongWord; |
66 |
end; |
|
67 |
||
68 |
var cWaterSprCount: integer; |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
95
diff
changeset
|
69 |
Captions: array[0..Pred(cMaxCaptions)] of TCaptionStr; |
161 | 70 |
AMxLeft, AMxCurr: integer; |
4 | 71 |
|
72 |
procedure InitWorld; |
|
73 |
begin |
|
74 | 74 |
cWaterSprCount:= 1 + cScreenWidth div (SpritesData[sprWater].Width); |
75 |
cScreenEdgesDist:= Min(cScreenWidth div 4, cScreenHeight div 4); |
|
76 |
SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
|
77 |
prevPoint.X:= cScreenWidth div 2; |
|
78 |
prevPoint.Y:= cScreenHeight div 2; |
|
79 |
WorldDx:= - 1024 + cScreenWidth div 2; |
|
161 | 80 |
WorldDy:= - 512 + cScreenHeight div 2; |
81 |
AMxLeft:= cScreenWidth - 210; |
|
82 |
AMxCurr:= cScreenWidth |
|
83 |
end; |
|
84 |
||
85 |
procedure ShowAmmoMenu(Surface: PSDL_Surface); |
|
86 |
const MENUSPEED = 15; |
|
87 |
var x, y, i, t: integer; |
|
88 |
begin |
|
89 |
if (TurnTimeLeft = 0) or KbdKeyPressed then bShowAmmoMenu:= false; |
|
90 |
if bShowAmmoMenu and (AMxCurr > AMxLeft) then dec(AMxCurr, MENUSPEED); |
|
91 |
if (not bShowAmmoMenu) and (AMxCurr < cScreenWidth) then inc(AMxCurr, MENUSPEED); |
|
92 |
||
93 |
if CurrentTeam = nil then exit; |
|
94 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
|
95 |
begin |
|
96 |
if Ammo = nil then exit; |
|
97 |
x:= AMxCurr; |
|
98 |
y:= cScreenHeight - 40; |
|
99 |
dec(y); |
|
100 |
DrawSprite(sprAMBorders, x, y, 0, Surface); |
|
101 |
dec(y); |
|
102 |
DrawSprite(sprAMBorders, x, y, 1, Surface); |
|
103 |
dec(y, 33); |
|
104 |
DrawSprite(sprAMSlotName, x, y, 0, Surface); |
|
105 |
for i:= cMaxSlotIndex downto 0 do |
|
106 |
if Ammo[i, 0].Count > 0 then |
|
107 |
begin |
|
108 |
dec(y, 33); |
|
109 |
DrawSprite(sprAMSlot, x, y, 0, Surface); |
|
110 |
DrawSprite(sprAMSlotKeys, x + 2, y + 1, i, Surface); |
|
111 |
t:= 0; |
|
112 |
while (t <= cMaxSlotAmmoIndex) and (Ammo[i, t].Count > 0) do |
|
113 |
begin |
|
114 |
DrawSprite(sprAMAmmos, x + t * 33 + 35, y + 1, integer(Ammo[i, t].AmmoType), Surface); |
|
115 |
inc(t) |
|
116 |
end |
|
117 |
end; |
|
118 |
dec(y, 1); |
|
119 |
DrawSprite(sprAMBorders, x, y, 0, Surface) |
|
120 |
end |
|
4 | 121 |
end; |
122 |
||
123 |
procedure DrawWorld(Lag: integer; Surface: PSDL_Surface); |
|
124 |
var i, t: integer; |
|
125 |
r: TSDL_Rect; |
|
126 |
team: PTeam; |
|
107 | 127 |
tdx, tdy: Double; |
80 | 128 |
|
82 | 129 |
procedure DrawRepeated(spr: TSprite; Shift: integer); |
80 | 130 |
var i, w: integer; |
131 |
begin |
|
132 |
w:= SpritesData[spr].Width; |
|
82 | 133 |
i:= Shift mod w; |
80 | 134 |
if i > 0 then dec(i, w); |
135 |
repeat |
|
136 |
DrawSprite(spr, i, WorldDy + 1024 - SpritesData[spr].Height, 0, Surface); |
|
137 |
inc(i, w) |
|
138 |
until i > cScreenWidth |
|
139 |
end; |
|
140 |
||
4 | 141 |
begin |
5 | 142 |
// Sky |
4 | 143 |
inc(RealTicks, Lag); |
109 | 144 |
if WorldDy > 0 then |
4 | 145 |
begin |
109 | 146 |
if WorldDy > cScreenHeight then r.h:= cScreenHeight |
147 |
else r.h:= WorldDy; |
|
4 | 148 |
r.x:= 0; |
149 |
r.y:= 0; |
|
150 |
r.w:= cScreenWidth; |
|
151 |
SDL_FillRect(Surface, @r, cSkyColor) |
|
152 |
end; |
|
5 | 153 |
// background |
82 | 154 |
DrawRepeated(sprSky, WorldDx * 3 div 8); |
155 |
DrawRepeated(sprHorizont, WorldDx * 3 div 5); |
|
4 | 156 |
|
5 | 157 |
// Waves |
4 | 158 |
{$WARNINGS OFF} |
56 | 159 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy - 64, 0, Surface); |
160 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 192) and $FF), cWaterLine + WorldDy - 48, 0, Surface); |
|
4 | 161 |
{$WARNINGS ON} |
162 |
||
163 |
DrawLand(WorldDx, WorldDy, Surface); |
|
5 | 164 |
// Water |
4 | 165 |
r.y:= WorldDy + cWaterLine + 32; |
166 |
if r.y < cScreenHeight then |
|
167 |
begin |
|
23 | 168 |
if r.y < 0 then r.y:= 0; |
4 | 169 |
r.h:= cScreenHeight - r.y; |
170 |
r.x:= 0; |
|
171 |
r.w:= cScreenWidth; |
|
172 |
SDL_FillRect(Surface, @r, cWaterColor) |
|
173 |
end; |
|
174 |
||
175 |
DrawGears(Surface); |
|
176 |
||
95 | 177 |
if CurrentTeam <> nil then |
178 |
begin |
|
179 |
team:= TeamsList; |
|
180 |
while team<>nil do |
|
4 | 181 |
begin |
182 |
for i:= 0 to 7 do |
|
183 |
with team.Hedgehogs[i] do |
|
184 |
if Gear<>nil then |
|
185 |
if Gear.State = 0 then |
|
5 | 186 |
begin |
95 | 187 |
t:= round(Gear.Y) - cHHRadius - 10 + WorldDy; |
188 |
dec(t, HealthTag.h + 2); |
|
189 |
DrawCentered(round(Gear.X) + WorldDx, t, HealthTag, Surface); |
|
190 |
dec(t, NameTag.h + 2); |
|
191 |
DrawCentered(round(Gear.X) + WorldDx, t, NameTag, Surface); |
|
192 |
dec(t, Team.NameTag.h + 2); |
|
193 |
DrawCentered(round(Gear.X) + WorldDx, t, Team.NameTag, Surface) |
|
5 | 194 |
end else // Current hedgehog |
4 | 195 |
begin |
69 | 196 |
if (Gear.State and (gstMoving or gstDrowning or gstFalling)) = 0 then |
4 | 197 |
if (Gear.State and gstHHThinking) <> 0 then |
53 | 198 |
DrawGear(sQuestion, Round(Gear.X) - 10 + WorldDx, Round(Gear.Y) - cHHRadius - 34 + WorldDy, Surface) |
4 | 199 |
else |
69 | 200 |
if ShowCrosshair and ((Gear.State and gstAttacked) = 0) then |
108 | 201 |
DrawCaption(Round(Gear.X + hwSign(Gear.dX) * Sin(Gear.Angle*pi/cMaxAngle)*60) + WorldDx, |
39 | 202 |
Round(Gear.Y - Cos(Gear.Angle*pi/cMaxAngle)*60) + WorldDy - 4, |
4 | 203 |
Team.CrossHairRect, Surface) |
204 |
end; |
|
205 |
team:= team.Next |
|
206 |
end; |
|
95 | 207 |
end; |
208 |
||
4 | 209 |
|
5 | 210 |
// Waves |
4 | 211 |
{$WARNINGS OFF} |
56 | 212 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) + 64) and $FF), cWaterLine + WorldDy - 32, 0, Surface); |
213 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 128) and $FF), cWaterLine + WorldDy - 16, 0, Surface); |
|
214 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy , 0, Surface); |
|
4 | 215 |
{$WARNINGS ON} |
216 |
||
79 | 217 |
// Turn time |
4 | 218 |
if TurnTimeLeft <> 0 then |
219 |
begin |
|
220 |
i:= Succ(Pred(TurnTimeLeft) div 1000); |
|
221 |
if i>99 then t:= 112 |
|
222 |
else if i>9 then t:= 96 |
|
223 |
else t:= 80; |
|
224 |
DrawSprite(sprFrame, t, cScreenHeight - 48, 1, Surface); |
|
225 |
while i > 0 do |
|
226 |
begin |
|
227 |
dec(t, 32); |
|
228 |
DrawSprite(sprBigDigit, t, cScreenHeight - 48, i mod 10, Surface); |
|
229 |
i:= i div 10 |
|
230 |
end; |
|
231 |
DrawSprite(sprFrame, t - 4, cScreenHeight - 48, 0, Surface); |
|
232 |
end; |
|
79 | 233 |
|
234 |
// Attack bar |
|
4 | 235 |
if CurrentTeam <> nil then |
236 |
case AttackBar of |
|
237 |
1: begin |
|
238 |
r:= StuffPoz[sPowerBar]; |
|
239 |
{$WARNINGS OFF} |
|
240 |
r.w:= (CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear.Power * 256) div cPowerDivisor; |
|
241 |
{$WARNINGS ON} |
|
242 |
DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface); |
|
243 |
end; |
|
74 | 244 |
2: with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
245 |
begin |
|
108 | 246 |
tdx:= hwSign(Gear.dX) * Sin(Gear.Angle*pi/cMaxAngle); |
74 | 247 |
tdy:= - Cos(Gear.Angle*pi/cMaxAngle); |
248 |
for i:= (Gear.Power * 24) div cPowerDivisor downto 0 do |
|
75 | 249 |
DrawSprite(sprPower, round(Gear.X + WorldDx + tdx * (24 + i * 2)) - 16, |
250 |
round(Gear.Y + WorldDy + tdy * (24 + i * 2)) - 12, |
|
74 | 251 |
i, Surface) |
252 |
end |
|
4 | 253 |
end; |
254 |
||
5 | 255 |
// Target |
4 | 256 |
if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0, Surface); |
257 |
||
258 |
// Captions |
|
259 |
i:= 0; |
|
260 |
while (i < cMaxCaptions) do |
|
261 |
begin |
|
262 |
with Captions[i] do |
|
83 | 263 |
if EndTime > 0 then |
95 | 264 |
DrawCentered(cScreenWidth div 2, 8 + i * (Surf.h + 2) + cConsoleYAdd, Surf, Surface); |
4 | 265 |
inc(i) |
266 |
end; |
|
267 |
while (Captions[0].EndTime > 0) and (Captions[0].EndTime <= RealTicks) do |
|
268 |
begin |
|
83 | 269 |
SDL_FreeSurface(Captions[0].Surf); |
95 | 270 |
Captions[0].Surf:= nil; |
4 | 271 |
for i:= 1 to Pred(cMaxCaptions) do |
272 |
Captions[Pred(i)]:= Captions[i]; |
|
273 |
Captions[Pred(cMaxCaptions)].EndTime:= 0 |
|
274 |
end; |
|
275 |
||
47 | 276 |
// Teams Healths |
277 |
team:= TeamsList; |
|
278 |
while team <> nil do |
|
279 |
begin |
|
95 | 280 |
r.x:= cScreenWidth div 2 - team.NameTag.w - 3; |
281 |
r.y:= team.DrawHealthY; |
|
282 |
r.w:= team.NameTag.w; |
|
283 |
r.h:= team.NameTag.h; |
|
284 |
SDL_UpperBlit(team.NameTag, nil, Surface, @r); |
|
47 | 285 |
r:= team.HealthRect; |
146 | 286 |
r.w:= 2 + team.TeamHealthBarWidth; |
49 | 287 |
DrawFromStoreRect(cScreenWidth div 2, |
288 |
Team.DrawHealthY, |
|
47 | 289 |
@r, Surface); |
83 | 290 |
inc(r.x, cTeamHealthWidth + 2); |
291 |
r.w:= 3; |
|
146 | 292 |
DrawFromStoreRect(cScreenWidth div 2 + team.TeamHealthBarWidth + 2, |
49 | 293 |
Team.DrawHealthY, |
47 | 294 |
@r, Surface); |
295 |
team:= team.Next |
|
296 |
end; |
|
297 |
||
5 | 298 |
// Lag alert |
4 | 299 |
if isInLag then DrawSprite(sprLag, 32, 32 + cConsoleYAdd, (RealTicks shr 7) mod 7, Surface); |
300 |
||
5 | 301 |
// Wind bar |
302 |
DrawGear(sWindBar, cScreenWidth - 180, cScreenHeight - 30, Surface); |
|
6 | 303 |
if WindBarWidth > 0 then |
5 | 304 |
begin |
305 |
with StuffPoz[sWindR] do |
|
306 |
begin |
|
6 | 307 |
{$WARNINGS OFF} |
5 | 308 |
r.x:= x + 8 - (RealTicks shr 6) mod 8; |
6 | 309 |
{$WARNINGS ON} |
5 | 310 |
r.y:= y; |
6 | 311 |
r.w:= WindBarWidth; |
5 | 312 |
r.h:= 13; |
313 |
end; |
|
314 |
DrawSpriteFromRect(r, cScreenWidth - 103, cScreenHeight - 28, 13, 0, Surface); |
|
315 |
end else |
|
6 | 316 |
if WindBarWidth < 0 then |
5 | 317 |
begin |
318 |
with StuffPoz[sWindL] do |
|
319 |
begin |
|
6 | 320 |
{$WARNINGS OFF} |
321 |
r.x:= x + (WindBarWidth + RealTicks shr 6) mod 8; |
|
322 |
{$WARNINGS ON} |
|
5 | 323 |
r.y:= y; |
6 | 324 |
r.w:= - WindBarWidth; |
5 | 325 |
r.h:= 13; |
326 |
end; |
|
6 | 327 |
DrawSpriteFromRect(r, cScreenWidth - 106 + WindBarWidth, cScreenHeight - 28, 13, 0, Surface); |
5 | 328 |
end; |
329 |
||
161 | 330 |
// AmmoMenu |
331 |
if (AMxCurr < cScreenWidth) or bShowAmmoMenu then ShowAmmoMenu(Surface); |
|
332 |
||
5 | 333 |
// Cursor |
4 | 334 |
if isCursorVisible then DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface); |
335 |
||
336 |
{$IFDEF COUNTTICKS} |
|
337 |
DXOutText(10, 10, fnt16, inttostr(cntTicks), Surface); |
|
338 |
{$ENDIF} |
|
339 |
||
340 |
inc(Frames); |
|
341 |
inc(CountTicks, Lag); |
|
342 |
if CountTicks >= 1000 then |
|
343 |
begin |
|
344 |
FPS:= Frames; |
|
345 |
Frames:= 0; |
|
346 |
CountTicks:= 0; |
|
347 |
end; |
|
348 |
if cShowFPS then DXOutText(cScreenWidth - 50, 10, fnt16, inttostr(FPS) + ' fps', Surface) |
|
349 |
end; |
|
350 |
||
108 | 351 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
4 | 352 |
var i, t, m, k: LongWord; |
353 |
begin |
|
83 | 354 |
if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s); |
4 | 355 |
i:= 0; |
83 | 356 |
while (i < cMaxCaptions) and (Captions[i].Group <> Group) do inc(i); |
4 | 357 |
if i < cMaxCaptions then |
358 |
begin |
|
95 | 359 |
SDL_FreeSurface(Captions[i].Surf); |
4 | 360 |
while (i < Pred(cMaxCaptions)) do |
361 |
begin |
|
362 |
Captions[i]:= Captions[Succ(i)]; |
|
363 |
inc(i) |
|
364 |
end; |
|
365 |
Captions[Pred(cMaxCaptions)].EndTime:= 0 |
|
366 |
end; |
|
367 |
||
368 |
if Captions[Pred(cMaxCaptions)].EndTime > 0 then |
|
369 |
begin |
|
95 | 370 |
SDL_FreeSurface(Captions[0].Surf); |
4 | 371 |
m:= Pred(cMaxCaptions); |
372 |
for i:= 1 to m do |
|
373 |
Captions[Pred(i)]:= Captions[i]; |
|
374 |
Captions[m].EndTime:= 0 |
|
375 |
end else |
|
376 |
begin |
|
377 |
m:= 0; |
|
378 |
while (m < cMaxCaptions)and(Captions[m].EndTime > 0) do inc(m) |
|
379 |
end; |
|
380 |
||
381 |
k:= 0; |
|
382 |
for i:= 0 to Pred(cMaxCaptions) do |
|
383 |
for t:= 0 to Pred(cMaxCaptions) do |
|
83 | 384 |
if (Captions[t].EndTime > 0) and (Captions[t].StorePos = k) then inc(k); |
4 | 385 |
|
95 | 386 |
Captions[m].Surf:= RenderString(s, Color, fntBig); |
4 | 387 |
Captions[m].StorePos:= k; |
388 |
Captions[m].Group:= Group; |
|
389 |
Captions[m].EndTime:= RealTicks + 1200 |
|
390 |
end; |
|
391 |
||
79 | 392 |
procedure MoveCamera; |
4 | 393 |
const PrevSentPointTime: LongWord = 0; |
394 |
begin |
|
395 |
if not (CurrentTeam.ExtDriven and isCursorVisible) then SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y); |
|
396 |
if (FollowGear <> nil) then |
|
57 | 397 |
if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then |
4 | 398 |
begin |
399 |
FollowGear:= nil; |
|
400 |
exit |
|
401 |
end |
|
402 |
else begin |
|
108 | 403 |
CursorPoint.x:= (CursorPoint.x * 7 + (round(FollowGear.X + hwSign(FollowGear.dX) * 100) + WorldDx)) div 8; |
71 | 404 |
CursorPoint.y:= (CursorPoint.y * 7 + (round(FollowGear.Y) + WorldDy)) div 8 |
4 | 405 |
end; |
406 |
||
407 |
if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit; |
|
408 |
||
409 |
if isCursorVisible then |
|
410 |
begin |
|
411 |
if (not CurrentTeam.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then |
|
412 |
begin |
|
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
146
diff
changeset
|
413 |
SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy); |
4 | 414 |
PrevSentPointTime:= GameTicks |
415 |
end; |
|
416 |
end; |
|
417 |
if isCursorVisible or (FollowGear <> nil) then |
|
418 |
begin |
|
419 |
if CursorPoint.X < cScreenEdgesDist then |
|
420 |
begin |
|
421 |
WorldDx:= WorldDx - CursorPoint.X + cScreenEdgesDist; |
|
422 |
CursorPoint.X:= cScreenEdgesDist |
|
423 |
end else |
|
424 |
if CursorPoint.X > cScreenWidth - cScreenEdgesDist then |
|
425 |
begin |
|
426 |
WorldDx:= WorldDx - CursorPoint.X + cScreenWidth - cScreenEdgesDist; |
|
427 |
CursorPoint.X:= cScreenWidth - cScreenEdgesDist |
|
428 |
end; |
|
429 |
if CursorPoint.Y < cScreenEdgesDist then |
|
430 |
begin |
|
431 |
WorldDy:= WorldDy - CursorPoint.Y + cScreenEdgesDist; |
|
432 |
CursorPoint.Y:= cScreenEdgesDist |
|
433 |
end else |
|
434 |
if CursorPoint.Y > cScreenHeight - cScreenEdgesDist then |
|
435 |
begin |
|
436 |
WorldDy:= WorldDy - CursorPoint.Y + cScreenHeight - cScreenEdgesDist; |
|
437 |
CursorPoint.Y:= cScreenHeight - cScreenEdgesDist |
|
438 |
end; |
|
439 |
end else |
|
440 |
begin |
|
70 | 441 |
WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; |
442 |
WorldDy:= WorldDy - CursorPoint.Y + prevPoint.Y; |
|
4 | 443 |
CursorPoint.X:= (cScreenWidth shr 1); |
444 |
CursorPoint.Y:= (cScreenHeight shr 1); |
|
445 |
end; |
|
446 |
SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
|
447 |
prevPoint:= CursorPoint; |
|
75 | 448 |
if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater; |
4 | 449 |
if WorldDy > 2048 then WorldDy:= 2048; |
450 |
if WorldDx < -2048 then WorldDx:= -2048; |
|
451 |
if WorldDx > cScreenWidth then WorldDx:= cScreenWidth; |
|
452 |
end; |
|
453 |
||
454 |
initialization |
|
455 |
FillChar(Captions, sizeof(Captions), 0) |
|
456 |
||
457 |
end. |