author | displacer |
Fri, 18 Aug 2006 20:37:50 +0000 | |
changeset 117 | d21a48200772 |
parent 108 | 08f1fe6f21f8 |
child 161 | d8870bbf960e |
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 |
* |
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); |
108 | 52 |
function RenderString(s: string; 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; |
|
107 | 236 |
var p: PByteArray; |
4 | 237 |
begin |
80 | 238 |
if SDL_MustLock(SpritesData[sprSky].Surface) then |
239 |
SDLTry(SDL_LockSurface(SpritesData[sprSky].Surface) >= 0, true); |
|
107 | 240 |
p:= SpritesData[sprSky].Surface.pixels; |
80 | 241 |
case SpritesData[sprSky].Surface.format.BytesPerPixel of |
4 | 242 |
1: cSkyColor:= PByte(p)^; |
243 |
2: cSkyColor:= PWord(p)^; |
|
107 | 244 |
3: cSkyColor:= (p^[0]) or (p^[1] shl 8) or (p^[2] shl 16); |
4 | 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 |
|
105 | 288 |
WriteToConsole('LandSurface tuning... '); |
4 | 289 |
tmpsurf:= LandSurface; |
290 |
TryDo(tmpsurf <> nil, msgFailed, true); |
|
291 |
if cFullScreen then |
|
292 |
begin |
|
293 |
LandSurface:= SDL_DisplayFormat(tmpsurf); |
|
294 |
SDL_FreeSurface(tmpsurf); |
|
295 |
end else LandSurface:= tmpsurf; |
|
35 | 296 |
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
4 | 297 |
WriteLnToConsole(msgOK); |
298 |
||
299 |
GetExplosionBorderColor; |
|
300 |
||
301 |
AddProgress; |
|
302 |
for i:= Low(TStuff) to High(TStuff) do |
|
53 | 303 |
LoadToSurface(Pathz[StuffLoadData[i].Path] + '/' + StuffLoadData[i].FileName, StoreSurface, StuffPoz[i].x, StuffPoz[i].y); |
4 | 304 |
|
305 |
AddProgress; |
|
306 |
WriteNames(fnt16); |
|
70 | 307 |
MakeCrossHairs; |
4 | 308 |
LoadGraves; |
309 |
||
310 |
AddProgress; |
|
311 |
for ii:= Low(TSprite) to High(TSprite) do |
|
312 |
with SpritesData[ii] do |
|
80 | 313 |
begin |
314 |
if AltPath = ptNone then |
|
315 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha) |
|
316 |
else begin |
|
317 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false); |
|
318 |
if Surface = nil then |
|
319 |
Surface:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha) |
|
320 |
end; |
|
321 |
if Width = 0 then Width:= Surface.w; |
|
322 |
if Height = 0 then Height:= Surface.h |
|
323 |
end; |
|
324 |
||
325 |
GetSkyColor; |
|
4 | 326 |
|
327 |
AddProgress; |
|
53 | 328 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, false); |
35 | 329 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
4 | 330 |
HHSurface:= SDL_DisplayFormat(tmpsurf); |
331 |
SDL_FreeSurface(tmpsurf); |
|
332 |
||
333 |
InitHealth; |
|
334 |
||
335 |
{$IFDEF DUMP} |
|
336 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
337 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
338 |
{$ENDIF} |
|
339 |
end; |
|
340 |
||
341 |
procedure DrawFromRect(X, Y: integer; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface); |
|
342 |
var rr: TSDL_Rect; |
|
343 |
begin |
|
344 |
rr.x:= X; |
|
345 |
rr.y:= Y; |
|
346 |
rr.w:= r.w; |
|
347 |
rr.h:= r.h; |
|
348 |
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then |
|
349 |
begin |
|
43 | 350 |
OutError('Blit: ' + SDL_GetError, true); |
4 | 351 |
exit |
352 |
end; |
|
353 |
end; |
|
354 |
||
355 |
procedure DrawGear(Stuff: TStuff; X, Y: integer; Surface: PSDL_Surface); |
|
356 |
begin |
|
357 |
DrawFromRect(X, Y, @StuffPoz[Stuff], StoreSurface, Surface) |
|
358 |
end; |
|
359 |
||
360 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface); |
|
361 |
begin |
|
362 |
r.y:= r.y + Height * Position; |
|
363 |
r.h:= Height; |
|
364 |
DrawFromRect(X, Y, @r, StoreSurface, Surface) |
|
365 |
end; |
|
366 |
||
367 |
procedure DrawSprite(Sprite: TSprite; X, Y, Position: integer; Surface: PSDL_Surface); |
|
368 |
var r: TSDL_Rect; |
|
369 |
begin |
|
370 |
r.x:= 0; |
|
371 |
r.w:= SpritesData[Sprite].Width; |
|
372 |
r.y:= Position * SpritesData[Sprite].Height; |
|
373 |
r.h:= SpritesData[Sprite].Height; |
|
374 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
|
375 |
end; |
|
376 |
||
43 | 377 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface); |
378 |
var r: TSDL_Rect; |
|
379 |
begin |
|
380 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
381 |
r.w:= SpritesData[Sprite].Width; |
|
382 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
383 |
r.h:= SpritesData[Sprite].Height; |
|
384 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
|
385 |
end; |
|
386 |
||
4 | 387 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
388 |
var clr: TSDL_Color; |
|
389 |
tmpsurf: PSDL_Surface; |
|
390 |
r: TSDL_Rect; |
|
391 |
begin |
|
392 |
r.x:= X; |
|
393 |
r.y:= Y; |
|
394 |
SDL_GetRGB(cWhiteColor, PixelFormat, @clr.r, @clr.g, @clr.b); |
|
74 | 395 |
tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, PChar(s), clr); |
4 | 396 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
397 |
SDL_FreeSurface(tmpsurf) |
|
398 |
end; |
|
399 |
||
400 |
procedure DrawLand(X, Y: integer; Surface: PSDL_Surface); |
|
401 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024); |
|
402 |
begin |
|
403 |
DrawFromRect(X, Y, @r, LandSurface, Surface) |
|
404 |
end; |
|
405 |
||
47 | 406 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface); |
407 |
begin |
|
408 |
DrawFromRect(X, Y, Rect, StoreSurface, Surface) |
|
409 |
end; |
|
410 |
||
95 | 411 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); |
4 | 412 |
begin |
95 | 413 |
DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface) |
414 |
end; |
|
415 |
||
416 |
procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface); |
|
417 |
var r: TSDL_Rect; |
|
418 |
begin |
|
419 |
r.x:= X - Source.w div 2; |
|
420 |
r.y:= Top; |
|
421 |
r.w:= Source.w; |
|
422 |
r.h:= Source.h; |
|
423 |
SDL_UpperBlit(Source, nil, Surface, @r) |
|
4 | 424 |
end; |
425 |
||
426 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface); |
|
427 |
var r: TSDL_Rect; |
|
428 |
begin |
|
429 |
r.x:= Step * 32; |
|
430 |
r.y:= Pos * 32; |
|
431 |
if Dir = -1 then r.x:= cHHSurfaceWidth - 32 - r.x; |
|
432 |
r.w:= 32; |
|
433 |
r.h:= 32; |
|
434 |
DrawFromRect(X, Y, @r, HHSurface, Surface) |
|
435 |
end; |
|
436 |
||
437 |
procedure StoreRelease; |
|
438 |
var ii: TSprite; |
|
439 |
begin |
|
440 |
for ii:= Low(TSprite) to High(TSprite) do |
|
441 |
SDL_FreeSurface(SpritesData[ii].Surface); |
|
442 |
SDL_FreeSurface( HHSurface ); |
|
443 |
SDL_FreeSurface(LandSurface ); |
|
444 |
SDL_FreeSurface(StoreSurface ) |
|
445 |
end; |
|
446 |
||
108 | 447 |
function RenderString(s: string; Color: integer; font: THWFont): PSDL_Surface; |
95 | 448 |
var w, h: integer; |
449 |
begin |
|
108 | 450 |
TTF_SizeUTF8(Fontz[font].Handle, PChar(s), w, h); |
95 | 451 |
Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + 6, h + 2, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0); |
107 | 452 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
95 | 453 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
454 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true) |
|
455 |
end; |
|
456 |
||
4 | 457 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 458 |
var s: shortstring; |
4 | 459 |
begin |
460 |
str(Hedgehog.Gear.Health, s); |
|
95 | 461 |
if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
462 |
Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Color, fnt16) |
|
4 | 463 |
end; |
464 |
||
465 |
procedure AddProgress; |
|
466 |
const Step: Longword = 0; |
|
467 |
ProgrSurf: PSDL_Surface = nil; |
|
71 | 468 |
MaxCalls = 11; // MaxCalls should be the count of calls to AddProgress to prevent memory leakage |
4 | 469 |
var r: TSDL_Rect; |
470 |
begin |
|
471 |
if Step = 0 then |
|
472 |
begin |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
95
diff
changeset
|
473 |
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
|
474 |
ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/BigDigits', false); |
4 | 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. |