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