author | unc0rr |
Mon, 28 Jan 2008 17:51:18 +0000 | |
changeset 774 | c2d6476e741f |
parent 770 | 0138f1b5a804 |
child 775 | 23c253aae336 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
393 | 3 |
* Copyright (c) 2004-2007 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 |
|
351 | 21 |
uses SDLh, uGears, uConsts, uFloat; |
4 | 22 |
{$INCLUDE options.inc} |
371 | 23 |
const WorldDx: LongInt = -512; |
24 |
WorldDy: LongInt = -256; |
|
4 | 25 |
|
26 |
procedure InitWorld; |
|
371 | 27 |
procedure DrawWorld(Lag: LongInt; 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; |
|
371 | 34 |
WindBarWidth: LongInt = 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 |
|
756 | 41 |
uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, GL; |
564 | 42 |
const FPS: Longword = 0; |
4 | 43 |
CountTicks: Longword = 0; |
174 | 44 |
SoundTimerTicks: Longword = 0; |
4 | 45 |
prevPoint: TPoint = (X: 0; Y: 0); |
161 | 46 |
|
4 | 47 |
type TCaptionStr = record |
762 | 48 |
Tex: PTexture; |
4 | 49 |
EndTime: LongWord; |
50 |
end; |
|
51 |
||
371 | 52 |
var cWaterSprCount: LongInt; |
175 | 53 |
Captions: array[TCapGroup] of TCaptionStr; |
371 | 54 |
AMxLeft, AMxCurr, SlotsNum: LongInt; |
759 | 55 |
tmpSurface: PSDL_Surface; |
56 |
fpsTexture: PTexture = nil; |
|
4 | 57 |
|
58 |
procedure InitWorld; |
|
59 |
begin |
|
74 | 60 |
cWaterSprCount:= 1 + cScreenWidth div (SpritesData[sprWater].Width); |
284 | 61 |
cGearScrEdgesDist:= Min(cScreenWidth div 2 - 100, cScreenHeight div 2 - 50); |
74 | 62 |
SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
63 |
prevPoint.X:= cScreenWidth div 2; |
|
64 |
prevPoint.Y:= cScreenHeight div 2; |
|
65 |
WorldDx:= - 1024 + cScreenWidth div 2; |
|
161 | 66 |
WorldDy:= - 512 + cScreenHeight div 2; |
67 |
AMxLeft:= cScreenWidth - 210; |
|
68 |
AMxCurr:= cScreenWidth |
|
69 |
end; |
|
70 |
||
71 |
procedure ShowAmmoMenu(Surface: PSDL_Surface); |
|
72 |
const MENUSPEED = 15; |
|
371 | 73 |
var x, y, i, t: LongInt; |
74 |
Slot, Pos: LongInt; |
|
161 | 75 |
begin |
76 |
if (TurnTimeLeft = 0) or KbdKeyPressed then bShowAmmoMenu:= false; |
|
165 | 77 |
if bShowAmmoMenu then |
78 |
begin |
|
79 |
if AMxCurr = cScreenWidth then prevPoint.X:= 0; |
|
80 |
if AMxCurr > AMxLeft then dec(AMxCurr, MENUSPEED); |
|
81 |
end else |
|
82 |
begin |
|
83 |
if AMxCurr = AMxLeft then |
|
84 |
begin |
|
85 |
CursorPoint.X:= cScreenWidth div 2; |
|
86 |
CursorPoint.Y:= cScreenHeight div 2; |
|
87 |
prevPoint:= CursorPoint; |
|
88 |
SDL_WarpMouse(CursorPoint.X, CursorPoint.Y) |
|
89 |
end; |
|
90 |
if AMxCurr < cScreenWidth then inc(AMxCurr, MENUSPEED); |
|
91 |
end; |
|
161 | 92 |
|
93 |
if CurrentTeam = nil then exit; |
|
162 | 94 |
Slot:= 0; |
95 |
Pos:= -1; |
|
602 | 96 |
with CurrentHedgehog^ do |
161 | 97 |
begin |
98 |
if Ammo = nil then exit; |
|
162 | 99 |
SlotsNum:= 0; |
161 | 100 |
x:= AMxCurr; |
101 |
y:= cScreenHeight - 40; |
|
102 |
dec(y); |
|
103 |
DrawSprite(sprAMBorders, x, y, 0, Surface); |
|
104 |
dec(y); |
|
105 |
DrawSprite(sprAMBorders, x, y, 1, Surface); |
|
106 |
dec(y, 33); |
|
107 |
DrawSprite(sprAMSlotName, x, y, 0, Surface); |
|
108 |
for i:= cMaxSlotIndex downto 0 do |
|
351 | 109 |
if Ammo^[i, 0].Count > 0 then |
161 | 110 |
begin |
162 | 111 |
if (CursorPoint.Y >= y - 33) and (CursorPoint.Y < y) then Slot:= i; |
161 | 112 |
dec(y, 33); |
162 | 113 |
inc(SlotsNum); |
161 | 114 |
DrawSprite(sprAMSlot, x, y, 0, Surface); |
115 |
DrawSprite(sprAMSlotKeys, x + 2, y + 1, i, Surface); |
|
116 |
t:= 0; |
|
351 | 117 |
while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do |
161 | 118 |
begin |
371 | 119 |
DrawSprite(sprAMAmmos, x + t * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType), Surface); |
162 | 120 |
if (Slot = i) and (CursorPoint.X >= x + t * 33 + 35) and (CursorPoint.X < x + t * 33 + 68) then |
121 |
begin |
|
122 |
DrawSprite(sprAMSelection, x + t * 33 + 35, y + 1, 0, Surface); |
|
123 |
Pos:= t; |
|
124 |
end; |
|
161 | 125 |
inc(t) |
126 |
end |
|
127 |
end; |
|
128 |
dec(y, 1); |
|
162 | 129 |
DrawSprite(sprAMBorders, x, y, 0, Surface); |
130 |
||
131 |
if (Pos >= 0) then |
|
351 | 132 |
if Ammo^[Slot, Pos].Count > 0 then |
162 | 133 |
begin |
351 | 134 |
DXOutText(AMxCurr + 10, cScreenHeight - 68, fnt16, trAmmo[Ammoz[Ammo^[Slot, Pos].AmmoType].NameId], Surface); |
135 |
if Ammo^[Slot, Pos].Count < 10 then |
|
136 |
DXOutText(AMxCurr + 175, cScreenHeight - 68, fnt16, chr(Ammo^[Slot, Pos].Count + 48) + 'x', Surface); |
|
162 | 137 |
if bSelected then |
138 |
begin |
|
165 | 139 |
bShowAmmoMenu:= false; |
351 | 140 |
SetWeapon(Ammo^[Slot, Pos].AmmoType); |
165 | 141 |
bSelected:= false; |
142 |
exit |
|
162 | 143 |
end; |
144 |
end; |
|
145 |
end; |
|
146 |
||
147 |
bSelected:= false; |
|
564 | 148 |
if AMxLeft = AMxCurr then DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface) |
4 | 149 |
end; |
150 |
||
162 | 151 |
procedure MoveCamera; forward; |
152 |
||
371 | 153 |
procedure DrawWorld(Lag: LongInt; Surface: PSDL_Surface); |
154 |
var i, t: LongInt; |
|
4 | 155 |
r: TSDL_Rect; |
107 | 156 |
tdx, tdy: Double; |
175 | 157 |
grp: TCapGroup; |
174 | 158 |
s: string[15]; |
80 | 159 |
|
371 | 160 |
procedure DrawRepeated(spr: TSprite; Shift: LongInt); |
161 |
var i, w: LongInt; |
|
80 | 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 |
770 | 173 |
// Sky |
756 | 174 |
glClear(GL_COLOR_BUFFER_BIT); |
175 |
glEnable(GL_BLEND); |
|
176 |
||
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
244
diff
changeset
|
177 |
if not isPaused then MoveCamera; |
162 | 178 |
|
5 | 179 |
// background |
755 | 180 |
DrawRepeated(sprSky, WorldDx * 3 div 8); |
181 |
DrawRepeated(sprHorizont, WorldDx * 3 div 5); |
|
4 | 182 |
|
5 | 183 |
// Waves |
4 | 184 |
{$WARNINGS OFF} |
757 | 185 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy - 64, 0, Surface); |
186 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 192) and $FF), cWaterLine + WorldDy - 48, 0, Surface); |
|
4 | 187 |
{$WARNINGS ON} |
188 |
||
762 | 189 |
DrawLand(WorldDx, WorldDy); |
5 | 190 |
// Water |
4 | 191 |
r.y:= WorldDy + cWaterLine + 32; |
192 |
if r.y < cScreenHeight then |
|
193 |
begin |
|
23 | 194 |
if r.y < 0 then r.y:= 0; |
4 | 195 |
r.h:= cScreenHeight - r.y; |
196 |
r.x:= 0; |
|
197 |
r.w:= cScreenWidth; |
|
753 | 198 |
// SDL_FillRect(Surface, @r, cWaterColor) |
4 | 199 |
end; |
200 |
||
755 | 201 |
DrawGears(Surface); |
4 | 202 |
|
5 | 203 |
// Waves |
4 | 204 |
{$WARNINGS OFF} |
757 | 205 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) + 64) and $FF), cWaterLine + WorldDy - 32, 0, Surface); |
206 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 128) and $FF), cWaterLine + WorldDy - 16, 0, Surface); |
|
207 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy , 0, Surface); |
|
4 | 208 |
{$WARNINGS ON} |
209 |
||
79 | 210 |
// Turn time |
4 | 211 |
if TurnTimeLeft <> 0 then |
212 |
begin |
|
213 |
i:= Succ(Pred(TurnTimeLeft) div 1000); |
|
214 |
if i>99 then t:= 112 |
|
215 |
else if i>9 then t:= 96 |
|
216 |
else t:= 80; |
|
770 | 217 |
DrawSprite(sprFrame, t, cScreenHeight - 48, 1, Surface); |
4 | 218 |
while i > 0 do |
219 |
begin |
|
220 |
dec(t, 32); |
|
221 |
DrawSprite(sprBigDigit, t, cScreenHeight - 48, i mod 10, Surface); |
|
222 |
i:= i div 10 |
|
223 |
end; |
|
770 | 224 |
DrawSprite(sprFrame, t - 4, cScreenHeight - 48, 0, Surface); |
4 | 225 |
end; |
79 | 226 |
|
227 |
// Attack bar |
|
4 | 228 |
if CurrentTeam <> nil then |
229 |
case AttackBar of |
|
689 | 230 |
(* 1: begin |
4 | 231 |
r:= StuffPoz[sPowerBar]; |
232 |
{$WARNINGS OFF} |
|
602 | 233 |
r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor; |
4 | 234 |
{$WARNINGS ON} |
235 |
DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface); |
|
236 |
end; |
|
689 | 237 |
*) 2: with CurrentHedgehog^ do |
74 | 238 |
begin |
351 | 239 |
tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle); |
240 |
tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle); |
|
241 |
for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do |
|
762 | 242 |
DrawSprite(sprPower, hwRound(Gear^.X) + system.round(WorldDx + tdx * (24 + i * 2)) - 16, |
243 |
hwRound(Gear^.Y) + system.round(WorldDy + tdy * (24 + i * 2)) - 12, |
|
244 |
i, Surface) |
|
74 | 245 |
end |
4 | 246 |
end; |
247 |
||
5 | 248 |
// Target |
762 | 249 |
if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0, Surface); |
4 | 250 |
|
251 |
// Captions |
|
175 | 252 |
i:= 8; |
253 |
for grp:= Low(TCapGroup) to High(TCapGroup) do |
|
254 |
with Captions[grp] do |
|
762 | 255 |
if Tex <> nil then |
175 | 256 |
begin |
762 | 257 |
DrawCentered(cScreenWidth div 2, i + cConsoleYAdd, Tex); |
258 |
inc(i, Tex^.h + 2); |
|
564 | 259 |
if EndTime <= RealTicks then |
175 | 260 |
begin |
762 | 261 |
FreeTexture(Tex); |
262 |
Tex:= nil; |
|
175 | 263 |
EndTime:= 0 |
264 |
end |
|
265 |
end; |
|
4 | 266 |
|
47 | 267 |
// Teams Healths |
547 | 268 |
for t:= 0 to Pred(TeamsCount) do |
269 |
with TeamsArray[t]^ do |
|
47 | 270 |
begin |
762 | 271 |
DrawTexture(cScreenWidth div 2 - NameTagTex^.w - 3, DrawHealthY, NameTagTex); |
690 | 272 |
|
273 |
r.x:= 0; |
|
274 |
r.y:= 0; |
|
547 | 275 |
r.w:= 2 + TeamHealthBarWidth; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
276 |
r.h:= HealthTex^.h; |
690 | 277 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
278 |
DrawFromRect(cScreenWidth div 2, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
279 |
DrawHealthY, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
280 |
@r, HealthTex, Surface); |
690 | 281 |
|
83 | 282 |
inc(r.x, cTeamHealthWidth + 2); |
283 |
r.w:= 3; |
|
690 | 284 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
285 |
DrawFromRect(cScreenWidth div 2 + TeamHealthBarWidth + 2, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
286 |
DrawHealthY, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
287 |
@r, HealthTex, Surface); |
47 | 288 |
end; |
289 |
||
5 | 290 |
// Lag alert |
762 | 291 |
if isInLag then DrawSprite(sprLag, 32, 32 + cConsoleYAdd, (RealTicks shr 7) mod 12, Surface); |
4 | 292 |
|
5 | 293 |
// Wind bar |
762 | 294 |
DrawSprite(sprWindBar, cScreenWidth - 180, cScreenHeight - 30, 0, Surface); |
6 | 295 |
if WindBarWidth > 0 then |
5 | 296 |
begin |
689 | 297 |
{$WARNINGS OFF} |
298 |
r.x:= 8 - (RealTicks shr 6) mod 8; |
|
299 |
{$WARNINGS ON} |
|
300 |
r.y:= 0; |
|
301 |
r.w:= WindBarWidth; |
|
302 |
r.h:= 13; |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
303 |
DrawSpriteFromRect(sprWindR, r, cScreenWidth - 103, cScreenHeight - 28, 13, 0, Surface); |
5 | 304 |
end else |
6 | 305 |
if WindBarWidth < 0 then |
5 | 306 |
begin |
689 | 307 |
{$WARNINGS OFF} |
308 |
r.x:= (WindBarWidth + RealTicks shr 6) mod 8; |
|
309 |
{$WARNINGS ON} |
|
310 |
r.y:= 0; |
|
311 |
r.w:= - WindBarWidth; |
|
312 |
r.h:= 13; |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
313 |
DrawSpriteFromRect(sprWindL, r, cScreenWidth - 106 + WindBarWidth, cScreenHeight - 28, 13, 0, Surface); |
5 | 314 |
end; |
315 |
||
161 | 316 |
// AmmoMenu |
770 | 317 |
if (AMxCurr < cScreenWidth) or bShowAmmoMenu then ShowAmmoMenu(Surface); |
161 | 318 |
|
5 | 319 |
// Cursor |
408 | 320 |
if isCursorVisible then |
321 |
begin |
|
322 |
if not bShowAmmoMenu then |
|
602 | 323 |
with CurrentHedgehog^ do |
408 | 324 |
if (Gear^.State and gstHHChooseTarget) <> 0 then |
325 |
begin |
|
326 |
i:= Ammo^[CurSlot, CurAmmo].Pos; |
|
327 |
with Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType] do |
|
328 |
if PosCount > 1 then |
|
762 | 329 |
DrawSprite(PosSprite, CursorPoint.X - SpritesData[PosSprite].Width div 2, |
330 |
CursorPoint.Y - SpritesData[PosSprite].Height div 2, |
|
331 |
i, Surface); |
|
408 | 332 |
end; |
762 | 333 |
DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface) |
408 | 334 |
end; |
4 | 335 |
|
762 | 336 |
if isPaused then DrawCentered(cScreenWidth div 2, cScreenHeight div 2, PauseTexture); |
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
244
diff
changeset
|
337 |
|
4 | 338 |
inc(Frames); |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
339 |
if cShowFPS then |
4 | 340 |
begin |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
341 |
inc(CountTicks, Lag); |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
342 |
if CountTicks >= 1000 then |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
343 |
begin |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
344 |
FPS:= Frames; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
345 |
Frames:= 0; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
346 |
CountTicks:= 0; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
347 |
s:= inttostr(FPS) + ' fps'; |
759 | 348 |
if fpsTexture <> nil then FreeTexture(fpsTexture); |
349 |
tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), $FFFFFF); |
|
350 |
fpsTexture:= Surface2Tex(tmpSurface); |
|
351 |
SDL_FreeSurface(tmpSurface) |
|
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
352 |
end; |
759 | 353 |
if fpsTexture <> nil then |
354 |
begin |
|
355 |
r.x:= 0; |
|
356 |
r.y:= 0; |
|
357 |
r.w:= fpsTexture^.w; |
|
358 |
r.h:= fpsTexture^.h; |
|
359 |
DrawFromRect(cScreenWidth - 50, 10, @r, fpsTexture, Surface); |
|
360 |
end |
|
4 | 361 |
end; |
174 | 362 |
|
363 |
inc(SoundTimerTicks, Lag); |
|
364 |
if SoundTimerTicks >= 50 then |
|
365 |
begin |
|
366 |
SoundTimerTicks:= 0; |
|
367 |
if cVolumeDelta <> 0 then |
|
368 |
begin |
|
369 |
str(ChangeVolume(cVolumeDelta), s); |
|
175 | 370 |
AddCaption(Format(trmsg[sidVolume], s), $FFFFFF, capgrpVolume) |
174 | 371 |
end |
756 | 372 |
end; |
373 |
||
374 |
glDisable(GL_BLEND) |
|
4 | 375 |
end; |
376 |
||
108 | 377 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
4 | 378 |
begin |
83 | 379 |
if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s); |
762 | 380 |
if Captions[Group].Tex <> nil then FreeTexture(Captions[Group].Tex); |
4 | 381 |
|
762 | 382 |
Captions[Group].Tex:= RenderStringTex(s, Color, fntBig); |
564 | 383 |
Captions[Group].EndTime:= RealTicks + 1500 |
4 | 384 |
end; |
385 |
||
79 | 386 |
procedure MoveCamera; |
4 | 387 |
const PrevSentPointTime: LongWord = 0; |
371 | 388 |
var EdgesDist: LongInt; |
4 | 389 |
begin |
678 | 390 |
if (not (CurrentTeam^.ExtDriven and isCursorVisible)) |
391 |
and cHasFocus then SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y); |
|
392 |
||
4 | 393 |
if (FollowGear <> nil) then |
57 | 394 |
if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then |
4 | 395 |
begin |
396 |
FollowGear:= nil; |
|
397 |
exit |
|
398 |
end |
|
399 |
else begin |
|
678 | 400 |
CursorPoint.x:= (prevPoint.x * 7 + (hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100) + WorldDx) div 8; |
401 |
CursorPoint.y:= (prevPoint.y * 7 + (hwRound(FollowGear^.Y) + WorldDy)) div 8 |
|
4 | 402 |
end; |
403 |
||
404 |
if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit; |
|
405 |
||
162 | 406 |
if AMxCurr < cScreenWidth then |
407 |
begin |
|
408 |
if CursorPoint.X < AMxCurr + 35 then CursorPoint.X:= AMxCurr + 35; |
|
409 |
if CursorPoint.X > AMxCurr + 200 then CursorPoint.X:= AMxCurr + 200; |
|
410 |
if CursorPoint.Y < cScreenHeight - 75 - SlotsNum * 33 then CursorPoint.Y:= cScreenHeight - 75 - SlotsNum * 33; |
|
411 |
if CursorPoint.Y > cScreenHeight - 76 then CursorPoint.Y:= cScreenHeight - 76; |
|
412 |
prevPoint:= CursorPoint; |
|
308 | 413 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
162 | 414 |
exit |
415 |
end; |
|
416 |
||
4 | 417 |
if isCursorVisible then |
418 |
begin |
|
351 | 419 |
if (not CurrentTeam^.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then |
4 | 420 |
begin |
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
146
diff
changeset
|
421 |
SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy); |
4 | 422 |
PrevSentPointTime:= GameTicks |
423 |
end; |
|
424 |
end; |
|
351 | 425 |
|
4 | 426 |
if isCursorVisible or (FollowGear <> nil) then |
427 |
begin |
|
284 | 428 |
if isCursorVisible then EdgesDist:= cCursorEdgesDist |
429 |
else EdgesDist:= cGearScrEdgesDist; |
|
430 |
if CursorPoint.X < EdgesDist then |
|
4 | 431 |
begin |
284 | 432 |
WorldDx:= WorldDx - CursorPoint.X + EdgesDist; |
433 |
CursorPoint.X:= EdgesDist |
|
4 | 434 |
end else |
284 | 435 |
if CursorPoint.X > cScreenWidth - EdgesDist then |
4 | 436 |
begin |
284 | 437 |
WorldDx:= WorldDx - CursorPoint.X + cScreenWidth - EdgesDist; |
438 |
CursorPoint.X:= cScreenWidth - EdgesDist |
|
4 | 439 |
end; |
284 | 440 |
if CursorPoint.Y < EdgesDist then |
4 | 441 |
begin |
284 | 442 |
WorldDy:= WorldDy - CursorPoint.Y + EdgesDist; |
443 |
CursorPoint.Y:= EdgesDist |
|
4 | 444 |
end else |
284 | 445 |
if CursorPoint.Y > cScreenHeight - EdgesDist then |
4 | 446 |
begin |
284 | 447 |
WorldDy:= WorldDy - CursorPoint.Y + cScreenHeight - EdgesDist; |
448 |
CursorPoint.Y:= cScreenHeight - EdgesDist |
|
4 | 449 |
end; |
450 |
end else |
|
308 | 451 |
if cHasFocus then |
452 |
begin |
|
70 | 453 |
WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; |
454 |
WorldDy:= WorldDy - CursorPoint.Y + prevPoint.Y; |
|
4 | 455 |
CursorPoint.X:= (cScreenWidth shr 1); |
456 |
CursorPoint.Y:= (cScreenHeight shr 1); |
|
308 | 457 |
end; |
351 | 458 |
|
308 | 459 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
4 | 460 |
prevPoint:= CursorPoint; |
75 | 461 |
if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater; |
4 | 462 |
if WorldDy > 2048 then WorldDy:= 2048; |
463 |
if WorldDx < -2048 then WorldDx:= -2048; |
|
464 |
if WorldDx > cScreenWidth then WorldDx:= cScreenWidth; |
|
465 |
end; |
|
466 |
||
467 |
initialization |
|
468 |
FillChar(Captions, sizeof(Captions), 0) |
|
469 |
||
470 |
end. |