author | unc0rr |
Wed, 05 Mar 2008 19:34:52 +0000 | |
changeset 797 | e7fa1a1b9791 |
parent 793 | c4a790225799 |
child 803 | 3f73901a350a |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
393 | 3 |
* Copyright (c) 2004-2007 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
19 |
unit uWorld; |
|
20 |
interface |
|
351 | 21 |
uses SDLh, uGears, uConsts, uFloat; |
4 | 22 |
{$INCLUDE options.inc} |
371 | 23 |
const WorldDx: LongInt = -512; |
24 |
WorldDy: LongInt = -256; |
|
4 | 25 |
|
26 |
procedure InitWorld; |
|
371 | 27 |
procedure DrawWorld(Lag: LongInt; Surface: PSDL_Surface); |
108 | 28 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
4 | 29 |
|
30 |
{$IFDEF COUNTTICKS} |
|
31 |
var cntTicks: LongWord; |
|
32 |
{$ENDIF} |
|
33 |
var FollowGear: PGear = nil; |
|
371 | 34 |
WindBarWidth: LongInt = 0; |
161 | 35 |
bShowAmmoMenu: boolean = false; |
162 | 36 |
bSelected: boolean = false; |
176 | 37 |
bShowFinger: boolean = false; |
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
183
diff
changeset
|
38 |
Frames: Longword = 0; |
4 | 39 |
|
40 |
implementation |
|
783 | 41 |
uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, GL, uAmmos; |
564 | 42 |
const FPS: Longword = 0; |
4 | 43 |
CountTicks: Longword = 0; |
174 | 44 |
SoundTimerTicks: Longword = 0; |
4 | 45 |
prevPoint: TPoint = (X: 0; Y: 0); |
161 | 46 |
|
4 | 47 |
type TCaptionStr = record |
762 | 48 |
Tex: PTexture; |
4 | 49 |
EndTime: LongWord; |
50 |
end; |
|
51 |
||
371 | 52 |
var cWaterSprCount: LongInt; |
175 | 53 |
Captions: array[TCapGroup] of TCaptionStr; |
371 | 54 |
AMxLeft, AMxCurr, SlotsNum: LongInt; |
759 | 55 |
tmpSurface: PSDL_Surface; |
56 |
fpsTexture: PTexture = nil; |
|
4 | 57 |
|
58 |
procedure InitWorld; |
|
59 |
begin |
|
74 | 60 |
cWaterSprCount:= 1 + cScreenWidth div (SpritesData[sprWater].Width); |
284 | 61 |
cGearScrEdgesDist:= Min(cScreenWidth div 2 - 100, cScreenHeight div 2 - 50); |
74 | 62 |
SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
63 |
prevPoint.X:= cScreenWidth div 2; |
|
64 |
prevPoint.Y:= cScreenHeight div 2; |
|
65 |
WorldDx:= - 1024 + cScreenWidth div 2; |
|
161 | 66 |
WorldDy:= - 512 + cScreenHeight div 2; |
67 |
AMxLeft:= cScreenWidth - 210; |
|
68 |
AMxCurr:= cScreenWidth |
|
69 |
end; |
|
70 |
||
71 |
procedure ShowAmmoMenu(Surface: PSDL_Surface); |
|
72 |
const MENUSPEED = 15; |
|
371 | 73 |
var x, y, i, t: LongInt; |
74 |
Slot, Pos: LongInt; |
|
161 | 75 |
begin |
76 |
if (TurnTimeLeft = 0) or KbdKeyPressed then bShowAmmoMenu:= false; |
|
165 | 77 |
if bShowAmmoMenu then |
78 |
begin |
|
79 |
if AMxCurr = cScreenWidth then prevPoint.X:= 0; |
|
80 |
if AMxCurr > AMxLeft then dec(AMxCurr, MENUSPEED); |
|
81 |
end else |
|
82 |
begin |
|
83 |
if AMxCurr = AMxLeft then |
|
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; |
|
90 |
if AMxCurr < cScreenWidth then inc(AMxCurr, MENUSPEED); |
|
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; |
161 | 100 |
x:= AMxCurr; |
101 |
y:= cScreenHeight - 40; |
|
102 |
dec(y); |
|
103 |
DrawSprite(sprAMBorders, x, y, 0, Surface); |
|
104 |
dec(y); |
|
105 |
DrawSprite(sprAMBorders, x, y, 1, Surface); |
|
106 |
dec(y, 33); |
|
107 |
DrawSprite(sprAMSlotName, x, y, 0, Surface); |
|
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); |
161 | 114 |
DrawSprite(sprAMSlot, x, y, 0, Surface); |
115 |
DrawSprite(sprAMSlotKeys, x + 2, y + 1, i, Surface); |
|
116 |
t:= 0; |
|
351 | 117 |
while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do |
161 | 118 |
begin |
371 | 119 |
DrawSprite(sprAMAmmos, x + t * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType), Surface); |
162 | 120 |
if (Slot = i) and (CursorPoint.X >= x + t * 33 + 35) and (CursorPoint.X < x + t * 33 + 68) then |
121 |
begin |
|
122 |
DrawSprite(sprAMSelection, x + t * 33 + 35, y + 1, 0, Surface); |
|
123 |
Pos:= t; |
|
124 |
end; |
|
161 | 125 |
inc(t) |
126 |
end |
|
127 |
end; |
|
128 |
dec(y, 1); |
|
162 | 129 |
DrawSprite(sprAMBorders, x, y, 0, Surface); |
130 |
||
131 |
if (Pos >= 0) then |
|
351 | 132 |
if Ammo^[Slot, Pos].Count > 0 then |
162 | 133 |
begin |
351 | 134 |
DXOutText(AMxCurr + 10, cScreenHeight - 68, fnt16, trAmmo[Ammoz[Ammo^[Slot, Pos].AmmoType].NameId], Surface); |
135 |
if Ammo^[Slot, Pos].Count < 10 then |
|
136 |
DXOutText(AMxCurr + 175, cScreenHeight - 68, fnt16, chr(Ammo^[Slot, Pos].Count + 48) + 'x', Surface); |
|
162 | 137 |
if bSelected then |
138 |
begin |
|
165 | 139 |
bShowAmmoMenu:= false; |
351 | 140 |
SetWeapon(Ammo^[Slot, Pos].AmmoType); |
165 | 141 |
bSelected:= false; |
142 |
exit |
|
162 | 143 |
end; |
144 |
end; |
|
145 |
end; |
|
146 |
||
147 |
bSelected:= false; |
|
564 | 148 |
if AMxLeft = AMxCurr then DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface) |
4 | 149 |
end; |
150 |
||
162 | 151 |
procedure MoveCamera; forward; |
152 |
||
371 | 153 |
procedure DrawWorld(Lag: LongInt; Surface: PSDL_Surface); |
154 |
var i, t: LongInt; |
|
4 | 155 |
r: TSDL_Rect; |
107 | 156 |
tdx, tdy: Double; |
175 | 157 |
grp: TCapGroup; |
174 | 158 |
s: string[15]; |
80 | 159 |
|
371 | 160 |
procedure DrawRepeated(spr: TSprite; Shift: LongInt); |
161 |
var i, w: LongInt; |
|
80 | 162 |
begin |
163 |
w:= SpritesData[spr].Width; |
|
82 | 164 |
i:= Shift mod w; |
80 | 165 |
if i > 0 then dec(i, w); |
166 |
repeat |
|
167 |
DrawSprite(spr, i, WorldDy + 1024 - SpritesData[spr].Height, 0, Surface); |
|
168 |
inc(i, w) |
|
169 |
until i > cScreenWidth |
|
170 |
end; |
|
171 |
||
4 | 172 |
begin |
770 | 173 |
// Sky |
756 | 174 |
glClear(GL_COLOR_BUFFER_BIT); |
175 |
glEnable(GL_BLEND); |
|
775 | 176 |
glEnable(GL_TEXTURE_2D); |
777 | 177 |
//glPushMatrix; |
178 |
//glScalef(1.0, 1.0, 1.0); |
|
756 | 179 |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
244
diff
changeset
|
180 |
if not isPaused then MoveCamera; |
162 | 181 |
|
5 | 182 |
// background |
755 | 183 |
DrawRepeated(sprSky, WorldDx * 3 div 8); |
184 |
DrawRepeated(sprHorizont, WorldDx * 3 div 5); |
|
4 | 185 |
|
5 | 186 |
// Waves |
4 | 187 |
{$WARNINGS OFF} |
757 | 188 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy - 64, 0, Surface); |
189 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 192) and $FF), cWaterLine + WorldDy - 48, 0, Surface); |
|
4 | 190 |
{$WARNINGS ON} |
191 |
||
762 | 192 |
DrawLand(WorldDx, WorldDy); |
5 | 193 |
// Water |
4 | 194 |
r.y:= WorldDy + cWaterLine + 32; |
195 |
if r.y < cScreenHeight then |
|
196 |
begin |
|
23 | 197 |
if r.y < 0 then r.y:= 0; |
780 | 198 |
|
199 |
glDisable(GL_TEXTURE_2D); |
|
200 |
glBegin(GL_QUADS); |
|
793 | 201 |
glColor3ub($54, $5C, $9D); // water color |
780 | 202 |
glVertex2i(0, r.y); |
203 |
glVertex2i(cScreenWidth, r.y); |
|
793 | 204 |
glColor3ub($34, $3C, $7D); // deep water color |
780 | 205 |
glVertex2i(cScreenWidth, cScreenHeight); |
206 |
glVertex2i(0, cScreenHeight); |
|
207 |
glEnd(); |
|
208 |
||
209 |
glColor4f(1, 1, 1, 1); // disable coloring |
|
210 |
glEnable(GL_TEXTURE_2D) |
|
4 | 211 |
end; |
212 |
||
755 | 213 |
DrawGears(Surface); |
4 | 214 |
|
5 | 215 |
// Waves |
4 | 216 |
{$WARNINGS OFF} |
757 | 217 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) + 64) and $FF), cWaterLine + WorldDy - 32, 0, Surface); |
218 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 128) and $FF), cWaterLine + WorldDy - 16, 0, Surface); |
|
219 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy , 0, Surface); |
|
4 | 220 |
{$WARNINGS ON} |
221 |
||
79 | 222 |
// Turn time |
4 | 223 |
if TurnTimeLeft <> 0 then |
224 |
begin |
|
225 |
i:= Succ(Pred(TurnTimeLeft) div 1000); |
|
226 |
if i>99 then t:= 112 |
|
227 |
else if i>9 then t:= 96 |
|
228 |
else t:= 80; |
|
770 | 229 |
DrawSprite(sprFrame, t, cScreenHeight - 48, 1, Surface); |
4 | 230 |
while i > 0 do |
231 |
begin |
|
232 |
dec(t, 32); |
|
233 |
DrawSprite(sprBigDigit, t, cScreenHeight - 48, i mod 10, Surface); |
|
234 |
i:= i div 10 |
|
235 |
end; |
|
770 | 236 |
DrawSprite(sprFrame, t - 4, cScreenHeight - 48, 0, Surface); |
4 | 237 |
end; |
79 | 238 |
|
239 |
// Attack bar |
|
4 | 240 |
if CurrentTeam <> nil then |
241 |
case AttackBar of |
|
689 | 242 |
(* 1: begin |
4 | 243 |
r:= StuffPoz[sPowerBar]; |
244 |
{$WARNINGS OFF} |
|
602 | 245 |
r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor; |
4 | 246 |
{$WARNINGS ON} |
247 |
DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface); |
|
248 |
end; |
|
689 | 249 |
*) 2: with CurrentHedgehog^ do |
74 | 250 |
begin |
351 | 251 |
tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle); |
252 |
tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle); |
|
253 |
for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do |
|
762 | 254 |
DrawSprite(sprPower, hwRound(Gear^.X) + system.round(WorldDx + tdx * (24 + i * 2)) - 16, |
255 |
hwRound(Gear^.Y) + system.round(WorldDy + tdy * (24 + i * 2)) - 12, |
|
256 |
i, Surface) |
|
74 | 257 |
end |
4 | 258 |
end; |
259 |
||
5 | 260 |
// Target |
762 | 261 |
if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0, Surface); |
4 | 262 |
|
777 | 263 |
//glPopMatrix; |
264 |
||
4 | 265 |
// Captions |
175 | 266 |
i:= 8; |
267 |
for grp:= Low(TCapGroup) to High(TCapGroup) do |
|
268 |
with Captions[grp] do |
|
762 | 269 |
if Tex <> nil then |
175 | 270 |
begin |
762 | 271 |
DrawCentered(cScreenWidth div 2, i + cConsoleYAdd, Tex); |
272 |
inc(i, Tex^.h + 2); |
|
564 | 273 |
if EndTime <= RealTicks then |
175 | 274 |
begin |
762 | 275 |
FreeTexture(Tex); |
276 |
Tex:= nil; |
|
175 | 277 |
EndTime:= 0 |
278 |
end |
|
279 |
end; |
|
4 | 280 |
|
47 | 281 |
// Teams Healths |
547 | 282 |
for t:= 0 to Pred(TeamsCount) do |
283 |
with TeamsArray[t]^ do |
|
47 | 284 |
begin |
762 | 285 |
DrawTexture(cScreenWidth div 2 - NameTagTex^.w - 3, DrawHealthY, NameTagTex); |
690 | 286 |
|
287 |
r.x:= 0; |
|
288 |
r.y:= 0; |
|
547 | 289 |
r.w:= 2 + TeamHealthBarWidth; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
290 |
r.h:= HealthTex^.h; |
690 | 291 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
292 |
DrawFromRect(cScreenWidth div 2, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
293 |
DrawHealthY, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
294 |
@r, HealthTex, Surface); |
690 | 295 |
|
83 | 296 |
inc(r.x, cTeamHealthWidth + 2); |
297 |
r.w:= 3; |
|
690 | 298 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
299 |
DrawFromRect(cScreenWidth div 2 + TeamHealthBarWidth + 2, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
300 |
DrawHealthY, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
301 |
@r, HealthTex, Surface); |
47 | 302 |
end; |
303 |
||
5 | 304 |
// Lag alert |
762 | 305 |
if isInLag then DrawSprite(sprLag, 32, 32 + cConsoleYAdd, (RealTicks shr 7) mod 12, Surface); |
4 | 306 |
|
5 | 307 |
// Wind bar |
762 | 308 |
DrawSprite(sprWindBar, cScreenWidth - 180, cScreenHeight - 30, 0, Surface); |
6 | 309 |
if WindBarWidth > 0 then |
5 | 310 |
begin |
689 | 311 |
{$WARNINGS OFF} |
312 |
r.x:= 8 - (RealTicks shr 6) mod 8; |
|
313 |
{$WARNINGS ON} |
|
314 |
r.y:= 0; |
|
315 |
r.w:= WindBarWidth; |
|
316 |
r.h:= 13; |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
317 |
DrawSpriteFromRect(sprWindR, r, cScreenWidth - 103, cScreenHeight - 28, 13, 0, Surface); |
5 | 318 |
end else |
6 | 319 |
if WindBarWidth < 0 then |
5 | 320 |
begin |
689 | 321 |
{$WARNINGS OFF} |
322 |
r.x:= (WindBarWidth + RealTicks shr 6) mod 8; |
|
323 |
{$WARNINGS ON} |
|
324 |
r.y:= 0; |
|
325 |
r.w:= - WindBarWidth; |
|
326 |
r.h:= 13; |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
327 |
DrawSpriteFromRect(sprWindL, r, cScreenWidth - 106 + WindBarWidth, cScreenHeight - 28, 13, 0, Surface); |
5 | 328 |
end; |
329 |
||
161 | 330 |
// AmmoMenu |
770 | 331 |
if (AMxCurr < cScreenWidth) or bShowAmmoMenu then ShowAmmoMenu(Surface); |
161 | 332 |
|
5 | 333 |
// Cursor |
408 | 334 |
if isCursorVisible then |
335 |
begin |
|
336 |
if not bShowAmmoMenu then |
|
602 | 337 |
with CurrentHedgehog^ do |
408 | 338 |
if (Gear^.State and gstHHChooseTarget) <> 0 then |
339 |
begin |
|
340 |
i:= Ammo^[CurSlot, CurAmmo].Pos; |
|
341 |
with Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType] do |
|
342 |
if PosCount > 1 then |
|
762 | 343 |
DrawSprite(PosSprite, CursorPoint.X - SpritesData[PosSprite].Width div 2, |
344 |
CursorPoint.Y - SpritesData[PosSprite].Height div 2, |
|
345 |
i, Surface); |
|
408 | 346 |
end; |
762 | 347 |
DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface) |
408 | 348 |
end; |
4 | 349 |
|
762 | 350 |
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
|
351 |
|
4 | 352 |
inc(Frames); |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
353 |
if cShowFPS then |
4 | 354 |
begin |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
355 |
inc(CountTicks, Lag); |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
356 |
if CountTicks >= 1000 then |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
357 |
begin |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
358 |
FPS:= Frames; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
359 |
Frames:= 0; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
360 |
CountTicks:= 0; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
361 |
s:= inttostr(FPS) + ' fps'; |
759 | 362 |
if fpsTexture <> nil then FreeTexture(fpsTexture); |
363 |
tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), $FFFFFF); |
|
364 |
fpsTexture:= Surface2Tex(tmpSurface); |
|
365 |
SDL_FreeSurface(tmpSurface) |
|
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
366 |
end; |
759 | 367 |
if fpsTexture <> nil then |
368 |
begin |
|
369 |
r.x:= 0; |
|
370 |
r.y:= 0; |
|
371 |
r.w:= fpsTexture^.w; |
|
372 |
r.h:= fpsTexture^.h; |
|
373 |
DrawFromRect(cScreenWidth - 50, 10, @r, fpsTexture, Surface); |
|
374 |
end |
|
4 | 375 |
end; |
174 | 376 |
|
377 |
inc(SoundTimerTicks, Lag); |
|
378 |
if SoundTimerTicks >= 50 then |
|
379 |
begin |
|
380 |
SoundTimerTicks:= 0; |
|
381 |
if cVolumeDelta <> 0 then |
|
382 |
begin |
|
383 |
str(ChangeVolume(cVolumeDelta), s); |
|
175 | 384 |
AddCaption(Format(trmsg[sidVolume], s), $FFFFFF, capgrpVolume) |
174 | 385 |
end |
756 | 386 |
end; |
387 |
||
775 | 388 |
glDisable(GL_TEXTURE_2D); |
756 | 389 |
glDisable(GL_BLEND) |
4 | 390 |
end; |
391 |
||
108 | 392 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
4 | 393 |
begin |
83 | 394 |
if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s); |
762 | 395 |
if Captions[Group].Tex <> nil then FreeTexture(Captions[Group].Tex); |
4 | 396 |
|
762 | 397 |
Captions[Group].Tex:= RenderStringTex(s, Color, fntBig); |
564 | 398 |
Captions[Group].EndTime:= RealTicks + 1500 |
4 | 399 |
end; |
400 |
||
79 | 401 |
procedure MoveCamera; |
4 | 402 |
const PrevSentPointTime: LongWord = 0; |
371 | 403 |
var EdgesDist: LongInt; |
4 | 404 |
begin |
678 | 405 |
if (not (CurrentTeam^.ExtDriven and isCursorVisible)) |
406 |
and cHasFocus then SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y); |
|
407 |
||
4 | 408 |
if (FollowGear <> nil) then |
57 | 409 |
if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then |
4 | 410 |
begin |
411 |
FollowGear:= nil; |
|
412 |
exit |
|
413 |
end |
|
414 |
else begin |
|
678 | 415 |
CursorPoint.x:= (prevPoint.x * 7 + (hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100) + WorldDx) div 8; |
416 |
CursorPoint.y:= (prevPoint.y * 7 + (hwRound(FollowGear^.Y) + WorldDy)) div 8 |
|
4 | 417 |
end; |
418 |
||
419 |
if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit; |
|
420 |
||
162 | 421 |
if AMxCurr < cScreenWidth then |
422 |
begin |
|
423 |
if CursorPoint.X < AMxCurr + 35 then CursorPoint.X:= AMxCurr + 35; |
|
424 |
if CursorPoint.X > AMxCurr + 200 then CursorPoint.X:= AMxCurr + 200; |
|
425 |
if CursorPoint.Y < cScreenHeight - 75 - SlotsNum * 33 then CursorPoint.Y:= cScreenHeight - 75 - SlotsNum * 33; |
|
426 |
if CursorPoint.Y > cScreenHeight - 76 then CursorPoint.Y:= cScreenHeight - 76; |
|
427 |
prevPoint:= CursorPoint; |
|
308 | 428 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
162 | 429 |
exit |
430 |
end; |
|
431 |
||
4 | 432 |
if isCursorVisible then |
433 |
begin |
|
351 | 434 |
if (not CurrentTeam^.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then |
4 | 435 |
begin |
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
146
diff
changeset
|
436 |
SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy); |
4 | 437 |
PrevSentPointTime:= GameTicks |
438 |
end; |
|
439 |
end; |
|
351 | 440 |
|
4 | 441 |
if isCursorVisible or (FollowGear <> nil) then |
442 |
begin |
|
284 | 443 |
if isCursorVisible then EdgesDist:= cCursorEdgesDist |
444 |
else EdgesDist:= cGearScrEdgesDist; |
|
445 |
if CursorPoint.X < EdgesDist then |
|
4 | 446 |
begin |
284 | 447 |
WorldDx:= WorldDx - CursorPoint.X + EdgesDist; |
448 |
CursorPoint.X:= EdgesDist |
|
4 | 449 |
end else |
284 | 450 |
if CursorPoint.X > cScreenWidth - EdgesDist then |
4 | 451 |
begin |
284 | 452 |
WorldDx:= WorldDx - CursorPoint.X + cScreenWidth - EdgesDist; |
453 |
CursorPoint.X:= cScreenWidth - EdgesDist |
|
4 | 454 |
end; |
284 | 455 |
if CursorPoint.Y < EdgesDist then |
4 | 456 |
begin |
284 | 457 |
WorldDy:= WorldDy - CursorPoint.Y + EdgesDist; |
458 |
CursorPoint.Y:= EdgesDist |
|
4 | 459 |
end else |
284 | 460 |
if CursorPoint.Y > cScreenHeight - EdgesDist then |
4 | 461 |
begin |
284 | 462 |
WorldDy:= WorldDy - CursorPoint.Y + cScreenHeight - EdgesDist; |
463 |
CursorPoint.Y:= cScreenHeight - EdgesDist |
|
4 | 464 |
end; |
465 |
end else |
|
308 | 466 |
if cHasFocus then |
467 |
begin |
|
70 | 468 |
WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; |
469 |
WorldDy:= WorldDy - CursorPoint.Y + prevPoint.Y; |
|
4 | 470 |
CursorPoint.X:= (cScreenWidth shr 1); |
471 |
CursorPoint.Y:= (cScreenHeight shr 1); |
|
308 | 472 |
end; |
351 | 473 |
|
308 | 474 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
4 | 475 |
prevPoint:= CursorPoint; |
75 | 476 |
if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater; |
4 | 477 |
if WorldDy > 2048 then WorldDy:= 2048; |
478 |
if WorldDx < -2048 then WorldDx:= -2048; |
|
479 |
if WorldDx > cScreenWidth then WorldDx:= cScreenWidth; |
|
480 |
end; |
|
481 |
||
482 |
initialization |
|
483 |
FillChar(Captions, sizeof(Captions), 0) |
|
484 |
||
485 |
end. |