author | unc0rr |
Thu, 31 Jan 2008 20:01:07 +0000 | |
changeset 779 | cb18225a150a |
parent 777 | 86177328b094 |
child 780 | f45b0e513dfd |
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); |
|
775 | 176 |
glEnable(GL_TEXTURE_2D); |
777 | 177 |
//glPushMatrix; |
178 |
//glScalef(1.0, 1.0, 1.0); |
|
756 | 179 |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
244
diff
changeset
|
180 |
if not isPaused then MoveCamera; |
162 | 181 |
|
5 | 182 |
// background |
755 | 183 |
DrawRepeated(sprSky, WorldDx * 3 div 8); |
184 |
DrawRepeated(sprHorizont, WorldDx * 3 div 5); |
|
4 | 185 |
|
5 | 186 |
// Waves |
4 | 187 |
{$WARNINGS OFF} |
757 | 188 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy - 64, 0, Surface); |
189 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 192) and $FF), cWaterLine + WorldDy - 48, 0, Surface); |
|
4 | 190 |
{$WARNINGS ON} |
191 |
||
762 | 192 |
DrawLand(WorldDx, WorldDy); |
5 | 193 |
// Water |
4 | 194 |
r.y:= WorldDy + cWaterLine + 32; |
195 |
if r.y < cScreenHeight then |
|
196 |
begin |
|
23 | 197 |
if r.y < 0 then r.y:= 0; |
4 | 198 |
r.h:= cScreenHeight - r.y; |
199 |
r.x:= 0; |
|
200 |
r.w:= cScreenWidth; |
|
753 | 201 |
// SDL_FillRect(Surface, @r, cWaterColor) |
4 | 202 |
end; |
203 |
||
755 | 204 |
DrawGears(Surface); |
4 | 205 |
|
5 | 206 |
// Waves |
4 | 207 |
{$WARNINGS OFF} |
757 | 208 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) + 64) and $FF), cWaterLine + WorldDy - 32, 0, Surface); |
209 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 128) and $FF), cWaterLine + WorldDy - 16, 0, Surface); |
|
210 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy , 0, Surface); |
|
4 | 211 |
{$WARNINGS ON} |
212 |
||
79 | 213 |
// Turn time |
4 | 214 |
if TurnTimeLeft <> 0 then |
215 |
begin |
|
216 |
i:= Succ(Pred(TurnTimeLeft) div 1000); |
|
217 |
if i>99 then t:= 112 |
|
218 |
else if i>9 then t:= 96 |
|
219 |
else t:= 80; |
|
770 | 220 |
DrawSprite(sprFrame, t, cScreenHeight - 48, 1, Surface); |
4 | 221 |
while i > 0 do |
222 |
begin |
|
223 |
dec(t, 32); |
|
224 |
DrawSprite(sprBigDigit, t, cScreenHeight - 48, i mod 10, Surface); |
|
225 |
i:= i div 10 |
|
226 |
end; |
|
770 | 227 |
DrawSprite(sprFrame, t - 4, cScreenHeight - 48, 0, Surface); |
4 | 228 |
end; |
79 | 229 |
|
230 |
// Attack bar |
|
4 | 231 |
if CurrentTeam <> nil then |
232 |
case AttackBar of |
|
689 | 233 |
(* 1: begin |
4 | 234 |
r:= StuffPoz[sPowerBar]; |
235 |
{$WARNINGS OFF} |
|
602 | 236 |
r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor; |
4 | 237 |
{$WARNINGS ON} |
238 |
DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface); |
|
239 |
end; |
|
689 | 240 |
*) 2: with CurrentHedgehog^ do |
74 | 241 |
begin |
351 | 242 |
tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle); |
243 |
tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle); |
|
244 |
for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do |
|
762 | 245 |
DrawSprite(sprPower, hwRound(Gear^.X) + system.round(WorldDx + tdx * (24 + i * 2)) - 16, |
246 |
hwRound(Gear^.Y) + system.round(WorldDy + tdy * (24 + i * 2)) - 12, |
|
247 |
i, Surface) |
|
74 | 248 |
end |
4 | 249 |
end; |
250 |
||
5 | 251 |
// Target |
762 | 252 |
if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0, Surface); |
4 | 253 |
|
777 | 254 |
//glPopMatrix; |
255 |
||
4 | 256 |
// Captions |
175 | 257 |
i:= 8; |
258 |
for grp:= Low(TCapGroup) to High(TCapGroup) do |
|
259 |
with Captions[grp] do |
|
762 | 260 |
if Tex <> nil then |
175 | 261 |
begin |
762 | 262 |
DrawCentered(cScreenWidth div 2, i + cConsoleYAdd, Tex); |
263 |
inc(i, Tex^.h + 2); |
|
564 | 264 |
if EndTime <= RealTicks then |
175 | 265 |
begin |
762 | 266 |
FreeTexture(Tex); |
267 |
Tex:= nil; |
|
175 | 268 |
EndTime:= 0 |
269 |
end |
|
270 |
end; |
|
4 | 271 |
|
47 | 272 |
// Teams Healths |
547 | 273 |
for t:= 0 to Pred(TeamsCount) do |
274 |
with TeamsArray[t]^ do |
|
47 | 275 |
begin |
762 | 276 |
DrawTexture(cScreenWidth div 2 - NameTagTex^.w - 3, DrawHealthY, NameTagTex); |
690 | 277 |
|
278 |
r.x:= 0; |
|
279 |
r.y:= 0; |
|
547 | 280 |
r.w:= 2 + TeamHealthBarWidth; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
281 |
r.h:= HealthTex^.h; |
690 | 282 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
283 |
DrawFromRect(cScreenWidth div 2, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
284 |
DrawHealthY, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
285 |
@r, HealthTex, Surface); |
690 | 286 |
|
83 | 287 |
inc(r.x, cTeamHealthWidth + 2); |
288 |
r.w:= 3; |
|
690 | 289 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
290 |
DrawFromRect(cScreenWidth div 2 + TeamHealthBarWidth + 2, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
291 |
DrawHealthY, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
292 |
@r, HealthTex, Surface); |
47 | 293 |
end; |
294 |
||
5 | 295 |
// Lag alert |
762 | 296 |
if isInLag then DrawSprite(sprLag, 32, 32 + cConsoleYAdd, (RealTicks shr 7) mod 12, Surface); |
4 | 297 |
|
5 | 298 |
// Wind bar |
762 | 299 |
DrawSprite(sprWindBar, cScreenWidth - 180, cScreenHeight - 30, 0, Surface); |
6 | 300 |
if WindBarWidth > 0 then |
5 | 301 |
begin |
689 | 302 |
{$WARNINGS OFF} |
303 |
r.x:= 8 - (RealTicks shr 6) mod 8; |
|
304 |
{$WARNINGS ON} |
|
305 |
r.y:= 0; |
|
306 |
r.w:= WindBarWidth; |
|
307 |
r.h:= 13; |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
308 |
DrawSpriteFromRect(sprWindR, r, cScreenWidth - 103, cScreenHeight - 28, 13, 0, Surface); |
5 | 309 |
end else |
6 | 310 |
if WindBarWidth < 0 then |
5 | 311 |
begin |
689 | 312 |
{$WARNINGS OFF} |
313 |
r.x:= (WindBarWidth + RealTicks shr 6) mod 8; |
|
314 |
{$WARNINGS ON} |
|
315 |
r.y:= 0; |
|
316 |
r.w:= - WindBarWidth; |
|
317 |
r.h:= 13; |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
318 |
DrawSpriteFromRect(sprWindL, r, cScreenWidth - 106 + WindBarWidth, cScreenHeight - 28, 13, 0, Surface); |
5 | 319 |
end; |
320 |
||
161 | 321 |
// AmmoMenu |
770 | 322 |
if (AMxCurr < cScreenWidth) or bShowAmmoMenu then ShowAmmoMenu(Surface); |
161 | 323 |
|
5 | 324 |
// Cursor |
408 | 325 |
if isCursorVisible then |
326 |
begin |
|
327 |
if not bShowAmmoMenu then |
|
602 | 328 |
with CurrentHedgehog^ do |
408 | 329 |
if (Gear^.State and gstHHChooseTarget) <> 0 then |
330 |
begin |
|
331 |
i:= Ammo^[CurSlot, CurAmmo].Pos; |
|
332 |
with Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType] do |
|
333 |
if PosCount > 1 then |
|
762 | 334 |
DrawSprite(PosSprite, CursorPoint.X - SpritesData[PosSprite].Width div 2, |
335 |
CursorPoint.Y - SpritesData[PosSprite].Height div 2, |
|
336 |
i, Surface); |
|
408 | 337 |
end; |
762 | 338 |
DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface) |
408 | 339 |
end; |
4 | 340 |
|
762 | 341 |
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
|
342 |
|
4 | 343 |
inc(Frames); |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
344 |
if cShowFPS then |
4 | 345 |
begin |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
346 |
inc(CountTicks, Lag); |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
347 |
if CountTicks >= 1000 then |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
348 |
begin |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
349 |
FPS:= Frames; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
350 |
Frames:= 0; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
351 |
CountTicks:= 0; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
352 |
s:= inttostr(FPS) + ' fps'; |
759 | 353 |
if fpsTexture <> nil then FreeTexture(fpsTexture); |
354 |
tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), $FFFFFF); |
|
355 |
fpsTexture:= Surface2Tex(tmpSurface); |
|
356 |
SDL_FreeSurface(tmpSurface) |
|
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
357 |
end; |
759 | 358 |
if fpsTexture <> nil then |
359 |
begin |
|
360 |
r.x:= 0; |
|
361 |
r.y:= 0; |
|
362 |
r.w:= fpsTexture^.w; |
|
363 |
r.h:= fpsTexture^.h; |
|
364 |
DrawFromRect(cScreenWidth - 50, 10, @r, fpsTexture, Surface); |
|
365 |
end |
|
4 | 366 |
end; |
174 | 367 |
|
368 |
inc(SoundTimerTicks, Lag); |
|
369 |
if SoundTimerTicks >= 50 then |
|
370 |
begin |
|
371 |
SoundTimerTicks:= 0; |
|
372 |
if cVolumeDelta <> 0 then |
|
373 |
begin |
|
374 |
str(ChangeVolume(cVolumeDelta), s); |
|
175 | 375 |
AddCaption(Format(trmsg[sidVolume], s), $FFFFFF, capgrpVolume) |
174 | 376 |
end |
756 | 377 |
end; |
378 |
||
775 | 379 |
glDisable(GL_TEXTURE_2D); |
756 | 380 |
glDisable(GL_BLEND) |
4 | 381 |
end; |
382 |
||
108 | 383 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
4 | 384 |
begin |
83 | 385 |
if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s); |
762 | 386 |
if Captions[Group].Tex <> nil then FreeTexture(Captions[Group].Tex); |
4 | 387 |
|
762 | 388 |
Captions[Group].Tex:= RenderStringTex(s, Color, fntBig); |
564 | 389 |
Captions[Group].EndTime:= RealTicks + 1500 |
4 | 390 |
end; |
391 |
||
79 | 392 |
procedure MoveCamera; |
4 | 393 |
const PrevSentPointTime: LongWord = 0; |
371 | 394 |
var EdgesDist: LongInt; |
4 | 395 |
begin |
678 | 396 |
if (not (CurrentTeam^.ExtDriven and isCursorVisible)) |
397 |
and cHasFocus then SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y); |
|
398 |
||
4 | 399 |
if (FollowGear <> nil) then |
57 | 400 |
if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then |
4 | 401 |
begin |
402 |
FollowGear:= nil; |
|
403 |
exit |
|
404 |
end |
|
405 |
else begin |
|
678 | 406 |
CursorPoint.x:= (prevPoint.x * 7 + (hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100) + WorldDx) div 8; |
407 |
CursorPoint.y:= (prevPoint.y * 7 + (hwRound(FollowGear^.Y) + WorldDy)) div 8 |
|
4 | 408 |
end; |
409 |
||
410 |
if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit; |
|
411 |
||
162 | 412 |
if AMxCurr < cScreenWidth then |
413 |
begin |
|
414 |
if CursorPoint.X < AMxCurr + 35 then CursorPoint.X:= AMxCurr + 35; |
|
415 |
if CursorPoint.X > AMxCurr + 200 then CursorPoint.X:= AMxCurr + 200; |
|
416 |
if CursorPoint.Y < cScreenHeight - 75 - SlotsNum * 33 then CursorPoint.Y:= cScreenHeight - 75 - SlotsNum * 33; |
|
417 |
if CursorPoint.Y > cScreenHeight - 76 then CursorPoint.Y:= cScreenHeight - 76; |
|
418 |
prevPoint:= CursorPoint; |
|
308 | 419 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
162 | 420 |
exit |
421 |
end; |
|
422 |
||
4 | 423 |
if isCursorVisible then |
424 |
begin |
|
351 | 425 |
if (not CurrentTeam^.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then |
4 | 426 |
begin |
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
146
diff
changeset
|
427 |
SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy); |
4 | 428 |
PrevSentPointTime:= GameTicks |
429 |
end; |
|
430 |
end; |
|
351 | 431 |
|
4 | 432 |
if isCursorVisible or (FollowGear <> nil) then |
433 |
begin |
|
284 | 434 |
if isCursorVisible then EdgesDist:= cCursorEdgesDist |
435 |
else EdgesDist:= cGearScrEdgesDist; |
|
436 |
if CursorPoint.X < EdgesDist then |
|
4 | 437 |
begin |
284 | 438 |
WorldDx:= WorldDx - CursorPoint.X + EdgesDist; |
439 |
CursorPoint.X:= EdgesDist |
|
4 | 440 |
end else |
284 | 441 |
if CursorPoint.X > cScreenWidth - EdgesDist then |
4 | 442 |
begin |
284 | 443 |
WorldDx:= WorldDx - CursorPoint.X + cScreenWidth - EdgesDist; |
444 |
CursorPoint.X:= cScreenWidth - EdgesDist |
|
4 | 445 |
end; |
284 | 446 |
if CursorPoint.Y < EdgesDist then |
4 | 447 |
begin |
284 | 448 |
WorldDy:= WorldDy - CursorPoint.Y + EdgesDist; |
449 |
CursorPoint.Y:= EdgesDist |
|
4 | 450 |
end else |
284 | 451 |
if CursorPoint.Y > cScreenHeight - EdgesDist then |
4 | 452 |
begin |
284 | 453 |
WorldDy:= WorldDy - CursorPoint.Y + cScreenHeight - EdgesDist; |
454 |
CursorPoint.Y:= cScreenHeight - EdgesDist |
|
4 | 455 |
end; |
456 |
end else |
|
308 | 457 |
if cHasFocus then |
458 |
begin |
|
70 | 459 |
WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; |
460 |
WorldDy:= WorldDy - CursorPoint.Y + prevPoint.Y; |
|
4 | 461 |
CursorPoint.X:= (cScreenWidth shr 1); |
462 |
CursorPoint.Y:= (cScreenHeight shr 1); |
|
308 | 463 |
end; |
351 | 464 |
|
308 | 465 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
4 | 466 |
prevPoint:= CursorPoint; |
75 | 467 |
if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater; |
4 | 468 |
if WorldDy > 2048 then WorldDy:= 2048; |
469 |
if WorldDx < -2048 then WorldDx:= -2048; |
|
470 |
if WorldDx > cScreenWidth then WorldDx:= cScreenWidth; |
|
471 |
end; |
|
472 |
||
473 |
initialization |
|
474 |
FillChar(Captions, sizeof(Captions), 0) |
|
475 |
||
476 |
end. |