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