author | unc0rr |
Sun, 26 Oct 2008 14:45:07 +0000 | |
changeset 1418 | 69df8f2a7cba |
parent 1256 | 2754a6a8c8f1 |
child 1439 | 340c47ad5600 |
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; |
|
1256 | 34 |
WindBarWidth: LongInt = 0; |
35 |
bShowAmmoMenu: boolean = false; |
|
36 |
bSelected: boolean = false; |
|
37 |
bShowFinger: boolean = false; |
|
38 |
Frames: Longword = 0; |
|
39 |
WaterColor, DeepWaterColor: TSDL_Color; |
|
4 | 40 |
|
41 |
implementation |
|
803 | 42 |
uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, GL, |
942 | 43 |
uAmmos, uVisualGears, uChat; |
564 | 44 |
const FPS: Longword = 0; |
4 | 45 |
CountTicks: Longword = 0; |
174 | 46 |
SoundTimerTicks: Longword = 0; |
4 | 47 |
prevPoint: TPoint = (X: 0; Y: 0); |
161 | 48 |
|
4 | 49 |
type TCaptionStr = record |
762 | 50 |
Tex: PTexture; |
4 | 51 |
EndTime: LongWord; |
52 |
end; |
|
53 |
||
371 | 54 |
var cWaterSprCount: LongInt; |
1256 | 55 |
Captions: array[TCapGroup] of TCaptionStr; |
56 |
AMxShift, SlotsNum: LongInt; |
|
57 |
tmpSurface: PSDL_Surface; |
|
58 |
fpsTexture: PTexture = nil; |
|
4 | 59 |
|
60 |
procedure InitWorld; |
|
61 |
begin |
|
74 | 62 |
cWaterSprCount:= 1 + cScreenWidth div (SpritesData[sprWater].Width); |
284 | 63 |
cGearScrEdgesDist:= Min(cScreenWidth div 2 - 100, cScreenHeight div 2 - 50); |
74 | 64 |
SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
65 |
prevPoint.X:= cScreenWidth div 2; |
|
66 |
prevPoint.Y:= cScreenHeight div 2; |
|
67 |
WorldDx:= - 1024 + cScreenWidth div 2; |
|
161 | 68 |
WorldDy:= - 512 + cScreenHeight div 2; |
1120 | 69 |
AMxShift:= 210 |
161 | 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 |
|
1120 | 80 |
if AMxShift = 210 then prevPoint.X:= 0; |
81 |
if AMxShift > 0 then dec(AMxShift, MENUSPEED); |
|
165 | 82 |
end else |
83 |
begin |
|
1120 | 84 |
if AMxShift = 0 then |
165 | 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; |
|
1120 | 91 |
if AMxShift < 210 then inc(AMxShift, MENUSPEED); |
165 | 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; |
1120 | 101 |
x:= cScreenWidth - 210 + AMxShift; |
161 | 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 |
961
a9a349b2b3fa
Use turnsleft sprites to indicate turns left to activate ammo
unc0rr
parents:
956
diff
changeset
|
120 |
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
|
121 |
|
a9a349b2b3fa
Use turnsleft sprites to indicate turns left to activate ammo
unc0rr
parents:
956
diff
changeset
|
122 |
if l >= 0 then |
1125 | 123 |
begin |
124 |
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
|
125 |
DrawSprite(sprTurnsLeft, x + t * 33 + 51, y + 17, l); |
1125 | 126 |
end else |
127 |
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
|
128 |
|
162 | 129 |
if (Slot = i) and (CursorPoint.X >= x + t * 33 + 35) and (CursorPoint.X < x + t * 33 + 68) then |
130 |
begin |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
131 |
DrawSprite(sprAMSelection, x + t * 33 + 35, y + 1, 0); |
162 | 132 |
Pos:= t; |
133 |
end; |
|
161 | 134 |
inc(t) |
135 |
end |
|
136 |
end; |
|
137 |
dec(y, 1); |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
138 |
DrawSprite(sprAMBorders, x, y, 0); |
162 | 139 |
|
140 |
if (Pos >= 0) then |
|
351 | 141 |
if Ammo^[Slot, Pos].Count > 0 then |
162 | 142 |
begin |
1120 | 143 |
DrawTexture(cScreenWidth - 200 + AMxShift, cScreenHeight - 68, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex); |
965 | 144 |
if Ammo^[Slot, Pos].Count < AMMO_INFINITE then |
1120 | 145 |
DrawTexture(cScreenWidth + AMxShift - 35, cScreenHeight - 68, CountTexz[Ammo^[Slot, Pos].Count]); |
162 | 146 |
if bSelected then |
147 |
begin |
|
165 | 148 |
bShowAmmoMenu:= false; |
351 | 149 |
SetWeapon(Ammo^[Slot, Pos].AmmoType); |
165 | 150 |
bSelected:= false; |
151 |
exit |
|
162 | 152 |
end; |
153 |
end; |
|
154 |
end; |
|
155 |
||
156 |
bSelected:= false; |
|
1120 | 157 |
if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8) |
4 | 158 |
end; |
159 |
||
162 | 160 |
procedure MoveCamera; forward; |
161 |
||
956 | 162 |
procedure DrawWorld(Lag: LongInt); |
371 | 163 |
var i, t: LongInt; |
4 | 164 |
r: TSDL_Rect; |
107 | 165 |
tdx, tdy: Double; |
175 | 166 |
grp: TCapGroup; |
174 | 167 |
s: string[15]; |
80 | 168 |
|
371 | 169 |
procedure DrawRepeated(spr: TSprite; Shift: LongInt); |
170 |
var i, w: LongInt; |
|
80 | 171 |
begin |
172 |
w:= SpritesData[spr].Width; |
|
82 | 173 |
i:= Shift mod w; |
80 | 174 |
if i > 0 then dec(i, w); |
175 |
repeat |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
176 |
DrawSprite(spr, i, WorldDy + 1024 - SpritesData[spr].Height, 0); |
80 | 177 |
inc(i, w) |
178 |
until i > cScreenWidth |
|
179 |
end; |
|
180 |
||
4 | 181 |
begin |
770 | 182 |
// Sky |
756 | 183 |
glClear(GL_COLOR_BUFFER_BIT); |
184 |
glEnable(GL_BLEND); |
|
775 | 185 |
glEnable(GL_TEXTURE_2D); |
777 | 186 |
//glPushMatrix; |
187 |
//glScalef(1.0, 1.0, 1.0); |
|
756 | 188 |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
244
diff
changeset
|
189 |
if not isPaused then MoveCamera; |
162 | 190 |
|
5 | 191 |
// background |
755 | 192 |
DrawRepeated(sprSky, WorldDx * 3 div 8); |
193 |
DrawRepeated(sprHorizont, WorldDx * 3 div 5); |
|
4 | 194 |
|
1045 | 195 |
DrawVisualGears(0); |
803 | 196 |
|
5 | 197 |
// Waves |
4 | 198 |
{$WARNINGS OFF} |
841
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) ) and $FF), cWaterLine + WorldDy - 64, 0); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
200 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 192) and $FF), cWaterLine + WorldDy - 48, 0); |
4 | 201 |
{$WARNINGS ON} |
202 |
||
762 | 203 |
DrawLand(WorldDx, WorldDy); |
5 | 204 |
// Water |
4 | 205 |
r.y:= WorldDy + cWaterLine + 32; |
206 |
if r.y < cScreenHeight then |
|
207 |
begin |
|
23 | 208 |
if r.y < 0 then r.y:= 0; |
780 | 209 |
|
210 |
glDisable(GL_TEXTURE_2D); |
|
211 |
glBegin(GL_QUADS); |
|
1256 | 212 |
glColor3ub(WaterColor.r, WaterColor.g, WaterColor. b); // water color |
780 | 213 |
glVertex2i(0, r.y); |
214 |
glVertex2i(cScreenWidth, r.y); |
|
1256 | 215 |
glColor3ub(DeepWaterColor.r, DeepWaterColor.g, DeepWaterColor. b); // deep water color |
780 | 216 |
glVertex2i(cScreenWidth, cScreenHeight); |
217 |
glVertex2i(0, cScreenHeight); |
|
218 |
glEnd(); |
|
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. |