4
|
1 |
(*
|
|
2 |
* Hedgewars, a worms-like game
|
47
|
3 |
* Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
|
4
|
4 |
*
|
|
5 |
* Distributed under the terms of the BSD-modified licence:
|
|
6 |
*
|
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8 |
* of this software and associated documentation files (the "Software"), to deal
|
|
9 |
* with the Software without restriction, including without limitation the
|
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is
|
|
12 |
* furnished to do so, subject to the following conditions:
|
|
13 |
*
|
|
14 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
15 |
* this list of conditions and the following disclaimer.
|
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
17 |
* this list of conditions and the following disclaimer in the documentation
|
|
18 |
* and/or other materials provided with the distribution.
|
|
19 |
* 3. The name of the author may not be used to endorse or promote products
|
|
20 |
* derived from this software without specific prior written permission.
|
|
21 |
*
|
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32 |
*)
|
|
33 |
|
|
34 |
unit uStore;
|
|
35 |
interface
|
|
36 |
uses uConsts, uTeams, SDLh;
|
|
37 |
{$INCLUDE options.inc}
|
|
38 |
|
|
39 |
procedure StoreInit;
|
|
40 |
procedure StoreLoad;
|
|
41 |
procedure StoreRelease;
|
|
42 |
procedure DrawGear(Stuff : TStuff; X, Y: integer; Surface: PSDL_Surface);
|
|
43 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface);
|
|
44 |
procedure DrawSprite (Sprite: TSprite; X, Y, Position: integer; Surface: PSDL_Surface);
|
43
|
45 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface);
|
4
|
46 |
procedure DrawLand (X, Y: integer; Surface: PSDL_Surface);
|
|
47 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface);
|
95
|
48 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface);
|
|
49 |
procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface);
|
47
|
50 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface);
|
4
|
51 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface);
|
95
|
52 |
function RenderString(var s: shortstring; Color: integer; font: THWFont): PSDL_Surface;
|
4
|
53 |
procedure RenderHealth(var Hedgehog: THedgehog);
|
|
54 |
procedure AddProgress;
|
80
|
55 |
function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true): PSDL_Surface;
|
4
|
56 |
|
|
57 |
var PixelFormat: PSDL_PixelFormat;
|
|
58 |
SDLPrimSurface: PSDL_Surface;
|
|
59 |
|
|
60 |
implementation
|
53
|
61 |
uses uMisc, uIO, uConsole, uLand, uCollisions;
|
4
|
62 |
|
|
63 |
var StoreSurface,
|
|
64 |
HHSurface: PSDL_Surface;
|
|
65 |
|
|
66 |
procedure StoreInit;
|
|
67 |
begin
|
74
|
68 |
StoreSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 576, 1024, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0);
|
4
|
69 |
TryDo( StoreSurface <> nil, errmsgCreateSurface + ': store' , true);
|
37
|
70 |
SDL_FillRect(StoreSurface, nil, 0);
|
4
|
71 |
|
|
72 |
TryDo(SDL_SetColorKey( StoreSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
|
73 |
end;
|
|
74 |
|
|
75 |
procedure LoadToSurface(Filename: String; Surface: PSDL_Surface; X, Y: integer);
|
|
76 |
var tmpsurf: PSDL_Surface;
|
|
77 |
rr: TSDL_Rect;
|
|
78 |
begin
|
35
|
79 |
tmpsurf:= LoadImage(Filename, false);
|
4
|
80 |
rr.x:= X;
|
|
81 |
rr.y:= Y;
|
|
82 |
SDL_UpperBlit(tmpsurf, nil, Surface, @rr);
|
|
83 |
SDL_FreeSurface(tmpsurf);
|
|
84 |
end;
|
|
85 |
|
83
|
86 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; const Clear: boolean = true);
|
47
|
87 |
var r: TSDL_Rect;
|
|
88 |
begin
|
|
89 |
r:= rect^;
|
83
|
90 |
if Clear then SDL_FillRect(Surface, @r, 0);
|
47
|
91 |
r.y:= rect.y + 1;
|
|
92 |
r.h:= rect.h - 2;
|
|
93 |
SDL_FillRect(Surface, @r, BorderColor);
|
|
94 |
r.x:= rect.x + 1;
|
|
95 |
r.w:= rect.w - 2;
|
|
96 |
r.y:= rect.y;
|
|
97 |
r.h:= rect.h;
|
|
98 |
SDL_FillRect(Surface, @r, BorderColor);
|
|
99 |
r.x:= rect.x + 2;
|
|
100 |
r.y:= rect.y + 1;
|
|
101 |
r.w:= rect.w - 4;
|
|
102 |
r.h:= rect.h - 2;
|
|
103 |
SDL_FillRect(Surface, @r, FillColor);
|
|
104 |
r.x:= rect.x + 1;
|
|
105 |
r.y:= rect.y + 2;
|
|
106 |
r.w:= rect.w - 2;
|
|
107 |
r.h:= rect.h - 4;
|
|
108 |
SDL_FillRect(Surface, @r, FillColor)
|
|
109 |
end;
|
|
110 |
|
4
|
111 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: integer; Color: LongWord; Font: THWFont; s: string): TSDL_Rect;
|
|
112 |
var w, h: integer;
|
|
113 |
tmpsurf: PSDL_Surface;
|
|
114 |
clr: TSDL_Color;
|
|
115 |
begin
|
74
|
116 |
TTF_SizeUTF8(Fontz[Font].Handle, PChar(s), w, h);
|
4
|
117 |
Result.x:= X;
|
|
118 |
Result.y:= Y;
|
|
119 |
Result.w:= w + 6;
|
74
|
120 |
Result.h:= h + 2;
|
47
|
121 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface);
|
4
|
122 |
SDL_GetRGB(Color, Surface.format, @clr.r, @clr.g, @clr.b);
|
74
|
123 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, PChar(s), clr);
|
4
|
124 |
Result.x:= X + 3;
|
74
|
125 |
Result.y:= Y + 1;
|
4
|
126 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result);
|
|
127 |
SDL_FreeSurface(tmpsurf);
|
|
128 |
Result.x:= X;
|
|
129 |
Result.y:= Y;
|
|
130 |
Result.w:= w + 6;
|
74
|
131 |
Result.h:= h + 2
|
4
|
132 |
end;
|
|
133 |
|
|
134 |
procedure StoreLoad;
|
|
135 |
var i: TStuff;
|
|
136 |
ii: TSprite;
|
|
137 |
fi: THWFont;
|
|
138 |
s: string;
|
|
139 |
tmpsurf: PSDL_Surface;
|
|
140 |
|
|
141 |
procedure WriteNames(Font: THWFont);
|
|
142 |
var Team: PTeam;
|
|
143 |
i: integer;
|
47
|
144 |
r, rr: TSDL_Rect;
|
49
|
145 |
drY: integer;
|
4
|
146 |
begin
|
|
147 |
r.x:= 0;
|
|
148 |
r.y:= 272;
|
70
|
149 |
drY:= cScreenHeight - 4;
|
4
|
150 |
Team:= TeamsList;
|
|
151 |
while Team<>nil do
|
|
152 |
begin
|
47
|
153 |
r.w:= 104;
|
95
|
154 |
Team.NameTag:= RenderString(Team.TeamName, Team.Color, Font);
|
47
|
155 |
r.w:= cTeamHealthWidth + 5;
|
95
|
156 |
r.h:= Team.NameTag.h;
|
47
|
157 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, StoreSurface);
|
|
158 |
Team.HealthRect:= r;
|
|
159 |
rr:= r;
|
|
160 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
|
83
|
161 |
DrawRoundRect(@rr, Team.Color, Team.Color, StoreSurface, false);
|
47
|
162 |
inc(r.y, r.h);
|
49
|
163 |
dec(drY, r.h + 2);
|
|
164 |
Team.DrawHealthY:= drY;
|
4
|
165 |
for i:= 0 to 7 do
|
95
|
166 |
with Team.Hedgehogs[i] do
|
|
167 |
if Gear <> nil then
|
|
168 |
NameTag:= RenderString(Name, Team.Color, fnt16);
|
4
|
169 |
Team:= Team.Next
|
|
170 |
end;
|
|
171 |
end;
|
|
172 |
|
|
173 |
procedure MakeCrossHairs;
|
|
174 |
var Team: PTeam;
|
|
175 |
r: TSDL_Rect;
|
|
176 |
tmpsurf: PSDL_Surface;
|
|
177 |
s: string;
|
|
178 |
TransColor: Longword;
|
|
179 |
begin
|
|
180 |
r.x:= 0;
|
|
181 |
r.y:= 256;
|
|
182 |
r.w:= 16;
|
|
183 |
r.h:= 16;
|
53
|
184 |
s:= Pathz[ptGraphics] + '/' + cCHFileName;
|
74
|
185 |
tmpsurf:= LoadImage(PChar(s), false);
|
4
|
186 |
TransColor:= SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF);
|
|
187 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, TransColor) = 0, errmsgTransparentSet, true);
|
|
188 |
|
|
189 |
Team:= TeamsList;
|
|
190 |
while Team<>nil do
|
|
191 |
begin
|
|
192 |
SDL_FillRect(StoreSurface, @r, Team.Color);
|
|
193 |
SDL_UpperBlit(tmpsurf, nil, StoreSurface, @r);
|
|
194 |
Team.CrossHairRect:= r;
|
|
195 |
inc(r.x, 16);
|
|
196 |
Team:= Team.Next
|
|
197 |
end;
|
|
198 |
|
|
199 |
SDL_FreeSurface(tmpsurf)
|
|
200 |
end;
|
|
201 |
|
|
202 |
procedure InitHealth;
|
|
203 |
var p: PTeam;
|
95
|
204 |
i: integer;
|
4
|
205 |
begin
|
|
206 |
p:= TeamsList;
|
|
207 |
while p <> nil do
|
|
208 |
begin
|
|
209 |
for i:= 0 to cMaxHHIndex do
|
|
210 |
if p.Hedgehogs[i].Gear <> nil then
|
|
211 |
RenderHealth(p.Hedgehogs[i]);
|
|
212 |
p:= p.Next
|
|
213 |
end
|
|
214 |
end;
|
|
215 |
|
|
216 |
procedure LoadGraves;
|
|
217 |
var p: PTeam;
|
|
218 |
l: integer;
|
|
219 |
begin
|
|
220 |
p:= TeamsList;
|
|
221 |
l:= 512;
|
|
222 |
while p <> nil do
|
|
223 |
begin
|
|
224 |
dec(l, 32);
|
|
225 |
if p.GraveName = '' then p.GraveName:= 'Simple';
|
74
|
226 |
LoadToSurface(Pathz[ptGraves] + '/' + p.GraveName, StoreSurface, l, 512);
|
4
|
227 |
p.GraveRect.x:= l;
|
|
228 |
p.GraveRect.y:= 512;
|
|
229 |
p.GraveRect.w:= 32;
|
|
230 |
p.GraveRect.h:= 256;
|
|
231 |
p:= p.Next
|
|
232 |
end
|
|
233 |
end;
|
|
234 |
|
|
235 |
procedure GetSkyColor;
|
|
236 |
var p: Longword;
|
|
237 |
begin
|
80
|
238 |
if SDL_MustLock(SpritesData[sprSky].Surface) then
|
|
239 |
SDLTry(SDL_LockSurface(SpritesData[sprSky].Surface) >= 0, true);
|
|
240 |
p:= Longword(SpritesData[sprSky].Surface.pixels);
|
|
241 |
case SpritesData[sprSky].Surface.format.BytesPerPixel of
|
4
|
242 |
1: cSkyColor:= PByte(p)^;
|
|
243 |
2: cSkyColor:= PWord(p)^;
|
|
244 |
3: cSkyColor:= (PByte(p)^) or (PByte(p + 1)^ shl 8) or (PByte(p + 2)^ shl 16);
|
|
245 |
4: cSkyColor:= PLongword(p)^;
|
|
246 |
end;
|
80
|
247 |
if SDL_MustLock(SpritesData[sprSky].Surface) then
|
|
248 |
SDL_UnlockSurface(SpritesData[sprSky].Surface)
|
4
|
249 |
end;
|
|
250 |
|
|
251 |
procedure GetExplosionBorderColor;
|
|
252 |
var f: textfile;
|
|
253 |
c: integer;
|
|
254 |
begin
|
80
|
255 |
s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename;
|
4
|
256 |
WriteToConsole(msgLoading + s + ' ');
|
|
257 |
AssignFile(f, s);
|
|
258 |
{$I-}
|
|
259 |
Reset(f);
|
|
260 |
Readln(f, s);
|
|
261 |
Closefile(f);
|
|
262 |
{$I+}
|
|
263 |
TryDo(IOResult = 0, msgFailed, true);
|
|
264 |
WriteLnToConsole(msgOK);
|
|
265 |
val(s, cExplosionBorderColor, c);
|
|
266 |
if cFullScreen then
|
|
267 |
cExplosionBorderColor:= SDL_MapRGB(PixelFormat, (cExplosionBorderColor shr 16) and $FF,
|
|
268 |
(cExplosionBorderColor shr 8) and $FF,
|
|
269 |
cExplosionBorderColor and $FF)
|
|
270 |
else
|
|
271 |
cExplosionBorderColor:= SDL_MapRGB(LandSurface.format, (cExplosionBorderColor shr 16) and $FF,
|
|
272 |
(cExplosionBorderColor shr 8) and $FF,
|
|
273 |
cExplosionBorderColor and $FF)
|
|
274 |
end;
|
|
275 |
|
|
276 |
begin
|
|
277 |
for fi:= Low(THWFont) to High(THWFont) do
|
|
278 |
with Fontz[fi] do
|
|
279 |
begin
|
53
|
280 |
s:= Pathz[ptFonts] + '/' + Name;
|
4
|
281 |
WriteToConsole(msgLoading + s + ' ');
|
|
282 |
Handle:= TTF_OpenFont(PChar(s), Height);
|
|
283 |
TryDo(Handle <> nil, msgFailed, true);
|
|
284 |
WriteLnToConsole(msgOK)
|
|
285 |
end;
|
|
286 |
AddProgress;
|
53
|
287 |
|
4
|
288 |
tmpsurf:= LandSurface;
|
|
289 |
TryDo(tmpsurf <> nil, msgFailed, true);
|
|
290 |
if cFullScreen then
|
|
291 |
begin
|
|
292 |
LandSurface:= SDL_DisplayFormat(tmpsurf);
|
|
293 |
SDL_FreeSurface(tmpsurf);
|
|
294 |
end else LandSurface:= tmpsurf;
|
35
|
295 |
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
|
4
|
296 |
WriteLnToConsole(msgOK);
|
|
297 |
|
|
298 |
GetExplosionBorderColor;
|
|
299 |
|
|
300 |
AddProgress;
|
|
301 |
for i:= Low(TStuff) to High(TStuff) do
|
53
|
302 |
LoadToSurface(Pathz[StuffLoadData[i].Path] + '/' + StuffLoadData[i].FileName, StoreSurface, StuffPoz[i].x, StuffPoz[i].y);
|
4
|
303 |
|
|
304 |
AddProgress;
|
|
305 |
WriteNames(fnt16);
|
70
|
306 |
MakeCrossHairs;
|
4
|
307 |
LoadGraves;
|
|
308 |
|
|
309 |
AddProgress;
|
|
310 |
for ii:= Low(TSprite) to High(TSprite) do
|
|
311 |
with SpritesData[ii] do
|
80
|
312 |
begin
|
|
313 |
if AltPath = ptNone then
|
|
314 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha)
|
|
315 |
else begin
|
|
316 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false);
|
|
317 |
if Surface = nil then
|
|
318 |
Surface:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha)
|
|
319 |
end;
|
|
320 |
if Width = 0 then Width:= Surface.w;
|
|
321 |
if Height = 0 then Height:= Surface.h
|
|
322 |
end;
|
|
323 |
|
|
324 |
GetSkyColor;
|
4
|
325 |
|
|
326 |
AddProgress;
|
53
|
327 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, false);
|
35
|
328 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
4
|
329 |
HHSurface:= SDL_DisplayFormat(tmpsurf);
|
|
330 |
SDL_FreeSurface(tmpsurf);
|
|
331 |
|
|
332 |
InitHealth;
|
|
333 |
|
|
334 |
{$IFDEF DUMP}
|
|
335 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1);
|
|
336 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1);
|
|
337 |
{$ENDIF}
|
|
338 |
end;
|
|
339 |
|
|
340 |
procedure DrawFromRect(X, Y: integer; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface);
|
|
341 |
var rr: TSDL_Rect;
|
|
342 |
begin
|
|
343 |
rr.x:= X;
|
|
344 |
rr.y:= Y;
|
|
345 |
rr.w:= r.w;
|
|
346 |
rr.h:= r.h;
|
|
347 |
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then
|
|
348 |
begin
|
43
|
349 |
OutError('Blit: ' + SDL_GetError, true);
|
4
|
350 |
exit
|
|
351 |
end;
|
|
352 |
end;
|
|
353 |
|
|
354 |
procedure DrawGear(Stuff: TStuff; X, Y: integer; Surface: PSDL_Surface);
|
|
355 |
begin
|
|
356 |
DrawFromRect(X, Y, @StuffPoz[Stuff], StoreSurface, Surface)
|
|
357 |
end;
|
|
358 |
|
|
359 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface);
|
|
360 |
begin
|
|
361 |
r.y:= r.y + Height * Position;
|
|
362 |
r.h:= Height;
|
|
363 |
DrawFromRect(X, Y, @r, StoreSurface, Surface)
|
|
364 |
end;
|
|
365 |
|
|
366 |
procedure DrawSprite(Sprite: TSprite; X, Y, Position: integer; Surface: PSDL_Surface);
|
|
367 |
var r: TSDL_Rect;
|
|
368 |
begin
|
|
369 |
r.x:= 0;
|
|
370 |
r.w:= SpritesData[Sprite].Width;
|
|
371 |
r.y:= Position * SpritesData[Sprite].Height;
|
|
372 |
r.h:= SpritesData[Sprite].Height;
|
|
373 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface)
|
|
374 |
end;
|
|
375 |
|
43
|
376 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface);
|
|
377 |
var r: TSDL_Rect;
|
|
378 |
begin
|
|
379 |
r.x:= FrameX * SpritesData[Sprite].Width;
|
|
380 |
r.w:= SpritesData[Sprite].Width;
|
|
381 |
r.y:= FrameY * SpritesData[Sprite].Height;
|
|
382 |
r.h:= SpritesData[Sprite].Height;
|
|
383 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface)
|
|
384 |
end;
|
|
385 |
|
4
|
386 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface);
|
|
387 |
var clr: TSDL_Color;
|
|
388 |
tmpsurf: PSDL_Surface;
|
|
389 |
r: TSDL_Rect;
|
|
390 |
begin
|
|
391 |
r.x:= X;
|
|
392 |
r.y:= Y;
|
|
393 |
SDL_GetRGB(cWhiteColor, PixelFormat, @clr.r, @clr.g, @clr.b);
|
74
|
394 |
tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, PChar(s), clr);
|
4
|
395 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r);
|
|
396 |
SDL_FreeSurface(tmpsurf)
|
|
397 |
end;
|
|
398 |
|
|
399 |
procedure DrawLand(X, Y: integer; Surface: PSDL_Surface);
|
|
400 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024);
|
|
401 |
begin
|
|
402 |
DrawFromRect(X, Y, @r, LandSurface, Surface)
|
|
403 |
end;
|
|
404 |
|
47
|
405 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface);
|
|
406 |
begin
|
|
407 |
DrawFromRect(X, Y, Rect, StoreSurface, Surface)
|
|
408 |
end;
|
|
409 |
|
95
|
410 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface);
|
4
|
411 |
begin
|
95
|
412 |
DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface)
|
|
413 |
end;
|
|
414 |
|
|
415 |
procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface);
|
|
416 |
var r: TSDL_Rect;
|
|
417 |
begin
|
|
418 |
r.x:= X - Source.w div 2;
|
|
419 |
r.y:= Top;
|
|
420 |
r.w:= Source.w;
|
|
421 |
r.h:= Source.h;
|
|
422 |
SDL_UpperBlit(Source, nil, Surface, @r)
|
4
|
423 |
end;
|
|
424 |
|
|
425 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface);
|
|
426 |
var r: TSDL_Rect;
|
|
427 |
begin
|
|
428 |
r.x:= Step * 32;
|
|
429 |
r.y:= Pos * 32;
|
|
430 |
if Dir = -1 then r.x:= cHHSurfaceWidth - 32 - r.x;
|
|
431 |
r.w:= 32;
|
|
432 |
r.h:= 32;
|
|
433 |
DrawFromRect(X, Y, @r, HHSurface, Surface)
|
|
434 |
end;
|
|
435 |
|
|
436 |
procedure StoreRelease;
|
|
437 |
var ii: TSprite;
|
|
438 |
begin
|
|
439 |
for ii:= Low(TSprite) to High(TSprite) do
|
|
440 |
SDL_FreeSurface(SpritesData[ii].Surface);
|
|
441 |
SDL_FreeSurface( HHSurface );
|
|
442 |
SDL_FreeSurface(LandSurface );
|
|
443 |
SDL_FreeSurface(StoreSurface )
|
|
444 |
end;
|
|
445 |
|
95
|
446 |
function RenderString(var s: shortstring; Color: integer; font: THWFont): PSDL_Surface;
|
|
447 |
var w, h: integer;
|
|
448 |
begin
|
|
449 |
TTF_SizeUTF8(Fontz[font].Handle, PChar(String(s)), w, h);
|
|
450 |
Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + 6, h + 2, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0);
|
|
451 |
WriteInRoundRect(Result, 0, 0, Color, font, s);
|
|
452 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true)
|
|
453 |
end;
|
|
454 |
|
4
|
455 |
procedure RenderHealth(var Hedgehog: THedgehog);
|
95
|
456 |
var s: shortstring;
|
4
|
457 |
begin
|
|
458 |
str(Hedgehog.Gear.Health, s);
|
95
|
459 |
if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag);
|
|
460 |
Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Color, fnt16)
|
4
|
461 |
end;
|
|
462 |
|
|
463 |
procedure AddProgress;
|
|
464 |
const Step: Longword = 0;
|
|
465 |
ProgrSurf: PSDL_Surface = nil;
|
71
|
466 |
MaxCalls = 11; // MaxCalls should be the count of calls to AddProgress to prevent memory leakage
|
4
|
467 |
var r: TSDL_Rect;
|
|
468 |
begin
|
|
469 |
if Step = 0 then
|
|
470 |
begin
|
|
471 |
WriteToConsole(msgLoading + 'progress sprite... ');
|
|
472 |
ProgrSurf:= IMG_Load(PChar(string('Data/Graphics/BigDigits.png')));
|
|
473 |
SDLTry(ProgrSurf <> nil, true);
|
|
474 |
WriteLnToConsole(msgOK)
|
|
475 |
end;
|
|
476 |
SDL_FillRect(SDLPrimSurface, nil, 0);
|
|
477 |
r.x:= 0;
|
|
478 |
r.w:= 32;
|
|
479 |
r.h:= 32;
|
71
|
480 |
r.y:= (Step mod 10) * 32;
|
4
|
481 |
DrawFromRect(cScreenWidth div 2 - 16, cScreenHeight div 2 - 16, @r, ProgrSurf, SDLPrimSurface);
|
|
482 |
SDL_Flip(SDLPrimSurface);
|
|
483 |
inc(Step);
|
|
484 |
if Step = MaxCalls then
|
|
485 |
begin
|
|
486 |
WriteLnToConsole('Freeing progress surface... ');
|
|
487 |
SDL_FreeSurface(ProgrSurf)
|
|
488 |
end;
|
|
489 |
end;
|
|
490 |
|
80
|
491 |
function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true): PSDL_Surface;
|
30
|
492 |
var tmpsurf: PSDL_Surface;
|
4
|
493 |
begin
|
|
494 |
WriteToConsole(msgLoading + filename + '... ');
|
74
|
495 |
tmpsurf:= IMG_Load(PChar(filename + '.' + cBitsStr + '.png'));
|
|
496 |
if tmpsurf = nil then
|
|
497 |
tmpsurf:= IMG_Load(PChar(filename + '.png'));
|
80
|
498 |
|
|
499 |
if tmpsurf = nil then
|
|
500 |
if critical then OutError(msgFailed, true)
|
|
501 |
else begin
|
|
502 |
WriteLnToConsole(msgFailed);
|
|
503 |
Result:= nil;
|
|
504 |
exit
|
|
505 |
end;
|
|
506 |
|
35
|
507 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
80
|
508 |
if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf)
|
|
509 |
else Result:= SDL_DisplayFormat(tmpsurf);
|
4
|
510 |
WriteLnToConsole(msgOK)
|
|
511 |
end;
|
|
512 |
|
|
513 |
end.
|