author | displacer |
Mon, 07 Jan 2008 13:09:10 +0000 | |
changeset 692 | 07787e748831 |
parent 690 | e9d35e319328 |
child 704 | 9b096d05004e |
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 uStore; |
|
20 |
interface |
|
351 | 21 |
uses uConsts, uTeams, SDLh, uFloat; |
4 | 22 |
{$INCLUDE options.inc} |
23 |
||
24 |
procedure StoreInit; |
|
25 |
procedure StoreLoad; |
|
26 |
procedure StoreRelease; |
|
689 | 27 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface); |
371 | 28 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt; Surface: PSDL_Surface); |
29 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt; Surface: PSDL_Surface); |
|
30 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source, Surface: PSDL_Surface); |
|
31 |
procedure DrawLand (X, Y: LongInt; Surface: PSDL_Surface); |
|
32 |
procedure DXOutText(X, Y: LongInt; Font: THWFont; s: string; Surface: PSDL_Surface); |
|
33 |
procedure DrawCentered(X, Top: LongInt; Source, Surface: PSDL_Surface); |
|
690 | 34 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface); |
371 | 35 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface); |
351 | 36 |
function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
4 | 37 |
procedure RenderHealth(var Hedgehog: THedgehog); |
38 |
procedure AddProgress; |
|
510 | 39 |
procedure FinishProgress; |
518 | 40 |
function LoadImage(const filename: string; hasAlpha, critical, setTransparent: boolean): PSDL_Surface; |
4 | 41 |
|
42 |
var PixelFormat: PSDL_PixelFormat; |
|
43 |
SDLPrimSurface: PSDL_Surface; |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
44 |
PauseSurface: PSDL_Surface; |
4 | 45 |
|
46 |
implementation |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
47 |
uses uMisc, uConsole, uLand, uLocale; |
4 | 48 |
|
690 | 49 |
var |
50 |
HHSurface: PSDL_Surface; |
|
4 | 51 |
|
52 |
procedure StoreInit; |
|
53 |
begin |
|
54 |
||
55 |
end; |
|
56 |
||
351 | 57 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 58 |
var r: TSDL_Rect; |
59 |
begin |
|
60 |
r:= rect^; |
|
83 | 61 |
if Clear then SDL_FillRect(Surface, @r, 0); |
351 | 62 |
r.y:= rect^.y + 1; |
63 |
r.h:= rect^.h - 2; |
|
47 | 64 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 65 |
r.x:= rect^.x + 1; |
66 |
r.w:= rect^.w - 2; |
|
67 |
r.y:= rect^.y; |
|
68 |
r.h:= rect^.h; |
|
47 | 69 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 70 |
r.x:= rect^.x + 2; |
71 |
r.y:= rect^.y + 1; |
|
72 |
r.w:= rect^.w - 4; |
|
73 |
r.h:= rect^.h - 2; |
|
47 | 74 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 75 |
r.x:= rect^.x + 1; |
76 |
r.y:= rect^.y + 2; |
|
77 |
r.w:= rect^.w - 2; |
|
78 |
r.h:= rect^.h - 4; |
|
47 | 79 |
SDL_FillRect(Surface, @r, FillColor) |
80 |
end; |
|
81 |
||
371 | 82 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
351 | 83 |
var w, h: LongInt; |
4 | 84 |
tmpsurf: PSDL_Surface; |
85 |
clr: TSDL_Color; |
|
351 | 86 |
Result: TSDL_Rect; |
4 | 87 |
begin |
355 | 88 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
4 | 89 |
Result.x:= X; |
90 |
Result.y:= Y; |
|
202 | 91 |
Result.w:= w + FontBorder * 2 + 4; |
92 |
Result.h:= h + FontBorder * 2; |
|
351 | 93 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true); |
189 | 94 |
clr.r:= Color shr 16; |
95 |
clr.g:= (Color shr 8) and $FF; |
|
96 |
clr.b:= Color and $FF; |
|
355 | 97 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value); |
202 | 98 |
Result.x:= X + FontBorder + 2; |
99 |
Result.y:= Y + FontBorder; |
|
199 | 100 |
SDLTry(tmpsurf <> nil, true); |
4 | 101 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
102 |
SDL_FreeSurface(tmpsurf); |
|
103 |
Result.x:= X; |
|
104 |
Result.y:= Y; |
|
202 | 105 |
Result.w:= w + FontBorder * 2 + 4; |
351 | 106 |
Result.h:= h + FontBorder * 2; |
107 |
WriteInRoundRect:= Result |
|
4 | 108 |
end; |
109 |
||
110 |
procedure StoreLoad; |
|
689 | 111 |
var ii: TSprite; |
4 | 112 |
fi: THWFont; |
113 |
s: string; |
|
114 |
tmpsurf: PSDL_Surface; |
|
115 |
||
116 |
procedure WriteNames(Font: THWFont); |
|
547 | 117 |
var t: LongInt; |
371 | 118 |
i: LongInt; |
47 | 119 |
r, rr: TSDL_Rect; |
371 | 120 |
drY: LongInt; |
4 | 121 |
begin |
122 |
r.x:= 0; |
|
690 | 123 |
r.y:= 0; |
70 | 124 |
drY:= cScreenHeight - 4; |
547 | 125 |
for t:= 0 to Pred(TeamsCount) do |
126 |
with TeamsArray[t]^ do |
|
4 | 127 |
begin |
549 | 128 |
NameTag:= RenderString(TeamName, Clan^.Color, Font); |
690 | 129 |
|
47 | 130 |
r.w:= cTeamHealthWidth + 5; |
547 | 131 |
r.h:= NameTag^.h; |
690 | 132 |
|
133 |
HealthSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, r.w, r.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
|
134 |
TryDo(HealthSurf <> nil, errmsgCreateSurface, true); |
|
135 |
||
136 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, HealthSurf, true); |
|
47 | 137 |
rr:= r; |
138 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
690 | 139 |
DrawRoundRect(@rr, Clan^.AdjColor, Clan^.AdjColor, HealthSurf, false); |
140 |
||
49 | 141 |
dec(drY, r.h + 2); |
547 | 142 |
DrawHealthY:= drY; |
4 | 143 |
for i:= 0 to 7 do |
547 | 144 |
with Hedgehogs[i] do |
95 | 145 |
if Gear <> nil then |
549 | 146 |
NameTag:= RenderString(Name, Clan^.Color, fnt16); |
4 | 147 |
end; |
148 |
end; |
|
149 |
||
150 |
procedure MakeCrossHairs; |
|
547 | 151 |
var t: LongInt; |
4 | 152 |
tmpsurf: PSDL_Surface; |
153 |
s: string; |
|
154 |
begin |
|
53 | 155 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
351 | 156 |
tmpsurf:= LoadImage(s, true, true, false); |
4 | 157 |
|
547 | 158 |
for t:= 0 to Pred(TeamsCount) do |
159 |
with TeamsArray[t]^ do |
|
4 | 160 |
begin |
547 | 161 |
CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, tmpsurf^.w, tmpsurf^.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
162 |
TryDo(CrosshairSurf <> nil, errmsgCreateSurface, true); |
|
549 | 163 |
SDL_FillRect(CrosshairSurf, nil, Clan^.AdjColor); |
547 | 164 |
SDL_UpperBlit(tmpsurf, nil, CrosshairSurf, nil); |
165 |
TryDo(SDL_SetColorKey(CrosshairSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
|
4 | 166 |
end; |
351 | 167 |
|
4 | 168 |
SDL_FreeSurface(tmpsurf) |
169 |
end; |
|
170 |
||
171 |
procedure InitHealth; |
|
547 | 172 |
var i, t: LongInt; |
4 | 173 |
begin |
547 | 174 |
for t:= 0 to Pred(TeamsCount) do |
175 |
if TeamsArray[t] <> nil then |
|
176 |
with TeamsArray[t]^ do |
|
4 | 177 |
begin |
178 |
for i:= 0 to cMaxHHIndex do |
|
547 | 179 |
if Hedgehogs[i].Gear <> nil then |
180 |
RenderHealth(Hedgehogs[i]); |
|
4 | 181 |
end |
182 |
end; |
|
183 |
||
184 |
procedure LoadGraves; |
|
689 | 185 |
var t: LongInt; |
4 | 186 |
begin |
547 | 187 |
for t:= 0 to Pred(TeamsCount) do |
188 |
if TeamsArray[t] <> nil then |
|
189 |
with TeamsArray[t]^ do |
|
4 | 190 |
begin |
547 | 191 |
if GraveName = '' then GraveName:= 'Simple'; |
689 | 192 |
GraveSurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, false, true, true); |
4 | 193 |
end |
194 |
end; |
|
195 |
||
196 |
procedure GetSkyColor; |
|
107 | 197 |
var p: PByteArray; |
4 | 198 |
begin |
80 | 199 |
if SDL_MustLock(SpritesData[sprSky].Surface) then |
200 |
SDLTry(SDL_LockSurface(SpritesData[sprSky].Surface) >= 0, true); |
|
351 | 201 |
p:= SpritesData[sprSky].Surface^.pixels; |
202 |
case SpritesData[sprSky].Surface^.format^.BytesPerPixel of |
|
4 | 203 |
1: cSkyColor:= PByte(p)^; |
204 |
2: cSkyColor:= PWord(p)^; |
|
107 | 205 |
3: cSkyColor:= (p^[0]) or (p^[1] shl 8) or (p^[2] shl 16); |
4 | 206 |
4: cSkyColor:= PLongword(p)^; |
207 |
end; |
|
80 | 208 |
if SDL_MustLock(SpritesData[sprSky].Surface) then |
209 |
SDL_UnlockSurface(SpritesData[sprSky].Surface) |
|
4 | 210 |
end; |
211 |
||
212 |
procedure GetExplosionBorderColor; |
|
213 |
var f: textfile; |
|
371 | 214 |
c: LongInt; |
4 | 215 |
begin |
80 | 216 |
s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename; |
4 | 217 |
WriteToConsole(msgLoading + s + ' '); |
351 | 218 |
Assign(f, s); |
4 | 219 |
{$I-} |
220 |
Reset(f); |
|
221 |
Readln(f, s); |
|
351 | 222 |
Close(f); |
4 | 223 |
{$I+} |
224 |
TryDo(IOResult = 0, msgFailed, true); |
|
225 |
WriteLnToConsole(msgOK); |
|
226 |
val(s, cExplosionBorderColor, c); |
|
495 | 227 |
TryDo(c = 0, 'Theme data corrupted', true); |
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
190
diff
changeset
|
228 |
AdjustColor(cExplosionBorderColor); |
4 | 229 |
end; |
230 |
||
231 |
begin |
|
232 |
for fi:= Low(THWFont) to High(THWFont) do |
|
233 |
with Fontz[fi] do |
|
234 |
begin |
|
53 | 235 |
s:= Pathz[ptFonts] + '/' + Name; |
200 | 236 |
WriteToConsole(msgLoading + s + '... '); |
355 | 237 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
200 | 238 |
SDLTry(Handle <> nil, true); |
202 | 239 |
TTF_SetFontStyle(Handle, style); |
4 | 240 |
WriteLnToConsole(msgOK) |
241 |
end; |
|
242 |
AddProgress; |
|
53 | 243 |
|
105 | 244 |
WriteToConsole('LandSurface tuning... '); |
4 | 245 |
tmpsurf:= LandSurface; |
246 |
TryDo(tmpsurf <> nil, msgFailed, true); |
|
247 |
if cFullScreen then |
|
248 |
begin |
|
249 |
LandSurface:= SDL_DisplayFormat(tmpsurf); |
|
250 |
SDL_FreeSurface(tmpsurf); |
|
251 |
end else LandSurface:= tmpsurf; |
|
35 | 252 |
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
4 | 253 |
WriteLnToConsole(msgOK); |
254 |
||
255 |
GetExplosionBorderColor; |
|
256 |
||
257 |
AddProgress; |
|
258 |
WriteNames(fnt16); |
|
70 | 259 |
MakeCrossHairs; |
4 | 260 |
LoadGraves; |
261 |
||
262 |
AddProgress; |
|
263 |
for ii:= Low(TSprite) to High(TSprite) do |
|
264 |
with SpritesData[ii] do |
|
80 | 265 |
begin |
266 |
if AltPath = ptNone then |
|
351 | 267 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, true, true) |
80 | 268 |
else begin |
351 | 269 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false, true); |
80 | 270 |
if Surface = nil then |
351 | 271 |
Surface:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha, true, true) |
80 | 272 |
end; |
351 | 273 |
if Width = 0 then Width:= Surface^.w; |
274 |
if Height = 0 then Height:= Surface^.h |
|
80 | 275 |
end; |
276 |
||
277 |
GetSkyColor; |
|
4 | 278 |
|
279 |
AddProgress; |
|
567 | 280 |
|
281 |
HHSurface:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, true, true, true); |
|
4 | 282 |
|
283 |
InitHealth; |
|
284 |
||
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
285 |
PauseSurface:= RenderString(trmsg[sidPaused], $FFFF00, fntBig); |
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
286 |
|
4 | 287 |
{$IFDEF DUMP} |
288 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
289 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
290 |
{$ENDIF} |
|
291 |
end; |
|
292 |
||
371 | 293 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface); |
4 | 294 |
var rr: TSDL_Rect; |
295 |
begin |
|
296 |
rr.x:= X; |
|
297 |
rr.y:= Y; |
|
351 | 298 |
rr.w:= r^.w; |
299 |
rr.h:= r^.h; |
|
4 | 300 |
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then |
301 |
begin |
|
43 | 302 |
OutError('Blit: ' + SDL_GetError, true); |
4 | 303 |
exit |
304 |
end; |
|
305 |
end; |
|
306 |
||
689 | 307 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface); |
4 | 308 |
begin |
309 |
r.y:= r.y + Height * Position; |
|
310 |
r.h:= Height; |
|
689 | 311 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
4 | 312 |
end; |
313 |
||
371 | 314 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt; Surface: PSDL_Surface); |
4 | 315 |
begin |
198 | 316 |
DrawSurfSprite(X, Y, SpritesData[Sprite].Height, Frame, SpritesData[Sprite].Surface, Surface) |
4 | 317 |
end; |
318 |
||
371 | 319 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt; Surface: PSDL_Surface); |
43 | 320 |
var r: TSDL_Rect; |
321 |
begin |
|
322 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
323 |
r.w:= SpritesData[Sprite].Width; |
|
324 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
325 |
r.h:= SpritesData[Sprite].Height; |
|
326 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
|
327 |
end; |
|
328 |
||
371 | 329 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source, Surface: PSDL_Surface); |
198 | 330 |
var r: TSDL_Rect; |
331 |
begin |
|
332 |
r.x:= 0; |
|
351 | 333 |
r.w:= Source^.w; |
198 | 334 |
r.y:= Frame * Height; |
335 |
r.h:= Height; |
|
336 |
DrawFromRect(X, Y, @r, Source, Surface) |
|
337 |
end; |
|
338 |
||
371 | 339 |
procedure DXOutText(X, Y: LongInt; Font: THWFont; s: string; Surface: PSDL_Surface); |
4 | 340 |
var clr: TSDL_Color; |
341 |
tmpsurf: PSDL_Surface; |
|
342 |
r: TSDL_Rect; |
|
343 |
begin |
|
344 |
r.x:= X; |
|
345 |
r.y:= Y; |
|
189 | 346 |
clr.r:= $FF; |
347 |
clr.g:= $FF; |
|
348 |
clr.b:= $FF; |
|
355 | 349 |
tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, Str2PChar(s), clr.value); |
208 | 350 |
if tmpsurf = nil then |
351 |
begin |
|
352 |
SetKB(1); |
|
353 |
exit |
|
354 |
end; |
|
4 | 355 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
356 |
SDL_FreeSurface(tmpsurf) |
|
357 |
end; |
|
358 |
||
371 | 359 |
procedure DrawLand(X, Y: LongInt; Surface: PSDL_Surface); |
4 | 360 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024); |
361 |
begin |
|
362 |
DrawFromRect(X, Y, @r, LandSurface, Surface) |
|
363 |
end; |
|
364 |
||
371 | 365 |
procedure DrawCentered(X, Top: LongInt; Source, Surface: PSDL_Surface); |
95 | 366 |
var r: TSDL_Rect; |
367 |
begin |
|
351 | 368 |
r.x:= X - Source^.w div 2; |
95 | 369 |
r.y:= Top; |
351 | 370 |
r.w:= Source^.w; |
371 |
r.h:= Source^.h; |
|
95 | 372 |
SDL_UpperBlit(Source, nil, Surface, @r) |
4 | 373 |
end; |
374 |
||
371 | 375 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface); |
4 | 376 |
var r: TSDL_Rect; |
377 |
begin |
|
378 |
r.x:= Step * 32; |
|
379 |
r.y:= Pos * 32; |
|
351 | 380 |
if Dir = -1 then r.x:= HHSurface^.w - 32 - r.x; |
4 | 381 |
r.w:= 32; |
382 |
r.h:= 32; |
|
383 |
DrawFromRect(X, Y, @r, HHSurface, Surface) |
|
384 |
end; |
|
385 |
||
386 |
procedure StoreRelease; |
|
387 |
var ii: TSprite; |
|
388 |
begin |
|
389 |
for ii:= Low(TSprite) to High(TSprite) do |
|
390 |
SDL_FreeSurface(SpritesData[ii].Surface); |
|
391 |
SDL_FreeSurface( HHSurface ); |
|
690 | 392 |
SDL_FreeSurface(LandSurface ) |
4 | 393 |
end; |
394 |
||
351 | 395 |
function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
432 | 396 |
var w, h: LongInt; |
351 | 397 |
Result: PSDL_Surface; |
95 | 398 |
begin |
355 | 399 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
202 | 400 |
Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
351 | 401 |
cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
107 | 402 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
95 | 403 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
351 | 404 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
405 |
RenderString:= Result |
|
95 | 406 |
end; |
407 |
||
4 | 408 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 409 |
var s: shortstring; |
4 | 410 |
begin |
351 | 411 |
str(Hedgehog.Gear^.Health, s); |
95 | 412 |
if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
549 | 413 |
Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Clan^.Color, fnt16) |
4 | 414 |
end; |
415 |
||
518 | 416 |
function LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
30 | 417 |
var tmpsurf: PSDL_Surface; |
351 | 418 |
Result: PSDL_Surface; |
355 | 419 |
s: shortstring; |
4 | 420 |
begin |
421 |
WriteToConsole(msgLoading + filename + '... '); |
|
355 | 422 |
s:= filename + '.' + cBitsStr + '.png'; |
423 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 424 |
|
74 | 425 |
if tmpsurf = nil then |
351 | 426 |
begin |
355 | 427 |
s:= filename + '.png'; |
428 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 429 |
end; |
80 | 430 |
|
431 |
if tmpsurf = nil then |
|
432 |
if critical then OutError(msgFailed, true) |
|
433 |
else begin |
|
434 |
WriteLnToConsole(msgFailed); |
|
351 | 435 |
exit(nil) |
80 | 436 |
end; |
351 | 437 |
|
198 | 438 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
80 | 439 |
if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
440 |
else Result:= SDL_DisplayFormat(tmpsurf); |
|
620 | 441 |
{$IFDEF DEBUGFILE}WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');{$ENDIF} |
351 | 442 |
WriteLnToConsole(msgOK); |
443 |
LoadImage:= Result |
|
4 | 444 |
end; |
445 |
||
510 | 446 |
//////////////////////////////////////////////////////////////////////////////// |
447 |
var ProgrSurf: PSDL_Surface = nil; |
|
534 | 448 |
Step: integer = 0; |
510 | 449 |
|
450 |
procedure AddProgress; |
|
451 |
var r: TSDL_Rect; |
|
452 |
begin |
|
453 |
if Step = 0 then |
|
454 |
begin |
|
455 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
456 |
ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
|
457 |
end; |
|
458 |
SDL_FillRect(SDLPrimSurface, nil, 0); |
|
459 |
r.x:= 0; |
|
460 |
r.w:= ProgrSurf^.w; |
|
461 |
r.h:= ProgrSurf^.w; |
|
462 |
r.y:= (Step mod (ProgrSurf^.h div ProgrSurf^.w)) * ProgrSurf^.w; |
|
463 |
DrawFromRect((cScreenWidth - ProgrSurf^.w) div 2, |
|
464 |
(cScreenHeight - ProgrSurf^.w) div 2, @r, ProgrSurf, SDLPrimSurface); |
|
465 |
SDL_Flip(SDLPrimSurface); |
|
466 |
inc(Step); |
|
467 |
end; |
|
468 |
||
469 |
procedure FinishProgress; |
|
470 |
begin |
|
471 |
WriteLnToConsole('Freeing progress surface... '); |
|
472 |
SDL_FreeSurface(ProgrSurf) |
|
473 |
end; |
|
474 |
||
4 | 475 |
end. |