author | unc0rr |
Sun, 27 Jul 2008 15:28:49 +0000 | |
changeset 1115 | 81fdeaa349a0 |
parent 1066 | 1f1b3686a2b0 |
child 1120 | eb5a9f86f9c6 |
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; |
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 |
|
1045 | 192 |
DrawVisualGears(0); |
803 | 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 |
|
1045 | 223 |
DrawVisualGears(1); |
224 |
||
5 | 225 |
// Waves |
4 | 226 |
{$WARNINGS OFF} |
841
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) + 64) and $FF), cWaterLine + WorldDy - 32, 0); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
228 |
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
|
229 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy , 0); |
4 | 230 |
{$WARNINGS ON} |
231 |
||
79 | 232 |
// Turn time |
4 | 233 |
if TurnTimeLeft <> 0 then |
234 |
begin |
|
235 |
i:= Succ(Pred(TurnTimeLeft) div 1000); |
|
236 |
if i>99 then t:= 112 |
|
237 |
else if i>9 then t:= 96 |
|
238 |
else t:= 80; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
239 |
DrawSprite(sprFrame, t, cScreenHeight - 48, 1); |
4 | 240 |
while i > 0 do |
241 |
begin |
|
242 |
dec(t, 32); |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
243 |
DrawSprite(sprBigDigit, t, cScreenHeight - 48, i mod 10); |
4 | 244 |
i:= i div 10 |
245 |
end; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
246 |
DrawSprite(sprFrame, t - 4, cScreenHeight - 48, 0); |
4 | 247 |
end; |
79 | 248 |
|
249 |
// Attack bar |
|
4 | 250 |
if CurrentTeam <> nil then |
251 |
case AttackBar of |
|
689 | 252 |
(* 1: begin |
4 | 253 |
r:= StuffPoz[sPowerBar]; |
254 |
{$WARNINGS OFF} |
|
602 | 255 |
r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor; |
4 | 256 |
{$WARNINGS ON} |
257 |
DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface); |
|
258 |
end; |
|
689 | 259 |
*) 2: with CurrentHedgehog^ do |
74 | 260 |
begin |
351 | 261 |
tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle); |
262 |
tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle); |
|
263 |
for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do |
|
762 | 264 |
DrawSprite(sprPower, hwRound(Gear^.X) + system.round(WorldDx + tdx * (24 + i * 2)) - 16, |
265 |
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
|
266 |
i) |
74 | 267 |
end |
4 | 268 |
end; |
269 |
||
5 | 270 |
// Target |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
271 |
if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0); |
4 | 272 |
|
777 | 273 |
//glPopMatrix; |
274 |
||
4 | 275 |
// Captions |
175 | 276 |
i:= 8; |
277 |
for grp:= Low(TCapGroup) to High(TCapGroup) do |
|
278 |
with Captions[grp] do |
|
762 | 279 |
if Tex <> nil then |
175 | 280 |
begin |
988 | 281 |
DrawCentered(cScreenWidth div 2, i, Tex); |
762 | 282 |
inc(i, Tex^.h + 2); |
564 | 283 |
if EndTime <= RealTicks then |
175 | 284 |
begin |
762 | 285 |
FreeTexture(Tex); |
286 |
Tex:= nil; |
|
175 | 287 |
EndTime:= 0 |
288 |
end |
|
289 |
end; |
|
4 | 290 |
|
47 | 291 |
// Teams Healths |
547 | 292 |
for t:= 0 to Pred(TeamsCount) do |
293 |
with TeamsArray[t]^ do |
|
47 | 294 |
begin |
762 | 295 |
DrawTexture(cScreenWidth div 2 - NameTagTex^.w - 3, DrawHealthY, NameTagTex); |
690 | 296 |
|
297 |
r.x:= 0; |
|
298 |
r.y:= 0; |
|
547 | 299 |
r.w:= 2 + TeamHealthBarWidth; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
300 |
r.h:= HealthTex^.h; |
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, |
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); |
690 | 305 |
|
83 | 306 |
inc(r.x, cTeamHealthWidth + 2); |
307 |
r.w:= 3; |
|
690 | 308 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
309 |
DrawFromRect(cScreenWidth div 2 + TeamHealthBarWidth + 2, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
310 |
DrawHealthY, |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
311 |
@r, HealthTex); |
47 | 312 |
end; |
313 |
||
5 | 314 |
// Lag alert |
988 | 315 |
if isInLag then DrawSprite(sprLag, 32, 32, (RealTicks shr 7) mod 12); |
4 | 316 |
|
5 | 317 |
// Wind bar |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
318 |
DrawSprite(sprWindBar, cScreenWidth - 180, cScreenHeight - 30, 0); |
6 | 319 |
if WindBarWidth > 0 then |
5 | 320 |
begin |
689 | 321 |
{$WARNINGS OFF} |
322 |
r.x:= 8 - (RealTicks shr 6) mod 8; |
|
323 |
{$WARNINGS ON} |
|
324 |
r.y:= 0; |
|
325 |
r.w:= WindBarWidth; |
|
326 |
r.h:= 13; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
327 |
DrawSpriteFromRect(sprWindR, r, cScreenWidth - 103, cScreenHeight - 28, 13, 0); |
5 | 328 |
end else |
6 | 329 |
if WindBarWidth < 0 then |
5 | 330 |
begin |
689 | 331 |
{$WARNINGS OFF} |
332 |
r.x:= (WindBarWidth + RealTicks shr 6) mod 8; |
|
333 |
{$WARNINGS ON} |
|
334 |
r.y:= 0; |
|
335 |
r.w:= - WindBarWidth; |
|
336 |
r.h:= 13; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
337 |
DrawSpriteFromRect(sprWindL, r, cScreenWidth - 106 + WindBarWidth, cScreenHeight - 28, 13, 0); |
5 | 338 |
end; |
339 |
||
161 | 340 |
// AmmoMenu |
956 | 341 |
if (AMxCurr < cScreenWidth) or bShowAmmoMenu then ShowAmmoMenu; |
161 | 342 |
|
942 | 343 |
DrawChat; |
344 |
||
5 | 345 |
// Cursor |
408 | 346 |
if isCursorVisible then |
347 |
begin |
|
348 |
if not bShowAmmoMenu then |
|
602 | 349 |
with CurrentHedgehog^ do |
408 | 350 |
if (Gear^.State and gstHHChooseTarget) <> 0 then |
351 |
begin |
|
352 |
i:= Ammo^[CurSlot, CurAmmo].Pos; |
|
353 |
with Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType] do |
|
354 |
if PosCount > 1 then |
|
762 | 355 |
DrawSprite(PosSprite, CursorPoint.X - SpritesData[PosSprite].Width div 2, |
356 |
CursorPoint.Y - SpritesData[PosSprite].Height div 2, |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
357 |
i); |
408 | 358 |
end; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
359 |
DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8) |
408 | 360 |
end; |
4 | 361 |
|
762 | 362 |
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
|
363 |
|
4 | 364 |
inc(Frames); |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
365 |
if cShowFPS then |
4 | 366 |
begin |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
367 |
inc(CountTicks, Lag); |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
368 |
if CountTicks >= 1000 then |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
369 |
begin |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
370 |
FPS:= Frames; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
371 |
Frames:= 0; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
372 |
CountTicks:= 0; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
373 |
s:= inttostr(FPS) + ' fps'; |
759 | 374 |
if fpsTexture <> nil then FreeTexture(fpsTexture); |
375 |
tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), $FFFFFF); |
|
376 |
fpsTexture:= Surface2Tex(tmpSurface); |
|
377 |
SDL_FreeSurface(tmpSurface) |
|
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
378 |
end; |
759 | 379 |
if fpsTexture <> nil then |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
803
diff
changeset
|
380 |
DrawTexture(cScreenWidth - 50, 10, fpsTexture); |
4 | 381 |
end; |
174 | 382 |
|
383 |
inc(SoundTimerTicks, Lag); |
|
384 |
if SoundTimerTicks >= 50 then |
|
385 |
begin |
|
386 |
SoundTimerTicks:= 0; |
|
387 |
if cVolumeDelta <> 0 then |
|
388 |
begin |
|
389 |
str(ChangeVolume(cVolumeDelta), s); |
|
175 | 390 |
AddCaption(Format(trmsg[sidVolume], s), $FFFFFF, capgrpVolume) |
174 | 391 |
end |
756 | 392 |
end; |
393 |
||
1023 | 394 |
if GameState = gsConfirm then DrawCentered(cScreenWidth div 2, cScreenHeight div 2, ConfirmTexture); |
395 |
||
775 | 396 |
glDisable(GL_TEXTURE_2D); |
756 | 397 |
glDisable(GL_BLEND) |
4 | 398 |
end; |
399 |
||
108 | 400 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
4 | 401 |
begin |
83 | 402 |
if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s); |
762 | 403 |
if Captions[Group].Tex <> nil then FreeTexture(Captions[Group].Tex); |
4 | 404 |
|
762 | 405 |
Captions[Group].Tex:= RenderStringTex(s, Color, fntBig); |
564 | 406 |
Captions[Group].EndTime:= RealTicks + 1500 |
4 | 407 |
end; |
408 |
||
79 | 409 |
procedure MoveCamera; |
4 | 410 |
const PrevSentPointTime: LongWord = 0; |
371 | 411 |
var EdgesDist: LongInt; |
4 | 412 |
begin |
678 | 413 |
if (not (CurrentTeam^.ExtDriven and isCursorVisible)) |
414 |
and cHasFocus then SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y); |
|
415 |
||
4 | 416 |
if (FollowGear <> nil) then |
57 | 417 |
if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then |
4 | 418 |
begin |
419 |
FollowGear:= nil; |
|
420 |
exit |
|
421 |
end |
|
422 |
else begin |
|
678 | 423 |
CursorPoint.x:= (prevPoint.x * 7 + (hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100) + WorldDx) div 8; |
424 |
CursorPoint.y:= (prevPoint.y * 7 + (hwRound(FollowGear^.Y) + WorldDy)) div 8 |
|
4 | 425 |
end; |
426 |
||
427 |
if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit; |
|
428 |
||
162 | 429 |
if AMxCurr < cScreenWidth then |
430 |
begin |
|
431 |
if CursorPoint.X < AMxCurr + 35 then CursorPoint.X:= AMxCurr + 35; |
|
432 |
if CursorPoint.X > AMxCurr + 200 then CursorPoint.X:= AMxCurr + 200; |
|
433 |
if CursorPoint.Y < cScreenHeight - 75 - SlotsNum * 33 then CursorPoint.Y:= cScreenHeight - 75 - SlotsNum * 33; |
|
434 |
if CursorPoint.Y > cScreenHeight - 76 then CursorPoint.Y:= cScreenHeight - 76; |
|
435 |
prevPoint:= CursorPoint; |
|
308 | 436 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
162 | 437 |
exit |
438 |
end; |
|
439 |
||
4 | 440 |
if isCursorVisible then |
441 |
begin |
|
351 | 442 |
if (not CurrentTeam^.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then |
4 | 443 |
begin |
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
146
diff
changeset
|
444 |
SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy); |
4 | 445 |
PrevSentPointTime:= GameTicks |
446 |
end; |
|
447 |
end; |
|
351 | 448 |
|
4 | 449 |
if isCursorVisible or (FollowGear <> nil) then |
450 |
begin |
|
284 | 451 |
if isCursorVisible then EdgesDist:= cCursorEdgesDist |
452 |
else EdgesDist:= cGearScrEdgesDist; |
|
453 |
if CursorPoint.X < EdgesDist then |
|
4 | 454 |
begin |
284 | 455 |
WorldDx:= WorldDx - CursorPoint.X + EdgesDist; |
456 |
CursorPoint.X:= EdgesDist |
|
4 | 457 |
end else |
284 | 458 |
if CursorPoint.X > cScreenWidth - EdgesDist then |
4 | 459 |
begin |
284 | 460 |
WorldDx:= WorldDx - CursorPoint.X + cScreenWidth - EdgesDist; |
461 |
CursorPoint.X:= cScreenWidth - EdgesDist |
|
4 | 462 |
end; |
284 | 463 |
if CursorPoint.Y < EdgesDist then |
4 | 464 |
begin |
284 | 465 |
WorldDy:= WorldDy - CursorPoint.Y + EdgesDist; |
466 |
CursorPoint.Y:= EdgesDist |
|
4 | 467 |
end else |
284 | 468 |
if CursorPoint.Y > cScreenHeight - EdgesDist then |
4 | 469 |
begin |
284 | 470 |
WorldDy:= WorldDy - CursorPoint.Y + cScreenHeight - EdgesDist; |
471 |
CursorPoint.Y:= cScreenHeight - EdgesDist |
|
4 | 472 |
end; |
473 |
end else |
|
308 | 474 |
if cHasFocus then |
475 |
begin |
|
70 | 476 |
WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; |
477 |
WorldDy:= WorldDy - CursorPoint.Y + prevPoint.Y; |
|
4 | 478 |
CursorPoint.X:= (cScreenWidth shr 1); |
479 |
CursorPoint.Y:= (cScreenHeight shr 1); |
|
308 | 480 |
end; |
351 | 481 |
|
308 | 482 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
4 | 483 |
prevPoint:= CursorPoint; |
75 | 484 |
if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater; |
4 | 485 |
if WorldDy > 2048 then WorldDy:= 2048; |
486 |
if WorldDx < -2048 then WorldDx:= -2048; |
|
487 |
if WorldDx > cScreenWidth then WorldDx:= cScreenWidth; |
|
488 |
end; |
|
489 |
||
490 |
initialization |
|
491 |
FillChar(Captions, sizeof(Captions), 0) |
|
492 |
||
493 |
end. |