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