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