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( 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 |
|
47
|
90 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface);
|
|
91 |
var r: TSDL_Rect;
|
|
92 |
begin
|
|
93 |
r:= rect^;
|
|
94 |
SDL_FillRect(Surface, @r, 0);
|
|
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
|
|
120 |
TTF_SizeText(Fontz[Font].Handle, PChar(s), w, h);
|
|
121 |
Result.x:= X;
|
|
122 |
Result.y:= Y;
|
|
123 |
Result.w:= w + 6;
|
|
124 |
Result.h:= h + 6;
|
47
|
125 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface);
|
4
|
126 |
SDL_GetRGB(Color, Surface.format, @clr.r, @clr.g, @clr.b);
|
|
127 |
tmpsurf:= TTF_RenderText_Blended(Fontz[Font].Handle, PChar(s), clr);
|
|
128 |
Result.x:= X + 3;
|
|
129 |
Result.y:= Y + 3;
|
|
130 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result);
|
|
131 |
SDL_FreeSurface(tmpsurf);
|
|
132 |
Result.x:= X;
|
|
133 |
Result.y:= Y;
|
|
134 |
Result.w:= w + 6;
|
|
135 |
Result.h:= h + 6
|
|
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;
|
49
|
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);
|
|
166 |
DrawRoundRect(@rr, Team.Color, Team.Color, StoreSurface);
|
|
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;
|
4
|
193 |
WriteToConsole(msgLoading + s + ' ');
|
|
194 |
tmpsurf:= IMG_Load(PChar(s));
|
|
195 |
TryDo(tmpsurf <> nil, msgFailed, true);
|
|
196 |
WriteLnToConsole(msgOK);
|
|
197 |
TransColor:= SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF);
|
|
198 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, TransColor) = 0, errmsgTransparentSet, true);
|
|
199 |
|
|
200 |
Team:= TeamsList;
|
|
201 |
while Team<>nil do
|
|
202 |
begin
|
|
203 |
SDL_FillRect(StoreSurface, @r, Team.Color);
|
|
204 |
SDL_UpperBlit(tmpsurf, nil, StoreSurface, @r);
|
|
205 |
Team.CrossHairRect:= r;
|
|
206 |
inc(r.x, 16);
|
|
207 |
Team:= Team.Next
|
|
208 |
end;
|
|
209 |
|
|
210 |
SDL_FreeSurface(tmpsurf)
|
|
211 |
end;
|
|
212 |
|
|
213 |
procedure InitHealth;
|
|
214 |
var p: PTeam;
|
|
215 |
i, t: integer;
|
|
216 |
begin
|
|
217 |
p:= TeamsList;
|
|
218 |
t:= 0;
|
|
219 |
while p <> nil do
|
|
220 |
begin
|
|
221 |
for i:= 0 to cMaxHHIndex do
|
|
222 |
if p.Hedgehogs[i].Gear <> nil then
|
|
223 |
begin
|
|
224 |
p.Hedgehogs[i].HealthRect.y:= t;
|
|
225 |
RenderHealth(p.Hedgehogs[i]);
|
|
226 |
inc(t, p.Hedgehogs[i].HealthRect.h)
|
|
227 |
end;
|
|
228 |
p:= p.Next
|
|
229 |
end
|
|
230 |
end;
|
|
231 |
|
|
232 |
procedure LoadGraves;
|
|
233 |
var p: PTeam;
|
|
234 |
l: integer;
|
|
235 |
begin
|
|
236 |
p:= TeamsList;
|
|
237 |
l:= 512;
|
|
238 |
while p <> nil do
|
|
239 |
begin
|
|
240 |
dec(l, 32);
|
|
241 |
if p.GraveName = '' then p.GraveName:= 'Simple';
|
53
|
242 |
LoadToSurface(Pathz[ptGraves] + '/' + p.GraveName + '.png', StoreSurface, l, 512);
|
4
|
243 |
p.GraveRect.x:= l;
|
|
244 |
p.GraveRect.y:= 512;
|
|
245 |
p.GraveRect.w:= 32;
|
|
246 |
p.GraveRect.h:= 256;
|
|
247 |
p:= p.Next
|
|
248 |
end
|
|
249 |
end;
|
|
250 |
|
|
251 |
procedure GetSkyColor;
|
|
252 |
var p: Longword;
|
|
253 |
begin
|
|
254 |
if SDL_MustLock(StoreSurface) then
|
|
255 |
SDLTry(SDL_LockSurface(StoreSurface) >= 0, true);
|
|
256 |
p:= Longword(StoreSurface.pixels) + Word(StuffPoz[sSky].x) * StoreSurface.format.BytesPerPixel;
|
|
257 |
case StoreSurface.format.BytesPerPixel of
|
|
258 |
1: cSkyColor:= PByte(p)^;
|
|
259 |
2: cSkyColor:= PWord(p)^;
|
|
260 |
3: cSkyColor:= (PByte(p)^) or (PByte(p + 1)^ shl 8) or (PByte(p + 2)^ shl 16);
|
|
261 |
4: cSkyColor:= PLongword(p)^;
|
|
262 |
end;
|
|
263 |
if SDL_MustLock(StoreSurface) then
|
|
264 |
SDL_UnlockSurface(StoreSurface)
|
|
265 |
end;
|
|
266 |
|
|
267 |
procedure GetExplosionBorderColor;
|
|
268 |
var f: textfile;
|
|
269 |
c: integer;
|
|
270 |
begin
|
53
|
271 |
s:= Pathz[ptThemeCurrent] + '/' + cThemeCFGFilename;
|
4
|
272 |
WriteToConsole(msgLoading + s + ' ');
|
|
273 |
AssignFile(f, s);
|
|
274 |
{$I-}
|
|
275 |
Reset(f);
|
|
276 |
Readln(f, s);
|
|
277 |
Closefile(f);
|
|
278 |
{$I+}
|
|
279 |
TryDo(IOResult = 0, msgFailed, true);
|
|
280 |
WriteLnToConsole(msgOK);
|
|
281 |
val(s, cExplosionBorderColor, c);
|
|
282 |
if cFullScreen then
|
|
283 |
cExplosionBorderColor:= SDL_MapRGB(PixelFormat, (cExplosionBorderColor shr 16) and $FF,
|
|
284 |
(cExplosionBorderColor shr 8) and $FF,
|
|
285 |
cExplosionBorderColor and $FF)
|
|
286 |
else
|
|
287 |
cExplosionBorderColor:= SDL_MapRGB(LandSurface.format, (cExplosionBorderColor shr 16) and $FF,
|
|
288 |
(cExplosionBorderColor shr 8) and $FF,
|
|
289 |
cExplosionBorderColor and $FF)
|
|
290 |
end;
|
|
291 |
|
|
292 |
begin
|
|
293 |
for fi:= Low(THWFont) to High(THWFont) do
|
|
294 |
with Fontz[fi] do
|
|
295 |
begin
|
53
|
296 |
s:= Pathz[ptFonts] + '/' + Name;
|
4
|
297 |
WriteToConsole(msgLoading + s + ' ');
|
|
298 |
Handle:= TTF_OpenFont(PChar(s), Height);
|
|
299 |
TryDo(Handle <> nil, msgFailed, true);
|
|
300 |
WriteLnToConsole(msgOK)
|
|
301 |
end;
|
|
302 |
AddProgress;
|
53
|
303 |
|
4
|
304 |
tmpsurf:= LandSurface;
|
|
305 |
TryDo(tmpsurf <> nil, msgFailed, true);
|
|
306 |
if cFullScreen then
|
|
307 |
begin
|
|
308 |
LandSurface:= SDL_DisplayFormat(tmpsurf);
|
|
309 |
SDL_FreeSurface(tmpsurf);
|
|
310 |
end else LandSurface:= tmpsurf;
|
35
|
311 |
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
|
4
|
312 |
WriteLnToConsole(msgOK);
|
|
313 |
|
|
314 |
GetExplosionBorderColor;
|
|
315 |
|
|
316 |
AddProgress;
|
|
317 |
for i:= Low(TStuff) to High(TStuff) do
|
53
|
318 |
LoadToSurface(Pathz[StuffLoadData[i].Path] + '/' + StuffLoadData[i].FileName, StoreSurface, StuffPoz[i].x, StuffPoz[i].y);
|
4
|
319 |
|
|
320 |
AddProgress;
|
|
321 |
WriteNames(fnt16);
|
|
322 |
MakeCrosshairs;
|
|
323 |
LoadGraves;
|
|
324 |
|
|
325 |
GetSkyColor;
|
|
326 |
|
|
327 |
AddProgress;
|
|
328 |
for ii:= Low(TSprite) to High(TSprite) do
|
|
329 |
with SpritesData[ii] do
|
53
|
330 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha);
|
4
|
331 |
|
|
332 |
AddProgress;
|
53
|
333 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, false);
|
35
|
334 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
4
|
335 |
HHSurface:= SDL_DisplayFormat(tmpsurf);
|
|
336 |
SDL_FreeSurface(tmpsurf);
|
|
337 |
|
|
338 |
InitHealth;
|
|
339 |
|
|
340 |
{$IFDEF DUMP}
|
|
341 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1);
|
|
342 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1);
|
|
343 |
SDL_SaveBMP_RW(TempSurface, SDL_RWFromFile('TempSurface.bmp', 'wb'), 1);
|
|
344 |
{$ENDIF}
|
|
345 |
end;
|
|
346 |
|
|
347 |
procedure DrawFromRect(X, Y: integer; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface);
|
|
348 |
var rr: TSDL_Rect;
|
|
349 |
begin
|
|
350 |
rr.x:= X;
|
|
351 |
rr.y:= Y;
|
|
352 |
rr.w:= r.w;
|
|
353 |
rr.h:= r.h;
|
|
354 |
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then
|
|
355 |
begin
|
43
|
356 |
OutError('Blit: ' + SDL_GetError, true);
|
4
|
357 |
exit
|
|
358 |
end;
|
|
359 |
end;
|
|
360 |
|
|
361 |
procedure DrawGear(Stuff: TStuff; X, Y: integer; Surface: PSDL_Surface);
|
|
362 |
begin
|
|
363 |
DrawFromRect(X, Y, @StuffPoz[Stuff], StoreSurface, Surface)
|
|
364 |
end;
|
|
365 |
|
|
366 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface);
|
|
367 |
begin
|
|
368 |
r.y:= r.y + Height * Position;
|
|
369 |
r.h:= Height;
|
|
370 |
DrawFromRect(X, Y, @r, StoreSurface, Surface)
|
|
371 |
end;
|
|
372 |
|
|
373 |
procedure DrawSprite(Sprite: TSprite; X, Y, Position: integer; Surface: PSDL_Surface);
|
|
374 |
var r: TSDL_Rect;
|
|
375 |
begin
|
|
376 |
r.x:= 0;
|
|
377 |
r.w:= SpritesData[Sprite].Width;
|
|
378 |
r.y:= Position * SpritesData[Sprite].Height;
|
|
379 |
r.h:= SpritesData[Sprite].Height;
|
|
380 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface)
|
|
381 |
end;
|
|
382 |
|
43
|
383 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface);
|
|
384 |
var r: TSDL_Rect;
|
|
385 |
begin
|
|
386 |
r.x:= FrameX * SpritesData[Sprite].Width;
|
|
387 |
r.w:= SpritesData[Sprite].Width;
|
|
388 |
r.y:= FrameY * SpritesData[Sprite].Height;
|
|
389 |
r.h:= SpritesData[Sprite].Height;
|
|
390 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface)
|
|
391 |
end;
|
|
392 |
|
4
|
393 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface);
|
|
394 |
var clr: TSDL_Color;
|
|
395 |
tmpsurf: PSDL_Surface;
|
|
396 |
r: TSDL_Rect;
|
|
397 |
begin
|
|
398 |
r.x:= X;
|
|
399 |
r.y:= Y;
|
|
400 |
SDL_GetRGB(cWhiteColor, PixelFormat, @clr.r, @clr.g, @clr.b);
|
|
401 |
tmpsurf:= TTF_RenderText_Solid(Fontz[Font].Handle, PChar(s), clr);
|
|
402 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r);
|
|
403 |
SDL_FreeSurface(tmpsurf)
|
|
404 |
end;
|
|
405 |
|
|
406 |
procedure DrawLand(X, Y: integer; Surface: PSDL_Surface);
|
|
407 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024);
|
|
408 |
begin
|
|
409 |
DrawFromRect(X, Y, @r, LandSurface, Surface)
|
|
410 |
end;
|
|
411 |
|
47
|
412 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface);
|
|
413 |
begin
|
|
414 |
DrawFromRect(X, Y, Rect, StoreSurface, Surface)
|
|
415 |
end;
|
|
416 |
|
4
|
417 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface; const fromTempSurf: boolean = false);
|
|
418 |
begin
|
|
419 |
if fromTempSurf then DrawFromRect(X - (Rect.w) div 2, Y, @Rect, TempSurface, Surface)
|
|
420 |
else DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface)
|
|
421 |
end;
|
|
422 |
|
|
423 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface);
|
|
424 |
var r: TSDL_Rect;
|
|
425 |
begin
|
|
426 |
r.x:= Step * 32;
|
|
427 |
r.y:= Pos * 32;
|
|
428 |
if Dir = -1 then r.x:= cHHSurfaceWidth - 32 - r.x;
|
|
429 |
r.w:= 32;
|
|
430 |
r.h:= 32;
|
|
431 |
DrawFromRect(X, Y, @r, HHSurface, Surface)
|
|
432 |
end;
|
|
433 |
|
|
434 |
procedure StoreRelease;
|
|
435 |
var ii: TSprite;
|
|
436 |
begin
|
|
437 |
for ii:= Low(TSprite) to High(TSprite) do
|
|
438 |
SDL_FreeSurface(SpritesData[ii].Surface);
|
|
439 |
SDL_FreeSurface( HHSurface );
|
|
440 |
SDL_FreeSurface(TempSurface );
|
|
441 |
SDL_FreeSurface(LandSurface );
|
|
442 |
SDL_FreeSurface(StoreSurface )
|
|
443 |
end;
|
|
444 |
|
|
445 |
procedure RenderHealth(var Hedgehog: THedgehog);
|
30
|
446 |
var s: string[15];
|
4
|
447 |
begin
|
|
448 |
str(Hedgehog.Gear.Health, s);
|
|
449 |
Hedgehog.HealthRect:= WriteInRoundRect(TempSurface, Hedgehog.HealthRect.x, Hedgehog.HealthRect.y, Hedgehog.Team.Color, fnt16, s);
|
|
450 |
if Hedgehog.Gear.Damage > 0 then
|
|
451 |
begin
|
|
452 |
str(Hedgehog.Gear.Damage, s);
|
|
453 |
Hedgehog.HealthTagRect:= WriteInRoundRect(TempSurface, Hedgehog.HealthRect.x + Hedgehog.HealthRect.w, Hedgehog.HealthRect.y, Hedgehog.Team.Color, fnt16, s)
|
|
454 |
end;
|
|
455 |
end;
|
|
456 |
|
|
457 |
function RenderString(var s: shortstring; Color, Pos: integer): TSDL_Rect;
|
|
458 |
begin
|
|
459 |
Result:= WriteInRoundRect(TempSurface, 64, Pos * Fontz[fntBig].Height, Color, fntBig, s);
|
|
460 |
end;
|
|
461 |
|
|
462 |
procedure AddProgress;
|
|
463 |
const Step: Longword = 0;
|
|
464 |
ProgrSurf: PSDL_Surface = nil;
|
|
465 |
MaxCalls = 10; // MaxCalls should be the count of calls to AddProgress to prevent memory leakage
|
|
466 |
var r: TSDL_Rect;
|
|
467 |
begin
|
|
468 |
if Step = 0 then
|
|
469 |
begin
|
|
470 |
WriteToConsole(msgLoading + 'progress sprite... ');
|
|
471 |
ProgrSurf:= IMG_Load(PChar(string('Data/Graphics/BigDigits.png')));
|
|
472 |
SDLTry(ProgrSurf <> nil, true);
|
|
473 |
WriteLnToConsole(msgOK)
|
|
474 |
end;
|
|
475 |
SDL_FillRect(SDLPrimSurface, nil, 0);
|
|
476 |
r.x:= 0;
|
|
477 |
r.w:= 32;
|
|
478 |
r.h:= 32;
|
|
479 |
r.y:= Step * 32;
|
|
480 |
DrawFromRect(cScreenWidth div 2 - 16, cScreenHeight div 2 - 16, @r, ProgrSurf, SDLPrimSurface);
|
|
481 |
SDL_Flip(SDLPrimSurface);
|
|
482 |
inc(Step);
|
|
483 |
if Step = MaxCalls then
|
|
484 |
begin
|
|
485 |
WriteLnToConsole('Freeing progress surface... ');
|
|
486 |
SDL_FreeSurface(ProgrSurf)
|
|
487 |
end;
|
|
488 |
end;
|
|
489 |
|
35
|
490 |
function LoadImage(filename: string; hasAlpha: boolean): PSDL_Surface;
|
30
|
491 |
var tmpsurf: PSDL_Surface;
|
4
|
492 |
begin
|
|
493 |
WriteToConsole(msgLoading + filename + '... ');
|
30
|
494 |
tmpsurf:= IMG_Load(PChar(filename));
|
|
495 |
TryDo(tmpsurf <> nil, msgFailed, true);
|
35
|
496 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
30
|
497 |
if cFullScreen then
|
|
498 |
begin
|
35
|
499 |
if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf)
|
|
500 |
else Result:= SDL_DisplayFormat(tmpsurf);
|
30
|
501 |
SDL_FreeSurface(tmpsurf);
|
|
502 |
end else Result:= tmpsurf;
|
4
|
503 |
WriteLnToConsole(msgOK)
|
|
504 |
end;
|
|
505 |
|
|
506 |
end.
|