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