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