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