author | unc0rr |
Sun, 27 Jan 2008 19:29:00 +0000 | |
changeset 768 | 2886dafa5bcf |
parent 764 | 7513452b1d51 |
child 770 | 0138f1b5a804 |
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 |
|
756 | 41 |
uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound, GL; |
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 |
756 | 173 |
glClear(GL_COLOR_BUFFER_BIT); |
174 |
glEnable(GL_BLEND); |
|
175 |
||
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
244
diff
changeset
|
176 |
if not isPaused then MoveCamera; |
162 | 177 |
|
5 | 178 |
// Sky |
109 | 179 |
if WorldDy > 0 then |
4 | 180 |
begin |
109 | 181 |
if WorldDy > cScreenHeight then r.h:= cScreenHeight |
182 |
else r.h:= WorldDy; |
|
4 | 183 |
r.x:= 0; |
184 |
r.y:= 0; |
|
185 |
r.w:= cScreenWidth; |
|
753 | 186 |
// SDL_FillRect(Surface, @r, cSkyColor) |
4 | 187 |
end; |
5 | 188 |
// background |
755 | 189 |
DrawRepeated(sprSky, WorldDx * 3 div 8); |
190 |
DrawRepeated(sprHorizont, WorldDx * 3 div 5); |
|
4 | 191 |
|
5 | 192 |
// Waves |
4 | 193 |
{$WARNINGS OFF} |
757 | 194 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy - 64, 0, Surface); |
195 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 192) and $FF), cWaterLine + WorldDy - 48, 0, Surface); |
|
4 | 196 |
{$WARNINGS ON} |
197 |
||
762 | 198 |
DrawLand(WorldDx, WorldDy); |
5 | 199 |
// Water |
4 | 200 |
r.y:= WorldDy + cWaterLine + 32; |
201 |
if r.y < cScreenHeight then |
|
202 |
begin |
|
23 | 203 |
if r.y < 0 then r.y:= 0; |
4 | 204 |
r.h:= cScreenHeight - r.y; |
205 |
r.x:= 0; |
|
206 |
r.w:= cScreenWidth; |
|
753 | 207 |
// SDL_FillRect(Surface, @r, cWaterColor) |
4 | 208 |
end; |
209 |
||
755 | 210 |
DrawGears(Surface); |
4 | 211 |
|
5 | 212 |
// Waves |
4 | 213 |
{$WARNINGS OFF} |
757 | 214 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) + 64) and $FF), cWaterLine + WorldDy - 32, 0, Surface); |
215 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 128) and $FF), cWaterLine + WorldDy - 16, 0, Surface); |
|
216 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy , 0, Surface); |
|
4 | 217 |
{$WARNINGS ON} |
218 |
||
79 | 219 |
// Turn time |
4 | 220 |
if TurnTimeLeft <> 0 then |
221 |
begin |
|
222 |
i:= Succ(Pred(TurnTimeLeft) div 1000); |
|
223 |
if i>99 then t:= 112 |
|
224 |
else if i>9 then t:= 96 |
|
225 |
else t:= 80; |
|
753 | 226 |
// DrawSprite(sprFrame, t, cScreenHeight - 48, 1, Surface); |
4 | 227 |
while i > 0 do |
228 |
begin |
|
229 |
dec(t, 32); |
|
230 |
DrawSprite(sprBigDigit, t, cScreenHeight - 48, i mod 10, Surface); |
|
231 |
i:= i div 10 |
|
232 |
end; |
|
753 | 233 |
// DrawSprite(sprFrame, t - 4, cScreenHeight - 48, 0, Surface); |
4 | 234 |
end; |
79 | 235 |
|
236 |
// Attack bar |
|
4 | 237 |
if CurrentTeam <> nil then |
238 |
case AttackBar of |
|
689 | 239 |
(* 1: begin |
4 | 240 |
r:= StuffPoz[sPowerBar]; |
241 |
{$WARNINGS OFF} |
|
602 | 242 |
r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor; |
4 | 243 |
{$WARNINGS ON} |
244 |
DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface); |
|
245 |
end; |
|
689 | 246 |
*) 2: with CurrentHedgehog^ do |
74 | 247 |
begin |
351 | 248 |
tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle); |
249 |
tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle); |
|
250 |
for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do |
|
762 | 251 |
DrawSprite(sprPower, hwRound(Gear^.X) + system.round(WorldDx + tdx * (24 + i * 2)) - 16, |
252 |
hwRound(Gear^.Y) + system.round(WorldDy + tdy * (24 + i * 2)) - 12, |
|
253 |
i, Surface) |
|
74 | 254 |
end |
4 | 255 |
end; |
256 |
||
5 | 257 |
// Target |
762 | 258 |
if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0, Surface); |
4 | 259 |
|
260 |
// Captions |
|
175 | 261 |
i:= 8; |
262 |
for grp:= Low(TCapGroup) to High(TCapGroup) do |
|
263 |
with Captions[grp] do |
|
762 | 264 |
if Tex <> nil then |
175 | 265 |
begin |
762 | 266 |
DrawCentered(cScreenWidth div 2, i + cConsoleYAdd, Tex); |
267 |
inc(i, Tex^.h + 2); |
|
564 | 268 |
if EndTime <= RealTicks then |
175 | 269 |
begin |
762 | 270 |
FreeTexture(Tex); |
271 |
Tex:= nil; |
|
175 | 272 |
EndTime:= 0 |
273 |
end |
|
274 |
end; |
|
4 | 275 |
|
47 | 276 |
// Teams Healths |
547 | 277 |
for t:= 0 to Pred(TeamsCount) do |
278 |
with TeamsArray[t]^ do |
|
47 | 279 |
begin |
762 | 280 |
DrawTexture(cScreenWidth div 2 - NameTagTex^.w - 3, DrawHealthY, NameTagTex); |
690 | 281 |
|
282 |
r.x:= 0; |
|
283 |
r.y:= 0; |
|
547 | 284 |
r.w:= 2 + TeamHealthBarWidth; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
285 |
r.h:= HealthTex^.h; |
690 | 286 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
287 |
DrawFromRect(cScreenWidth div 2, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
288 |
DrawHealthY, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
289 |
@r, HealthTex, Surface); |
690 | 290 |
|
83 | 291 |
inc(r.x, cTeamHealthWidth + 2); |
292 |
r.w:= 3; |
|
690 | 293 |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
294 |
DrawFromRect(cScreenWidth div 2 + TeamHealthBarWidth + 2, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
295 |
DrawHealthY, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
296 |
@r, HealthTex, Surface); |
47 | 297 |
end; |
298 |
||
5 | 299 |
// Lag alert |
762 | 300 |
if isInLag then DrawSprite(sprLag, 32, 32 + cConsoleYAdd, (RealTicks shr 7) mod 12, Surface); |
4 | 301 |
|
5 | 302 |
// Wind bar |
762 | 303 |
DrawSprite(sprWindBar, cScreenWidth - 180, cScreenHeight - 30, 0, Surface); |
6 | 304 |
if WindBarWidth > 0 then |
5 | 305 |
begin |
689 | 306 |
{$WARNINGS OFF} |
307 |
r.x:= 8 - (RealTicks shr 6) mod 8; |
|
308 |
{$WARNINGS ON} |
|
309 |
r.y:= 0; |
|
310 |
r.w:= WindBarWidth; |
|
311 |
r.h:= 13; |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
312 |
DrawSpriteFromRect(sprWindR, r, cScreenWidth - 103, cScreenHeight - 28, 13, 0, Surface); |
5 | 313 |
end else |
6 | 314 |
if WindBarWidth < 0 then |
5 | 315 |
begin |
689 | 316 |
{$WARNINGS OFF} |
317 |
r.x:= (WindBarWidth + RealTicks shr 6) mod 8; |
|
318 |
{$WARNINGS ON} |
|
319 |
r.y:= 0; |
|
320 |
r.w:= - WindBarWidth; |
|
321 |
r.h:= 13; |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
322 |
DrawSpriteFromRect(sprWindL, r, cScreenWidth - 106 + WindBarWidth, cScreenHeight - 28, 13, 0, Surface); |
5 | 323 |
end; |
324 |
||
161 | 325 |
// AmmoMenu |
753 | 326 |
//if (AMxCurr < cScreenWidth) or bShowAmmoMenu then ShowAmmoMenu(Surface); |
161 | 327 |
|
5 | 328 |
// Cursor |
408 | 329 |
if isCursorVisible then |
330 |
begin |
|
331 |
if not bShowAmmoMenu then |
|
602 | 332 |
with CurrentHedgehog^ do |
408 | 333 |
if (Gear^.State and gstHHChooseTarget) <> 0 then |
334 |
begin |
|
335 |
i:= Ammo^[CurSlot, CurAmmo].Pos; |
|
336 |
with Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType] do |
|
337 |
if PosCount > 1 then |
|
762 | 338 |
DrawSprite(PosSprite, CursorPoint.X - SpritesData[PosSprite].Width div 2, |
339 |
CursorPoint.Y - SpritesData[PosSprite].Height div 2, |
|
340 |
i, Surface); |
|
408 | 341 |
end; |
762 | 342 |
DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface) |
408 | 343 |
end; |
4 | 344 |
|
345 |
{$IFDEF COUNTTICKS} |
|
753 | 346 |
//DXOutText(10, 10, fnt16, inttostr(cntTicks), Surface); |
4 | 347 |
{$ENDIF} |
348 |
||
762 | 349 |
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
|
350 |
|
4 | 351 |
inc(Frames); |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
352 |
if cShowFPS then |
4 | 353 |
begin |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
354 |
inc(CountTicks, Lag); |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
355 |
if CountTicks >= 1000 then |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
356 |
begin |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
357 |
FPS:= Frames; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
358 |
Frames:= 0; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
359 |
CountTicks:= 0; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
360 |
s:= inttostr(FPS) + ' fps'; |
759 | 361 |
if fpsTexture <> nil then FreeTexture(fpsTexture); |
362 |
tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), $FFFFFF); |
|
363 |
fpsTexture:= Surface2Tex(tmpSurface); |
|
364 |
SDL_FreeSurface(tmpSurface) |
|
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
365 |
end; |
759 | 366 |
if fpsTexture <> nil then |
367 |
begin |
|
368 |
r.x:= 0; |
|
369 |
r.y:= 0; |
|
370 |
r.w:= fpsTexture^.w; |
|
371 |
r.h:= fpsTexture^.h; |
|
372 |
DrawFromRect(cScreenWidth - 50, 10, @r, fpsTexture, Surface); |
|
373 |
end |
|
4 | 374 |
end; |
174 | 375 |
|
376 |
inc(SoundTimerTicks, Lag); |
|
377 |
if SoundTimerTicks >= 50 then |
|
378 |
begin |
|
379 |
SoundTimerTicks:= 0; |
|
380 |
if cVolumeDelta <> 0 then |
|
381 |
begin |
|
382 |
str(ChangeVolume(cVolumeDelta), s); |
|
175 | 383 |
AddCaption(Format(trmsg[sidVolume], s), $FFFFFF, capgrpVolume) |
174 | 384 |
end |
756 | 385 |
end; |
386 |
||
387 |
glDisable(GL_BLEND) |
|
4 | 388 |
end; |
389 |
||
108 | 390 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
4 | 391 |
begin |
83 | 392 |
if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s); |
762 | 393 |
if Captions[Group].Tex <> nil then FreeTexture(Captions[Group].Tex); |
4 | 394 |
|
762 | 395 |
Captions[Group].Tex:= RenderStringTex(s, Color, fntBig); |
564 | 396 |
Captions[Group].EndTime:= RealTicks + 1500 |
4 | 397 |
end; |
398 |
||
79 | 399 |
procedure MoveCamera; |
4 | 400 |
const PrevSentPointTime: LongWord = 0; |
371 | 401 |
var EdgesDist: LongInt; |
4 | 402 |
begin |
678 | 403 |
if (not (CurrentTeam^.ExtDriven and isCursorVisible)) |
404 |
and cHasFocus then SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y); |
|
405 |
||
4 | 406 |
if (FollowGear <> nil) then |
57 | 407 |
if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then |
4 | 408 |
begin |
409 |
FollowGear:= nil; |
|
410 |
exit |
|
411 |
end |
|
412 |
else begin |
|
678 | 413 |
CursorPoint.x:= (prevPoint.x * 7 + (hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100) + WorldDx) div 8; |
414 |
CursorPoint.y:= (prevPoint.y * 7 + (hwRound(FollowGear^.Y) + WorldDy)) div 8 |
|
4 | 415 |
end; |
416 |
||
417 |
if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit; |
|
418 |
||
162 | 419 |
if AMxCurr < cScreenWidth then |
420 |
begin |
|
421 |
if CursorPoint.X < AMxCurr + 35 then CursorPoint.X:= AMxCurr + 35; |
|
422 |
if CursorPoint.X > AMxCurr + 200 then CursorPoint.X:= AMxCurr + 200; |
|
423 |
if CursorPoint.Y < cScreenHeight - 75 - SlotsNum * 33 then CursorPoint.Y:= cScreenHeight - 75 - SlotsNum * 33; |
|
424 |
if CursorPoint.Y > cScreenHeight - 76 then CursorPoint.Y:= cScreenHeight - 76; |
|
425 |
prevPoint:= CursorPoint; |
|
308 | 426 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
162 | 427 |
exit |
428 |
end; |
|
429 |
||
4 | 430 |
if isCursorVisible then |
431 |
begin |
|
351 | 432 |
if (not CurrentTeam^.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then |
4 | 433 |
begin |
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
146
diff
changeset
|
434 |
SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy); |
4 | 435 |
PrevSentPointTime:= GameTicks |
436 |
end; |
|
437 |
end; |
|
351 | 438 |
|
4 | 439 |
if isCursorVisible or (FollowGear <> nil) then |
440 |
begin |
|
284 | 441 |
if isCursorVisible then EdgesDist:= cCursorEdgesDist |
442 |
else EdgesDist:= cGearScrEdgesDist; |
|
443 |
if CursorPoint.X < EdgesDist then |
|
4 | 444 |
begin |
284 | 445 |
WorldDx:= WorldDx - CursorPoint.X + EdgesDist; |
446 |
CursorPoint.X:= EdgesDist |
|
4 | 447 |
end else |
284 | 448 |
if CursorPoint.X > cScreenWidth - EdgesDist then |
4 | 449 |
begin |
284 | 450 |
WorldDx:= WorldDx - CursorPoint.X + cScreenWidth - EdgesDist; |
451 |
CursorPoint.X:= cScreenWidth - EdgesDist |
|
4 | 452 |
end; |
284 | 453 |
if CursorPoint.Y < EdgesDist then |
4 | 454 |
begin |
284 | 455 |
WorldDy:= WorldDy - CursorPoint.Y + EdgesDist; |
456 |
CursorPoint.Y:= EdgesDist |
|
4 | 457 |
end else |
284 | 458 |
if CursorPoint.Y > cScreenHeight - EdgesDist then |
4 | 459 |
begin |
284 | 460 |
WorldDy:= WorldDy - CursorPoint.Y + cScreenHeight - EdgesDist; |
461 |
CursorPoint.Y:= cScreenHeight - EdgesDist |
|
4 | 462 |
end; |
463 |
end else |
|
308 | 464 |
if cHasFocus then |
465 |
begin |
|
70 | 466 |
WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; |
467 |
WorldDy:= WorldDy - CursorPoint.Y + prevPoint.Y; |
|
4 | 468 |
CursorPoint.X:= (cScreenWidth shr 1); |
469 |
CursorPoint.Y:= (cScreenHeight shr 1); |
|
308 | 470 |
end; |
351 | 471 |
|
308 | 472 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
4 | 473 |
prevPoint:= CursorPoint; |
75 | 474 |
if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater; |
4 | 475 |
if WorldDy > 2048 then WorldDy:= 2048; |
476 |
if WorldDx < -2048 then WorldDx:= -2048; |
|
477 |
if WorldDx > cScreenWidth then WorldDx:= cScreenWidth; |
|
478 |
end; |
|
479 |
||
480 |
initialization |
|
481 |
FillChar(Captions, sizeof(Captions), 0) |
|
482 |
||
483 |
end. |