author | unc0rr |
Sun, 18 May 2008 10:54:43 +0000 | |
changeset 941 | b5222ddafe1f |
parent 883 | 07a568ba44e0 |
child 942 | b41af014d85e |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
883 | 3 |
* Copyright (c) 2004-2008 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); |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
104 |
DrawSprite(sprAMBorders, x, y, 0); |
161 | 105 |
dec(y); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
106 |
DrawSprite(sprAMBorders, x, y, 1); |
161 | 107 |
dec(y, 33); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
108 |
DrawSprite(sprAMSlotName, x, y, 0); |
161 | 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); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
115 |
DrawSprite(sprAMSlot, x, y, 0); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
116 |
DrawSprite(sprAMSlotKeys, x + 2, y + 1, i); |
161 | 117 |
t:= 0; |
351 | 118 |
while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do |
161 | 119 |
begin |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
120 |
DrawSprite(sprAMAmmos, x + t * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType)); |
162 | 121 |
if (Slot = i) and (CursorPoint.X >= x + t * 33 + 35) and (CursorPoint.X < x + t * 33 + 68) then |
122 |
begin |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
123 |
DrawSprite(sprAMSelection, x + t * 33 + 35, y + 1, 0); |
162 | 124 |
Pos:= t; |
125 |
end; |
|
161 | 126 |
inc(t) |
127 |
end |
|
128 |
end; |
|
129 |
dec(y, 1); |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
130 |
DrawSprite(sprAMBorders, x, y, 0); |
162 | 131 |
|
132 |
if (Pos >= 0) then |
|
351 | 133 |
if Ammo^[Slot, Pos].Count > 0 then |
162 | 134 |
begin |
843 | 135 |
DrawTexture(AMxCurr + 10, cScreenHeight - 68, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex); |
351 | 136 |
if Ammo^[Slot, Pos].Count < 10 then |
844 | 137 |
DrawTexture(AMxCurr + 175, cScreenHeight - 68, CountTexz[Ammo^[Slot, Pos].Count]); |
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; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
149 |
if AMxLeft = AMxCurr then DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8) |
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 |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
168 |
DrawSprite(spr, i, WorldDy + 1024 - SpritesData[spr].Height, 0); |
80 | 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} |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
191 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy - 64, 0); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
192 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 192) and $FF), cWaterLine + WorldDy - 48, 0); |
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} |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
220 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) + 64) and $FF), cWaterLine + WorldDy - 32, 0); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
221 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 128) and $FF), cWaterLine + WorldDy - 16, 0); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
222 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy , 0); |
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; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
232 |
DrawSprite(sprFrame, t, cScreenHeight - 48, 1); |
4 | 233 |
while i > 0 do |
234 |
begin |
|
235 |
dec(t, 32); |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
236 |
DrawSprite(sprBigDigit, t, cScreenHeight - 48, i mod 10); |
4 | 237 |
i:= i div 10 |
238 |
end; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
239 |
DrawSprite(sprFrame, t - 4, cScreenHeight - 48, 0); |
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, |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
259 |
i) |
74 | 260 |
end |
4 | 261 |
end; |
262 |
||
5 | 263 |
// Target |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
264 |
if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0); |
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, |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
297 |
@r, HealthTex); |
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, |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
304 |
@r, HealthTex); |
47 | 305 |
end; |
306 |
||
5 | 307 |
// Lag alert |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
308 |
if isInLag then DrawSprite(sprLag, 32, 32 + cConsoleYAdd, (RealTicks shr 7) mod 12); |
4 | 309 |
|
5 | 310 |
// Wind bar |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
311 |
DrawSprite(sprWindBar, cScreenWidth - 180, cScreenHeight - 30, 0); |
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; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
320 |
DrawSpriteFromRect(sprWindR, r, cScreenWidth - 103, cScreenHeight - 28, 13, 0); |
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; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
330 |
DrawSpriteFromRect(sprWindL, r, cScreenWidth - 106 + WindBarWidth, cScreenHeight - 28, 13, 0); |
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, |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
348 |
i); |
408 | 349 |
end; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
350 |
DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8) |
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 |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
371 |
DrawTexture(cScreenWidth - 50, 10, fpsTexture); |
4 | 372 |
end; |
174 | 373 |
|
374 |
inc(SoundTimerTicks, Lag); |
|
375 |
if SoundTimerTicks >= 50 then |
|
376 |
begin |
|
377 |
SoundTimerTicks:= 0; |
|
378 |
if cVolumeDelta <> 0 then |
|
379 |
begin |
|
380 |
str(ChangeVolume(cVolumeDelta), s); |
|
175 | 381 |
AddCaption(Format(trmsg[sidVolume], s), $FFFFFF, capgrpVolume) |
174 | 382 |
end |
756 | 383 |
end; |
384 |
||
775 | 385 |
glDisable(GL_TEXTURE_2D); |
756 | 386 |
glDisable(GL_BLEND) |
4 | 387 |
end; |
388 |
||
108 | 389 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
4 | 390 |
begin |
83 | 391 |
if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s); |
762 | 392 |
if Captions[Group].Tex <> nil then FreeTexture(Captions[Group].Tex); |
4 | 393 |
|
762 | 394 |
Captions[Group].Tex:= RenderStringTex(s, Color, fntBig); |
564 | 395 |
Captions[Group].EndTime:= RealTicks + 1500 |
4 | 396 |
end; |
397 |
||
79 | 398 |
procedure MoveCamera; |
4 | 399 |
const PrevSentPointTime: LongWord = 0; |
371 | 400 |
var EdgesDist: LongInt; |
4 | 401 |
begin |
678 | 402 |
if (not (CurrentTeam^.ExtDriven and isCursorVisible)) |
403 |
and cHasFocus then SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y); |
|
404 |
||
4 | 405 |
if (FollowGear <> nil) then |
57 | 406 |
if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then |
4 | 407 |
begin |
408 |
FollowGear:= nil; |
|
409 |
exit |
|
410 |
end |
|
411 |
else begin |
|
678 | 412 |
CursorPoint.x:= (prevPoint.x * 7 + (hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100) + WorldDx) div 8; |
413 |
CursorPoint.y:= (prevPoint.y * 7 + (hwRound(FollowGear^.Y) + WorldDy)) div 8 |
|
4 | 414 |
end; |
415 |
||
416 |
if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit; |
|
417 |
||
162 | 418 |
if AMxCurr < cScreenWidth then |
419 |
begin |
|
420 |
if CursorPoint.X < AMxCurr + 35 then CursorPoint.X:= AMxCurr + 35; |
|
421 |
if CursorPoint.X > AMxCurr + 200 then CursorPoint.X:= AMxCurr + 200; |
|
422 |
if CursorPoint.Y < cScreenHeight - 75 - SlotsNum * 33 then CursorPoint.Y:= cScreenHeight - 75 - SlotsNum * 33; |
|
423 |
if CursorPoint.Y > cScreenHeight - 76 then CursorPoint.Y:= cScreenHeight - 76; |
|
424 |
prevPoint:= CursorPoint; |
|
308 | 425 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
162 | 426 |
exit |
427 |
end; |
|
428 |
||
4 | 429 |
if isCursorVisible then |
430 |
begin |
|
351 | 431 |
if (not CurrentTeam^.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then |
4 | 432 |
begin |
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
146
diff
changeset
|
433 |
SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy); |
4 | 434 |
PrevSentPointTime:= GameTicks |
435 |
end; |
|
436 |
end; |
|
351 | 437 |
|
4 | 438 |
if isCursorVisible or (FollowGear <> nil) then |
439 |
begin |
|
284 | 440 |
if isCursorVisible then EdgesDist:= cCursorEdgesDist |
441 |
else EdgesDist:= cGearScrEdgesDist; |
|
442 |
if CursorPoint.X < EdgesDist then |
|
4 | 443 |
begin |
284 | 444 |
WorldDx:= WorldDx - CursorPoint.X + EdgesDist; |
445 |
CursorPoint.X:= EdgesDist |
|
4 | 446 |
end else |
284 | 447 |
if CursorPoint.X > cScreenWidth - EdgesDist then |
4 | 448 |
begin |
284 | 449 |
WorldDx:= WorldDx - CursorPoint.X + cScreenWidth - EdgesDist; |
450 |
CursorPoint.X:= cScreenWidth - EdgesDist |
|
4 | 451 |
end; |
284 | 452 |
if CursorPoint.Y < EdgesDist then |
4 | 453 |
begin |
284 | 454 |
WorldDy:= WorldDy - CursorPoint.Y + EdgesDist; |
455 |
CursorPoint.Y:= EdgesDist |
|
4 | 456 |
end else |
284 | 457 |
if CursorPoint.Y > cScreenHeight - EdgesDist then |
4 | 458 |
begin |
284 | 459 |
WorldDy:= WorldDy - CursorPoint.Y + cScreenHeight - EdgesDist; |
460 |
CursorPoint.Y:= cScreenHeight - EdgesDist |
|
4 | 461 |
end; |
462 |
end else |
|
308 | 463 |
if cHasFocus then |
464 |
begin |
|
70 | 465 |
WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; |
466 |
WorldDy:= WorldDy - CursorPoint.Y + prevPoint.Y; |
|
4 | 467 |
CursorPoint.X:= (cScreenWidth shr 1); |
468 |
CursorPoint.Y:= (cScreenHeight shr 1); |
|
308 | 469 |
end; |
351 | 470 |
|
308 | 471 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
4 | 472 |
prevPoint:= CursorPoint; |
75 | 473 |
if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater; |
4 | 474 |
if WorldDy > 2048 then WorldDy:= 2048; |
475 |
if WorldDx < -2048 then WorldDx:= -2048; |
|
476 |
if WorldDx > cScreenWidth then WorldDx:= cScreenWidth; |
|
477 |
end; |
|
478 |
||
479 |
initialization |
|
480 |
FillChar(Captions, sizeof(Captions), 0) |
|
481 |
||
482 |
end. |