author | unc0rr |
Wed, 01 Nov 2006 19:36:41 +0000 | |
changeset 227 | 4f6940084811 |
parent 208 | a049157d673a |
child 281 | 5b483aa9f2ab |
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; |
|
206
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
203
diff
changeset
|
111 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, PChar(s), clr.value); |
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 |
|
203 | 173 |
Team.CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, tmpsurf.w, tmpsurf.h, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, PixelFormat.AMask); |
198 | 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; |
|
206
32fa6282efe2
Add workaround over freepascal bug (http://www.freepascal.org/mantis/view.php?id=7613)
unc0rr
parents:
203
diff
changeset
|
378 |
tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, PChar(s), clr.value); |
208 | 379 |
if tmpsurf = nil then |
380 |
begin |
|
381 |
SetKB(1); |
|
382 |
exit |
|
383 |
end; |
|
4 | 384 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
385 |
SDL_FreeSurface(tmpsurf) |
|
386 |
end; |
|
387 |
||
388 |
procedure DrawLand(X, Y: integer; Surface: PSDL_Surface); |
|
389 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024); |
|
390 |
begin |
|
391 |
DrawFromRect(X, Y, @r, LandSurface, Surface) |
|
392 |
end; |
|
393 |
||
47 | 394 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface); |
395 |
begin |
|
396 |
DrawFromRect(X, Y, Rect, StoreSurface, Surface) |
|
397 |
end; |
|
398 |
||
95 | 399 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); |
4 | 400 |
begin |
95 | 401 |
DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface) |
402 |
end; |
|
403 |
||
404 |
procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface); |
|
405 |
var r: TSDL_Rect; |
|
406 |
begin |
|
407 |
r.x:= X - Source.w div 2; |
|
408 |
r.y:= Top; |
|
409 |
r.w:= Source.w; |
|
410 |
r.h:= Source.h; |
|
411 |
SDL_UpperBlit(Source, nil, Surface, @r) |
|
4 | 412 |
end; |
413 |
||
414 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface); |
|
415 |
var r: TSDL_Rect; |
|
416 |
begin |
|
417 |
r.x:= Step * 32; |
|
418 |
r.y:= Pos * 32; |
|
419 |
if Dir = -1 then r.x:= cHHSurfaceWidth - 32 - r.x; |
|
420 |
r.w:= 32; |
|
421 |
r.h:= 32; |
|
422 |
DrawFromRect(X, Y, @r, HHSurface, Surface) |
|
423 |
end; |
|
424 |
||
425 |
procedure StoreRelease; |
|
426 |
var ii: TSprite; |
|
427 |
begin |
|
428 |
for ii:= Low(TSprite) to High(TSprite) do |
|
429 |
SDL_FreeSurface(SpritesData[ii].Surface); |
|
430 |
SDL_FreeSurface( HHSurface ); |
|
431 |
SDL_FreeSurface(LandSurface ); |
|
432 |
SDL_FreeSurface(StoreSurface ) |
|
433 |
end; |
|
434 |
||
108 | 435 |
function RenderString(s: string; Color: integer; font: THWFont): PSDL_Surface; |
95 | 436 |
var w, h: integer; |
437 |
begin |
|
108 | 438 |
TTF_SizeUTF8(Fontz[font].Handle, PChar(s), w, h); |
202 | 439 |
Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
440 |
cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, PixelFormat.AMask); |
|
107 | 441 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
95 | 442 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
443 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true) |
|
444 |
end; |
|
445 |
||
4 | 446 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 447 |
var s: shortstring; |
4 | 448 |
begin |
449 |
str(Hedgehog.Gear.Health, s); |
|
95 | 450 |
if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
451 |
Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Color, fnt16) |
|
4 | 452 |
end; |
453 |
||
454 |
procedure AddProgress; |
|
455 |
const Step: Longword = 0; |
|
456 |
ProgrSurf: PSDL_Surface = nil; |
|
71 | 457 |
MaxCalls = 11; // MaxCalls should be the count of calls to AddProgress to prevent memory leakage |
4 | 458 |
var r: TSDL_Rect; |
459 |
begin |
|
460 |
if Step = 0 then |
|
461 |
begin |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
95
diff
changeset
|
462 |
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
|
463 |
ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/BigDigits', false); |
4 | 464 |
end; |
465 |
SDL_FillRect(SDLPrimSurface, nil, 0); |
|
466 |
r.x:= 0; |
|
467 |
r.w:= 32; |
|
468 |
r.h:= 32; |
|
71 | 469 |
r.y:= (Step mod 10) * 32; |
4 | 470 |
DrawFromRect(cScreenWidth div 2 - 16, cScreenHeight div 2 - 16, @r, ProgrSurf, SDLPrimSurface); |
471 |
SDL_Flip(SDLPrimSurface); |
|
472 |
inc(Step); |
|
473 |
if Step = MaxCalls then |
|
474 |
begin |
|
475 |
WriteLnToConsole('Freeing progress surface... '); |
|
476 |
SDL_FreeSurface(ProgrSurf) |
|
477 |
end; |
|
478 |
end; |
|
479 |
||
198 | 480 |
function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true; const setTransparent: boolean = true): PSDL_Surface; |
30 | 481 |
var tmpsurf: PSDL_Surface; |
4 | 482 |
begin |
483 |
WriteToConsole(msgLoading + filename + '... '); |
|
74 | 484 |
tmpsurf:= IMG_Load(PChar(filename + '.' + cBitsStr + '.png')); |
485 |
if tmpsurf = nil then |
|
486 |
tmpsurf:= IMG_Load(PChar(filename + '.png')); |
|
80 | 487 |
|
488 |
if tmpsurf = nil then |
|
489 |
if critical then OutError(msgFailed, true) |
|
490 |
else begin |
|
491 |
WriteLnToConsole(msgFailed); |
|
492 |
Result:= nil; |
|
493 |
exit |
|
494 |
end; |
|
495 |
||
198 | 496 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
80 | 497 |
if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
498 |
else Result:= SDL_DisplayFormat(tmpsurf); |
|
4 | 499 |
WriteLnToConsole(msgOK) |
500 |
end; |
|
501 |
||
502 |
end. |