author | unc0rr |
Wed, 29 Nov 2006 15:47:32 +0000 | |
changeset 284 | 22ce72bd637f |
parent 282 | b1e3387389b6 |
child 292 | 0ca921ca7557 |
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 |
* |
183 | 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 |
|
4 | 8 |
* |
183 | 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. |
|
4 | 13 |
* |
183 | 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 |
|
4 | 17 |
*) |
18 |
||
19 |
unit uWorld; |
|
20 |
interface |
|
83 | 21 |
uses SDLh, uGears, uConsts; |
4 | 22 |
{$INCLUDE options.inc} |
23 |
const WorldDx: integer = -512; |
|
24 |
WorldDy: integer = -256; |
|
25 |
||
26 |
procedure InitWorld; |
|
27 |
procedure DrawWorld(Lag: integer; Surface: PSDL_Surface); |
|
108 | 28 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
4 | 29 |
|
30 |
{$IFDEF COUNTTICKS} |
|
31 |
var cntTicks: LongWord; |
|
32 |
{$ENDIF} |
|
33 |
var FollowGear: PGear = nil; |
|
6 | 34 |
WindBarWidth: integer = 0; |
161 | 35 |
bShowAmmoMenu: boolean = false; |
162 | 36 |
bSelected: boolean = false; |
176 | 37 |
bShowFinger: boolean = false; |
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
183
diff
changeset
|
38 |
Frames: Longword = 0; |
4 | 39 |
|
40 |
implementation |
|
174 | 41 |
uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound; |
4 | 42 |
const RealTicks: Longword = 0; |
43 |
FPS: Longword = 0; |
|
44 |
CountTicks: Longword = 0; |
|
174 | 45 |
SoundTimerTicks: Longword = 0; |
4 | 46 |
prevPoint: TPoint = (X: 0; Y: 0); |
161 | 47 |
|
4 | 48 |
type TCaptionStr = record |
83 | 49 |
Surf: PSDL_Surface; |
4 | 50 |
EndTime: LongWord; |
51 |
end; |
|
52 |
||
53 |
var cWaterSprCount: integer; |
|
175 | 54 |
Captions: array[TCapGroup] of TCaptionStr; |
162 | 55 |
AMxLeft, AMxCurr, SlotsNum: integer; |
4 | 56 |
|
57 |
procedure InitWorld; |
|
58 |
begin |
|
74 | 59 |
cWaterSprCount:= 1 + cScreenWidth div (SpritesData[sprWater].Width); |
284 | 60 |
cGearScrEdgesDist:= Min(cScreenWidth div 2 - 100, cScreenHeight div 2 - 50); |
74 | 61 |
SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
62 |
prevPoint.X:= cScreenWidth div 2; |
|
63 |
prevPoint.Y:= cScreenHeight div 2; |
|
64 |
WorldDx:= - 1024 + cScreenWidth div 2; |
|
161 | 65 |
WorldDy:= - 512 + cScreenHeight div 2; |
66 |
AMxLeft:= cScreenWidth - 210; |
|
67 |
AMxCurr:= cScreenWidth |
|
68 |
end; |
|
69 |
||
70 |
procedure ShowAmmoMenu(Surface: PSDL_Surface); |
|
71 |
const MENUSPEED = 15; |
|
72 |
var x, y, i, t: integer; |
|
162 | 73 |
Slot, Pos: integer; |
161 | 74 |
begin |
75 |
if (TurnTimeLeft = 0) or KbdKeyPressed then bShowAmmoMenu:= false; |
|
165 | 76 |
if bShowAmmoMenu then |
77 |
begin |
|
78 |
if AMxCurr = cScreenWidth then prevPoint.X:= 0; |
|
79 |
if AMxCurr > AMxLeft then dec(AMxCurr, MENUSPEED); |
|
80 |
end else |
|
81 |
begin |
|
82 |
if AMxCurr = AMxLeft then |
|
83 |
begin |
|
84 |
CursorPoint.X:= cScreenWidth div 2; |
|
85 |
CursorPoint.Y:= cScreenHeight div 2; |
|
86 |
prevPoint:= CursorPoint; |
|
87 |
SDL_WarpMouse(CursorPoint.X, CursorPoint.Y) |
|
88 |
end; |
|
89 |
if AMxCurr < cScreenWidth then inc(AMxCurr, MENUSPEED); |
|
90 |
end; |
|
161 | 91 |
|
92 |
if CurrentTeam = nil then exit; |
|
162 | 93 |
Slot:= 0; |
94 |
Pos:= -1; |
|
161 | 95 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
96 |
begin |
|
97 |
if Ammo = nil then exit; |
|
162 | 98 |
SlotsNum:= 0; |
161 | 99 |
x:= AMxCurr; |
100 |
y:= cScreenHeight - 40; |
|
101 |
dec(y); |
|
102 |
DrawSprite(sprAMBorders, x, y, 0, Surface); |
|
103 |
dec(y); |
|
104 |
DrawSprite(sprAMBorders, x, y, 1, Surface); |
|
105 |
dec(y, 33); |
|
106 |
DrawSprite(sprAMSlotName, x, y, 0, Surface); |
|
107 |
for i:= cMaxSlotIndex downto 0 do |
|
108 |
if Ammo[i, 0].Count > 0 then |
|
109 |
begin |
|
162 | 110 |
if (CursorPoint.Y >= y - 33) and (CursorPoint.Y < y) then Slot:= i; |
161 | 111 |
dec(y, 33); |
162 | 112 |
inc(SlotsNum); |
161 | 113 |
DrawSprite(sprAMSlot, x, y, 0, Surface); |
114 |
DrawSprite(sprAMSlotKeys, x + 2, y + 1, i, Surface); |
|
115 |
t:= 0; |
|
116 |
while (t <= cMaxSlotAmmoIndex) and (Ammo[i, t].Count > 0) do |
|
117 |
begin |
|
118 |
DrawSprite(sprAMAmmos, x + t * 33 + 35, y + 1, integer(Ammo[i, t].AmmoType), Surface); |
|
162 | 119 |
if (Slot = i) and (CursorPoint.X >= x + t * 33 + 35) and (CursorPoint.X < x + t * 33 + 68) then |
120 |
begin |
|
121 |
DrawSprite(sprAMSelection, x + t * 33 + 35, y + 1, 0, Surface); |
|
122 |
Pos:= t; |
|
123 |
end; |
|
161 | 124 |
inc(t) |
125 |
end |
|
126 |
end; |
|
127 |
dec(y, 1); |
|
162 | 128 |
DrawSprite(sprAMBorders, x, y, 0, Surface); |
129 |
||
130 |
if (Pos >= 0) then |
|
131 |
if Ammo[Slot, Pos].Count > 0 then |
|
132 |
begin |
|
133 |
DXOutText(AMxCurr + 10, cScreenHeight - 68, fnt16, trAmmo[Ammoz[Ammo[Slot, Pos].AmmoType].NameId], Surface); |
|
134 |
if Ammo[Slot, Pos].Count < 10 then |
|
135 |
DXOutText(AMxCurr + 175, cScreenHeight - 68, fnt16, chr(Ammo[Slot, Pos].Count + 48) + 'x', Surface); |
|
136 |
if bSelected then |
|
137 |
begin |
|
165 | 138 |
bShowAmmoMenu:= false; |
139 |
SetWeapon(Ammo[Slot, Pos].AmmoType); |
|
140 |
bSelected:= false; |
|
141 |
exit |
|
162 | 142 |
end; |
143 |
end; |
|
144 |
end; |
|
145 |
||
146 |
bSelected:= false; |
|
165 | 147 |
if AMxLeft = AMxCurr then DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface) |
4 | 148 |
end; |
149 |
||
162 | 150 |
procedure MoveCamera; forward; |
151 |
||
4 | 152 |
procedure DrawWorld(Lag: integer; Surface: PSDL_Surface); |
153 |
var i, t: integer; |
|
154 |
r: TSDL_Rect; |
|
155 |
team: PTeam; |
|
107 | 156 |
tdx, tdy: Double; |
175 | 157 |
grp: TCapGroup; |
174 | 158 |
s: string[15]; |
80 | 159 |
|
82 | 160 |
procedure DrawRepeated(spr: TSprite; Shift: integer); |
80 | 161 |
var i, w: integer; |
162 |
begin |
|
163 |
w:= SpritesData[spr].Width; |
|
82 | 164 |
i:= Shift mod w; |
80 | 165 |
if i > 0 then dec(i, w); |
166 |
repeat |
|
167 |
DrawSprite(spr, i, WorldDy + 1024 - SpritesData[spr].Height, 0, Surface); |
|
168 |
inc(i, w) |
|
169 |
until i > cScreenWidth |
|
170 |
end; |
|
171 |
||
4 | 172 |
begin |
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
244
diff
changeset
|
173 |
if not isPaused then MoveCamera; |
162 | 174 |
|
5 | 175 |
// Sky |
4 | 176 |
inc(RealTicks, Lag); |
109 | 177 |
if WorldDy > 0 then |
4 | 178 |
begin |
109 | 179 |
if WorldDy > cScreenHeight then r.h:= cScreenHeight |
180 |
else r.h:= WorldDy; |
|
4 | 181 |
r.x:= 0; |
182 |
r.y:= 0; |
|
183 |
r.w:= cScreenWidth; |
|
184 |
SDL_FillRect(Surface, @r, cSkyColor) |
|
185 |
end; |
|
5 | 186 |
// background |
82 | 187 |
DrawRepeated(sprSky, WorldDx * 3 div 8); |
188 |
DrawRepeated(sprHorizont, WorldDx * 3 div 5); |
|
4 | 189 |
|
5 | 190 |
// Waves |
4 | 191 |
{$WARNINGS OFF} |
56 | 192 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy - 64, 0, Surface); |
193 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 192) and $FF), cWaterLine + WorldDy - 48, 0, Surface); |
|
4 | 194 |
{$WARNINGS ON} |
195 |
||
196 |
DrawLand(WorldDx, WorldDy, Surface); |
|
5 | 197 |
// Water |
4 | 198 |
r.y:= WorldDy + cWaterLine + 32; |
199 |
if r.y < cScreenHeight then |
|
200 |
begin |
|
23 | 201 |
if r.y < 0 then r.y:= 0; |
4 | 202 |
r.h:= cScreenHeight - r.y; |
203 |
r.x:= 0; |
|
204 |
r.w:= cScreenWidth; |
|
205 |
SDL_FillRect(Surface, @r, cWaterColor) |
|
206 |
end; |
|
207 |
||
208 |
DrawGears(Surface); |
|
209 |
||
95 | 210 |
if CurrentTeam <> nil then |
211 |
begin |
|
212 |
team:= TeamsList; |
|
213 |
while team<>nil do |
|
4 | 214 |
begin |
215 |
for i:= 0 to 7 do |
|
216 |
with team.Hedgehogs[i] do |
|
217 |
if Gear<>nil then |
|
218 |
if Gear.State = 0 then |
|
5 | 219 |
begin |
95 | 220 |
t:= round(Gear.Y) - cHHRadius - 10 + WorldDy; |
221 |
dec(t, HealthTag.h + 2); |
|
222 |
DrawCentered(round(Gear.X) + WorldDx, t, HealthTag, Surface); |
|
223 |
dec(t, NameTag.h + 2); |
|
224 |
DrawCentered(round(Gear.X) + WorldDx, t, NameTag, Surface); |
|
225 |
dec(t, Team.NameTag.h + 2); |
|
226 |
DrawCentered(round(Gear.X) + WorldDx, t, Team.NameTag, Surface) |
|
5 | 227 |
end else // Current hedgehog |
4 | 228 |
begin |
176 | 229 |
if bShowFinger |
230 |
and ((Gear.State and gstHHDriven) <> 0) then DrawSprite(sprFinger, round(Gear.X) - 16 + WorldDx, round(Gear.Y) - 64 + WorldDy, RealTicks div 32 mod 16, Surface); |
|
69 | 231 |
if (Gear.State and (gstMoving or gstDrowning or gstFalling)) = 0 then |
4 | 232 |
if (Gear.State and gstHHThinking) <> 0 then |
198 | 233 |
DrawGear(sQuestion, Round(Gear.X) - 10 + WorldDx, Round(Gear.Y) - cHHRadius - 34 + WorldDy, Surface) |
4 | 234 |
else |
69 | 235 |
if ShowCrosshair and ((Gear.State and gstAttacked) = 0) then |
244 | 236 |
DrawSurfSprite(Round(Gear.X + hwSign(Gear.dX) * Sin(Gear.Angle*pi/cMaxAngle)*60) + WorldDx - 11, |
198 | 237 |
Round(Gear.Y - Cos(Gear.Angle*pi/cMaxAngle)*60) + WorldDy - 12, |
203 | 238 |
24, (18 + hwSign(Gear.dX) * integer(((Gear.Angle * 72 div cMaxAngle) + 1) div 2) mod 18) mod 18, |
198 | 239 |
Team.CrosshairSurf, Surface); |
4 | 240 |
end; |
241 |
team:= team.Next |
|
242 |
end; |
|
95 | 243 |
end; |
244 |
||
4 | 245 |
|
5 | 246 |
// Waves |
4 | 247 |
{$WARNINGS OFF} |
56 | 248 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) + 64) and $FF), cWaterLine + WorldDy - 32, 0, Surface); |
249 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 128) and $FF), cWaterLine + WorldDy - 16, 0, Surface); |
|
250 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy , 0, Surface); |
|
4 | 251 |
{$WARNINGS ON} |
252 |
||
79 | 253 |
// Turn time |
4 | 254 |
if TurnTimeLeft <> 0 then |
255 |
begin |
|
256 |
i:= Succ(Pred(TurnTimeLeft) div 1000); |
|
257 |
if i>99 then t:= 112 |
|
258 |
else if i>9 then t:= 96 |
|
259 |
else t:= 80; |
|
260 |
DrawSprite(sprFrame, t, cScreenHeight - 48, 1, Surface); |
|
261 |
while i > 0 do |
|
262 |
begin |
|
263 |
dec(t, 32); |
|
264 |
DrawSprite(sprBigDigit, t, cScreenHeight - 48, i mod 10, Surface); |
|
265 |
i:= i div 10 |
|
266 |
end; |
|
267 |
DrawSprite(sprFrame, t - 4, cScreenHeight - 48, 0, Surface); |
|
268 |
end; |
|
79 | 269 |
|
270 |
// Attack bar |
|
4 | 271 |
if CurrentTeam <> nil then |
272 |
case AttackBar of |
|
273 |
1: begin |
|
274 |
r:= StuffPoz[sPowerBar]; |
|
275 |
{$WARNINGS OFF} |
|
276 |
r.w:= (CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear.Power * 256) div cPowerDivisor; |
|
277 |
{$WARNINGS ON} |
|
278 |
DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface); |
|
279 |
end; |
|
74 | 280 |
2: with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
281 |
begin |
|
108 | 282 |
tdx:= hwSign(Gear.dX) * Sin(Gear.Angle*pi/cMaxAngle); |
74 | 283 |
tdy:= - Cos(Gear.Angle*pi/cMaxAngle); |
284 |
for i:= (Gear.Power * 24) div cPowerDivisor downto 0 do |
|
75 | 285 |
DrawSprite(sprPower, round(Gear.X + WorldDx + tdx * (24 + i * 2)) - 16, |
286 |
round(Gear.Y + WorldDy + tdy * (24 + i * 2)) - 12, |
|
74 | 287 |
i, Surface) |
288 |
end |
|
4 | 289 |
end; |
290 |
||
5 | 291 |
// Target |
4 | 292 |
if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0, Surface); |
293 |
||
294 |
// Captions |
|
175 | 295 |
i:= 8; |
296 |
for grp:= Low(TCapGroup) to High(TCapGroup) do |
|
297 |
with Captions[grp] do |
|
83 | 298 |
if EndTime > 0 then |
175 | 299 |
begin |
300 |
DrawCentered(cScreenWidth div 2, i + cConsoleYAdd, Surf, Surface); |
|
301 |
inc(i, Surf.h + 2); |
|
302 |
if EndTime <= RealTicks then |
|
303 |
begin |
|
304 |
SDL_FreeSurface(Surf); |
|
305 |
Surf:= nil; |
|
306 |
EndTime:= 0 |
|
307 |
end |
|
308 |
end; |
|
4 | 309 |
|
47 | 310 |
// Teams Healths |
311 |
team:= TeamsList; |
|
312 |
while team <> nil do |
|
313 |
begin |
|
95 | 314 |
r.x:= cScreenWidth div 2 - team.NameTag.w - 3; |
315 |
r.y:= team.DrawHealthY; |
|
316 |
r.w:= team.NameTag.w; |
|
317 |
r.h:= team.NameTag.h; |
|
318 |
SDL_UpperBlit(team.NameTag, nil, Surface, @r); |
|
47 | 319 |
r:= team.HealthRect; |
146 | 320 |
r.w:= 2 + team.TeamHealthBarWidth; |
49 | 321 |
DrawFromStoreRect(cScreenWidth div 2, |
322 |
Team.DrawHealthY, |
|
47 | 323 |
@r, Surface); |
83 | 324 |
inc(r.x, cTeamHealthWidth + 2); |
325 |
r.w:= 3; |
|
146 | 326 |
DrawFromStoreRect(cScreenWidth div 2 + team.TeamHealthBarWidth + 2, |
49 | 327 |
Team.DrawHealthY, |
47 | 328 |
@r, Surface); |
329 |
team:= team.Next |
|
330 |
end; |
|
331 |
||
5 | 332 |
// Lag alert |
4 | 333 |
if isInLag then DrawSprite(sprLag, 32, 32 + cConsoleYAdd, (RealTicks shr 7) mod 7, Surface); |
334 |
||
5 | 335 |
// Wind bar |
336 |
DrawGear(sWindBar, cScreenWidth - 180, cScreenHeight - 30, Surface); |
|
6 | 337 |
if WindBarWidth > 0 then |
5 | 338 |
begin |
339 |
with StuffPoz[sWindR] do |
|
340 |
begin |
|
6 | 341 |
{$WARNINGS OFF} |
5 | 342 |
r.x:= x + 8 - (RealTicks shr 6) mod 8; |
6 | 343 |
{$WARNINGS ON} |
5 | 344 |
r.y:= y; |
6 | 345 |
r.w:= WindBarWidth; |
5 | 346 |
r.h:= 13; |
347 |
end; |
|
348 |
DrawSpriteFromRect(r, cScreenWidth - 103, cScreenHeight - 28, 13, 0, Surface); |
|
349 |
end else |
|
6 | 350 |
if WindBarWidth < 0 then |
5 | 351 |
begin |
352 |
with StuffPoz[sWindL] do |
|
353 |
begin |
|
6 | 354 |
{$WARNINGS OFF} |
355 |
r.x:= x + (WindBarWidth + RealTicks shr 6) mod 8; |
|
356 |
{$WARNINGS ON} |
|
5 | 357 |
r.y:= y; |
6 | 358 |
r.w:= - WindBarWidth; |
5 | 359 |
r.h:= 13; |
360 |
end; |
|
6 | 361 |
DrawSpriteFromRect(r, cScreenWidth - 106 + WindBarWidth, cScreenHeight - 28, 13, 0, Surface); |
5 | 362 |
end; |
363 |
||
161 | 364 |
// AmmoMenu |
365 |
if (AMxCurr < cScreenWidth) or bShowAmmoMenu then ShowAmmoMenu(Surface); |
|
366 |
||
5 | 367 |
// Cursor |
4 | 368 |
if isCursorVisible then DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface); |
369 |
||
370 |
{$IFDEF COUNTTICKS} |
|
371 |
DXOutText(10, 10, fnt16, inttostr(cntTicks), Surface); |
|
372 |
{$ENDIF} |
|
373 |
||
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
244
diff
changeset
|
374 |
if isPaused then DrawCentered(cScreenWidth div 2, cScreenHeight div 2, PauseSurface, Surface); |
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
244
diff
changeset
|
375 |
|
4 | 376 |
inc(Frames); |
377 |
inc(CountTicks, Lag); |
|
378 |
if CountTicks >= 1000 then |
|
379 |
begin |
|
380 |
FPS:= Frames; |
|
381 |
Frames:= 0; |
|
382 |
CountTicks:= 0; |
|
383 |
end; |
|
174 | 384 |
if cShowFPS then DXOutText(cScreenWidth - 50, 10, fnt16, inttostr(FPS) + ' fps', Surface); |
385 |
||
386 |
inc(SoundTimerTicks, Lag); |
|
387 |
if SoundTimerTicks >= 50 then |
|
388 |
begin |
|
389 |
SoundTimerTicks:= 0; |
|
390 |
if cVolumeDelta <> 0 then |
|
391 |
begin |
|
392 |
str(ChangeVolume(cVolumeDelta), s); |
|
175 | 393 |
AddCaption(Format(trmsg[sidVolume], s), $FFFFFF, capgrpVolume) |
174 | 394 |
end |
395 |
end |
|
4 | 396 |
end; |
397 |
||
108 | 398 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
4 | 399 |
begin |
83 | 400 |
if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s); |
175 | 401 |
if Captions[Group].Surf <> nil then SDL_FreeSurface(Captions[Group].Surf); |
4 | 402 |
|
175 | 403 |
Captions[Group].Surf:= RenderString(s, Color, fntBig); |
404 |
Captions[Group].EndTime:= RealTicks + 1200 |
|
4 | 405 |
end; |
406 |
||
79 | 407 |
procedure MoveCamera; |
4 | 408 |
const PrevSentPointTime: LongWord = 0; |
284 | 409 |
var EdgesDist: integer; |
4 | 410 |
begin |
411 |
if not (CurrentTeam.ExtDriven and isCursorVisible) then SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y); |
|
412 |
if (FollowGear <> nil) then |
|
57 | 413 |
if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then |
4 | 414 |
begin |
415 |
FollowGear:= nil; |
|
416 |
exit |
|
417 |
end |
|
418 |
else begin |
|
108 | 419 |
CursorPoint.x:= (CursorPoint.x * 7 + (round(FollowGear.X + hwSign(FollowGear.dX) * 100) + WorldDx)) div 8; |
71 | 420 |
CursorPoint.y:= (CursorPoint.y * 7 + (round(FollowGear.Y) + WorldDy)) div 8 |
4 | 421 |
end; |
422 |
||
423 |
if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit; |
|
424 |
||
162 | 425 |
if AMxCurr < cScreenWidth then |
426 |
begin |
|
427 |
if CursorPoint.X < AMxCurr + 35 then CursorPoint.X:= AMxCurr + 35; |
|
428 |
if CursorPoint.X > AMxCurr + 200 then CursorPoint.X:= AMxCurr + 200; |
|
429 |
if CursorPoint.Y < cScreenHeight - 75 - SlotsNum * 33 then CursorPoint.Y:= cScreenHeight - 75 - SlotsNum * 33; |
|
430 |
if CursorPoint.Y > cScreenHeight - 76 then CursorPoint.Y:= cScreenHeight - 76; |
|
431 |
prevPoint:= CursorPoint; |
|
432 |
SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
|
433 |
exit |
|
434 |
end; |
|
435 |
||
4 | 436 |
if isCursorVisible then |
437 |
begin |
|
438 |
if (not CurrentTeam.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then |
|
439 |
begin |
|
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
146
diff
changeset
|
440 |
SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy); |
4 | 441 |
PrevSentPointTime:= GameTicks |
442 |
end; |
|
443 |
end; |
|
284 | 444 |
|
4 | 445 |
if isCursorVisible or (FollowGear <> nil) then |
446 |
begin |
|
284 | 447 |
if isCursorVisible then EdgesDist:= cCursorEdgesDist |
448 |
else EdgesDist:= cGearScrEdgesDist; |
|
449 |
if CursorPoint.X < EdgesDist then |
|
4 | 450 |
begin |
284 | 451 |
WorldDx:= WorldDx - CursorPoint.X + EdgesDist; |
452 |
CursorPoint.X:= EdgesDist |
|
4 | 453 |
end else |
284 | 454 |
if CursorPoint.X > cScreenWidth - EdgesDist then |
4 | 455 |
begin |
284 | 456 |
WorldDx:= WorldDx - CursorPoint.X + cScreenWidth - EdgesDist; |
457 |
CursorPoint.X:= cScreenWidth - EdgesDist |
|
4 | 458 |
end; |
284 | 459 |
if CursorPoint.Y < EdgesDist then |
4 | 460 |
begin |
284 | 461 |
WorldDy:= WorldDy - CursorPoint.Y + EdgesDist; |
462 |
CursorPoint.Y:= EdgesDist |
|
4 | 463 |
end else |
284 | 464 |
if CursorPoint.Y > cScreenHeight - EdgesDist then |
4 | 465 |
begin |
284 | 466 |
WorldDy:= WorldDy - CursorPoint.Y + cScreenHeight - EdgesDist; |
467 |
CursorPoint.Y:= cScreenHeight - EdgesDist |
|
4 | 468 |
end; |
469 |
end else |
|
470 |
begin |
|
70 | 471 |
WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; |
472 |
WorldDy:= WorldDy - CursorPoint.Y + prevPoint.Y; |
|
4 | 473 |
CursorPoint.X:= (cScreenWidth shr 1); |
474 |
CursorPoint.Y:= (cScreenHeight shr 1); |
|
475 |
end; |
|
476 |
SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
|
477 |
prevPoint:= CursorPoint; |
|
75 | 478 |
if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater; |
4 | 479 |
if WorldDy > 2048 then WorldDy:= 2048; |
480 |
if WorldDx < -2048 then WorldDx:= -2048; |
|
481 |
if WorldDx > cScreenWidth then WorldDx:= cScreenWidth; |
|
482 |
end; |
|
483 |
||
484 |
initialization |
|
485 |
FillChar(Captions, sizeof(Captions), 0) |
|
486 |
||
487 |
end. |