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