author | unc0rr |
Mon, 16 Oct 2006 17:10:30 +0000 | |
changeset 198 | 6f00e0f4cb88 |
parent 196 | 993cf173218b |
child 199 | f156e54736a4 |
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 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
19 |
unit uStore; |
|
20 |
interface |
|
21 |
uses uConsts, uTeams, SDLh; |
|
22 |
{$INCLUDE options.inc} |
|
23 |
||
24 |
procedure StoreInit; |
|
25 |
procedure StoreLoad; |
|
26 |
procedure StoreRelease; |
|
27 |
procedure DrawGear(Stuff : TStuff; X, Y: integer; Surface: PSDL_Surface); |
|
28 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface); |
|
161 | 29 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: integer; Surface: PSDL_Surface); |
43 | 30 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface); |
198 | 31 |
procedure DrawSurfSprite(X, Y, Height, Frame: integer; Source, Surface: PSDL_Surface); |
4 | 32 |
procedure DrawLand (X, Y: integer; Surface: PSDL_Surface); |
33 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
|
95 | 34 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); |
35 |
procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface); |
|
47 | 36 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface); |
4 | 37 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface); |
108 | 38 |
function RenderString(s: string; Color: integer; font: THWFont): PSDL_Surface; |
4 | 39 |
procedure RenderHealth(var Hedgehog: THedgehog); |
40 |
procedure AddProgress; |
|
198 | 41 |
function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true; const setTransparent: boolean = true): PSDL_Surface; |
4 | 42 |
|
43 |
var PixelFormat: PSDL_PixelFormat; |
|
44 |
SDLPrimSurface: PSDL_Surface; |
|
45 |
||
46 |
implementation |
|
196 | 47 |
uses uMisc, uConsole, uLand; |
4 | 48 |
|
49 |
var StoreSurface, |
|
50 |
HHSurface: PSDL_Surface; |
|
51 |
||
52 |
procedure StoreInit; |
|
53 |
begin |
|
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
190
diff
changeset
|
54 |
StoreSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 576, 1024, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, PixelFormat.AMask); |
4 | 55 |
TryDo( StoreSurface <> nil, errmsgCreateSurface + ': store' , true); |
37 | 56 |
SDL_FillRect(StoreSurface, nil, 0); |
4 | 57 |
|
58 |
TryDo(SDL_SetColorKey( StoreSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
|
59 |
end; |
|
60 |
||
61 |
procedure LoadToSurface(Filename: String; Surface: PSDL_Surface; X, Y: integer); |
|
62 |
var tmpsurf: PSDL_Surface; |
|
63 |
rr: TSDL_Rect; |
|
64 |
begin |
|
35 | 65 |
tmpsurf:= LoadImage(Filename, false); |
4 | 66 |
rr.x:= X; |
67 |
rr.y:= Y; |
|
68 |
SDL_UpperBlit(tmpsurf, nil, Surface, @rr); |
|
69 |
SDL_FreeSurface(tmpsurf); |
|
70 |
end; |
|
71 |
||
83 | 72 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; const Clear: boolean = true); |
47 | 73 |
var r: TSDL_Rect; |
74 |
begin |
|
75 |
r:= rect^; |
|
83 | 76 |
if Clear then SDL_FillRect(Surface, @r, 0); |
47 | 77 |
r.y:= rect.y + 1; |
78 |
r.h:= rect.h - 2; |
|
79 |
SDL_FillRect(Surface, @r, BorderColor); |
|
80 |
r.x:= rect.x + 1; |
|
81 |
r.w:= rect.w - 2; |
|
82 |
r.y:= rect.y; |
|
83 |
r.h:= rect.h; |
|
84 |
SDL_FillRect(Surface, @r, BorderColor); |
|
85 |
r.x:= rect.x + 2; |
|
86 |
r.y:= rect.y + 1; |
|
87 |
r.w:= rect.w - 4; |
|
88 |
r.h:= rect.h - 2; |
|
89 |
SDL_FillRect(Surface, @r, FillColor); |
|
90 |
r.x:= rect.x + 1; |
|
91 |
r.y:= rect.y + 2; |
|
92 |
r.w:= rect.w - 2; |
|
93 |
r.h:= rect.h - 4; |
|
94 |
SDL_FillRect(Surface, @r, FillColor) |
|
95 |
end; |
|
96 |
||
4 | 97 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: integer; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
98 |
var w, h: integer; |
|
99 |
tmpsurf: PSDL_Surface; |
|
100 |
clr: TSDL_Color; |
|
101 |
begin |
|
74 | 102 |
TTF_SizeUTF8(Fontz[Font].Handle, PChar(s), w, h); |
4 | 103 |
Result.x:= X; |
104 |
Result.y:= Y; |
|
105 |
Result.w:= w + 6; |
|
74 | 106 |
Result.h:= h + 2; |
47 | 107 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface); |
189 | 108 |
clr.r:= Color shr 16; |
109 |
clr.g:= (Color shr 8) and $FF; |
|
110 |
clr.b:= Color and $FF; |
|
74 | 111 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, PChar(s), clr); |
4 | 112 |
Result.x:= X + 3; |
74 | 113 |
Result.y:= Y + 1; |
198 | 114 |
TryDo(tmpsurf <> nil, errmsgRenderText, true); |
4 | 115 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
116 |
SDL_FreeSurface(tmpsurf); |
|
117 |
Result.x:= X; |
|
118 |
Result.y:= Y; |
|
119 |
Result.w:= w + 6; |
|
74 | 120 |
Result.h:= h + 2 |
4 | 121 |
end; |
122 |
||
123 |
procedure StoreLoad; |
|
124 |
var i: TStuff; |
|
125 |
ii: TSprite; |
|
126 |
fi: THWFont; |
|
127 |
s: string; |
|
128 |
tmpsurf: PSDL_Surface; |
|
129 |
||
130 |
procedure WriteNames(Font: THWFont); |
|
131 |
var Team: PTeam; |
|
132 |
i: integer; |
|
47 | 133 |
r, rr: TSDL_Rect; |
49 | 134 |
drY: integer; |
4 | 135 |
begin |
136 |
r.x:= 0; |
|
137 |
r.y:= 272; |
|
70 | 138 |
drY:= cScreenHeight - 4; |
4 | 139 |
Team:= TeamsList; |
140 |
while Team<>nil do |
|
141 |
begin |
|
47 | 142 |
r.w:= 104; |
95 | 143 |
Team.NameTag:= RenderString(Team.TeamName, Team.Color, Font); |
47 | 144 |
r.w:= cTeamHealthWidth + 5; |
95 | 145 |
r.h:= Team.NameTag.h; |
47 | 146 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, StoreSurface); |
147 |
Team.HealthRect:= r; |
|
148 |
rr:= r; |
|
149 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
189 | 150 |
DrawRoundRect(@rr, Team.AdjColor, Team.AdjColor, StoreSurface, false); |
47 | 151 |
inc(r.y, r.h); |
49 | 152 |
dec(drY, r.h + 2); |
153 |
Team.DrawHealthY:= drY; |
|
4 | 154 |
for i:= 0 to 7 do |
95 | 155 |
with Team.Hedgehogs[i] do |
156 |
if Gear <> nil then |
|
157 |
NameTag:= RenderString(Name, Team.Color, fnt16); |
|
4 | 158 |
Team:= Team.Next |
159 |
end; |
|
160 |
end; |
|
161 |
||
162 |
procedure MakeCrossHairs; |
|
163 |
var Team: PTeam; |
|
164 |
tmpsurf: PSDL_Surface; |
|
165 |
s: string; |
|
166 |
begin |
|
53 | 167 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
198 | 168 |
tmpsurf:= LoadImage(PChar(s), true, true, false); |
4 | 169 |
|
170 |
Team:= TeamsList; |
|
171 |
while Team<>nil do |
|
172 |
begin |
|
198 | 173 |
Team.CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, 24, 360, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, PixelFormat.AMask); |
174 |
TryDo(Team.CrosshairSurf <> nil, errmsgCreateSurface, true); |
|
175 |
SDL_FillRect(Team.CrosshairSurf, nil, Team.AdjColor); |
|
176 |
SDL_UpperBlit(tmpsurf, nil, Team.CrosshairSurf, nil); |
|
177 |
TryDo(SDL_SetColorKey(Team.CrosshairSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
|
4 | 178 |
Team:= Team.Next |
179 |
end; |
|
180 |
||
181 |
SDL_FreeSurface(tmpsurf) |
|
182 |
end; |
|
183 |
||
184 |
procedure InitHealth; |
|
185 |
var p: PTeam; |
|
95 | 186 |
i: integer; |
4 | 187 |
begin |
188 |
p:= TeamsList; |
|
189 |
while p <> nil do |
|
190 |
begin |
|
191 |
for i:= 0 to cMaxHHIndex do |
|
192 |
if p.Hedgehogs[i].Gear <> nil then |
|
193 |
RenderHealth(p.Hedgehogs[i]); |
|
194 |
p:= p.Next |
|
195 |
end |
|
196 |
end; |
|
197 |
||
198 |
procedure LoadGraves; |
|
199 |
var p: PTeam; |
|
200 |
l: integer; |
|
201 |
begin |
|
202 |
p:= TeamsList; |
|
203 |
l:= 512; |
|
204 |
while p <> nil do |
|
205 |
begin |
|
206 |
dec(l, 32); |
|
207 |
if p.GraveName = '' then p.GraveName:= 'Simple'; |
|
74 | 208 |
LoadToSurface(Pathz[ptGraves] + '/' + p.GraveName, StoreSurface, l, 512); |
4 | 209 |
p.GraveRect.x:= l; |
210 |
p.GraveRect.y:= 512; |
|
211 |
p.GraveRect.w:= 32; |
|
212 |
p.GraveRect.h:= 256; |
|
213 |
p:= p.Next |
|
214 |
end |
|
215 |
end; |
|
216 |
||
217 |
procedure GetSkyColor; |
|
107 | 218 |
var p: PByteArray; |
4 | 219 |
begin |
80 | 220 |
if SDL_MustLock(SpritesData[sprSky].Surface) then |
221 |
SDLTry(SDL_LockSurface(SpritesData[sprSky].Surface) >= 0, true); |
|
107 | 222 |
p:= SpritesData[sprSky].Surface.pixels; |
80 | 223 |
case SpritesData[sprSky].Surface.format.BytesPerPixel of |
4 | 224 |
1: cSkyColor:= PByte(p)^; |
225 |
2: cSkyColor:= PWord(p)^; |
|
107 | 226 |
3: cSkyColor:= (p^[0]) or (p^[1] shl 8) or (p^[2] shl 16); |
4 | 227 |
4: cSkyColor:= PLongword(p)^; |
228 |
end; |
|
80 | 229 |
if SDL_MustLock(SpritesData[sprSky].Surface) then |
230 |
SDL_UnlockSurface(SpritesData[sprSky].Surface) |
|
4 | 231 |
end; |
232 |
||
233 |
procedure GetExplosionBorderColor; |
|
234 |
var f: textfile; |
|
235 |
c: integer; |
|
236 |
begin |
|
80 | 237 |
s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename; |
4 | 238 |
WriteToConsole(msgLoading + s + ' '); |
239 |
AssignFile(f, s); |
|
240 |
{$I-} |
|
241 |
Reset(f); |
|
242 |
Readln(f, s); |
|
243 |
Closefile(f); |
|
244 |
{$I+} |
|
245 |
TryDo(IOResult = 0, msgFailed, true); |
|
246 |
WriteLnToConsole(msgOK); |
|
247 |
val(s, cExplosionBorderColor, c); |
|
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
190
diff
changeset
|
248 |
AdjustColor(cExplosionBorderColor); |
4 | 249 |
end; |
250 |
||
251 |
begin |
|
252 |
for fi:= Low(THWFont) to High(THWFont) do |
|
253 |
with Fontz[fi] do |
|
254 |
begin |
|
53 | 255 |
s:= Pathz[ptFonts] + '/' + Name; |
4 | 256 |
WriteToConsole(msgLoading + s + ' '); |
257 |
Handle:= TTF_OpenFont(PChar(s), Height); |
|
258 |
TryDo(Handle <> nil, msgFailed, true); |
|
259 |
WriteLnToConsole(msgOK) |
|
260 |
end; |
|
261 |
AddProgress; |
|
53 | 262 |
|
105 | 263 |
WriteToConsole('LandSurface tuning... '); |
4 | 264 |
tmpsurf:= LandSurface; |
265 |
TryDo(tmpsurf <> nil, msgFailed, true); |
|
266 |
if cFullScreen then |
|
267 |
begin |
|
268 |
LandSurface:= SDL_DisplayFormat(tmpsurf); |
|
269 |
SDL_FreeSurface(tmpsurf); |
|
270 |
end else LandSurface:= tmpsurf; |
|
35 | 271 |
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
4 | 272 |
WriteLnToConsole(msgOK); |
273 |
||
274 |
GetExplosionBorderColor; |
|
275 |
||
276 |
AddProgress; |
|
277 |
for i:= Low(TStuff) to High(TStuff) do |
|
53 | 278 |
LoadToSurface(Pathz[StuffLoadData[i].Path] + '/' + StuffLoadData[i].FileName, StoreSurface, StuffPoz[i].x, StuffPoz[i].y); |
4 | 279 |
|
280 |
AddProgress; |
|
281 |
WriteNames(fnt16); |
|
70 | 282 |
MakeCrossHairs; |
4 | 283 |
LoadGraves; |
284 |
||
285 |
AddProgress; |
|
286 |
for ii:= Low(TSprite) to High(TSprite) do |
|
287 |
with SpritesData[ii] do |
|
80 | 288 |
begin |
289 |
if AltPath = ptNone then |
|
290 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha) |
|
291 |
else begin |
|
292 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false); |
|
293 |
if Surface = nil then |
|
294 |
Surface:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha) |
|
295 |
end; |
|
296 |
if Width = 0 then Width:= Surface.w; |
|
297 |
if Height = 0 then Height:= Surface.h |
|
298 |
end; |
|
299 |
||
300 |
GetSkyColor; |
|
4 | 301 |
|
302 |
AddProgress; |
|
53 | 303 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, false); |
35 | 304 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
4 | 305 |
HHSurface:= SDL_DisplayFormat(tmpsurf); |
306 |
SDL_FreeSurface(tmpsurf); |
|
307 |
||
308 |
InitHealth; |
|
309 |
||
310 |
{$IFDEF DUMP} |
|
311 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
312 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
313 |
{$ENDIF} |
|
314 |
end; |
|
315 |
||
316 |
procedure DrawFromRect(X, Y: integer; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface); |
|
317 |
var rr: TSDL_Rect; |
|
318 |
begin |
|
319 |
rr.x:= X; |
|
320 |
rr.y:= Y; |
|
321 |
rr.w:= r.w; |
|
322 |
rr.h:= r.h; |
|
323 |
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then |
|
324 |
begin |
|
43 | 325 |
OutError('Blit: ' + SDL_GetError, true); |
4 | 326 |
exit |
327 |
end; |
|
328 |
end; |
|
329 |
||
330 |
procedure DrawGear(Stuff: TStuff; X, Y: integer; Surface: PSDL_Surface); |
|
331 |
begin |
|
332 |
DrawFromRect(X, Y, @StuffPoz[Stuff], StoreSurface, Surface) |
|
333 |
end; |
|
334 |
||
335 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface); |
|
336 |
begin |
|
337 |
r.y:= r.y + Height * Position; |
|
338 |
r.h:= Height; |
|
339 |
DrawFromRect(X, Y, @r, StoreSurface, Surface) |
|
340 |
end; |
|
341 |
||
161 | 342 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: integer; Surface: PSDL_Surface); |
4 | 343 |
begin |
198 | 344 |
DrawSurfSprite(X, Y, SpritesData[Sprite].Height, Frame, SpritesData[Sprite].Surface, Surface) |
4 | 345 |
end; |
346 |
||
43 | 347 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface); |
348 |
var r: TSDL_Rect; |
|
349 |
begin |
|
350 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
351 |
r.w:= SpritesData[Sprite].Width; |
|
352 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
353 |
r.h:= SpritesData[Sprite].Height; |
|
354 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
|
355 |
end; |
|
356 |
||
198 | 357 |
procedure DrawSurfSprite(X, Y, Height, Frame: integer; Source, Surface: PSDL_Surface); |
358 |
var r: TSDL_Rect; |
|
359 |
begin |
|
360 |
r.x:= 0; |
|
361 |
r.w:= Source.w; |
|
362 |
r.y:= Frame * Height; |
|
363 |
r.h:= Height; |
|
364 |
DrawFromRect(X, Y, @r, Source, Surface) |
|
365 |
end; |
|
366 |
||
4 | 367 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); |
368 |
var clr: TSDL_Color; |
|
369 |
tmpsurf: PSDL_Surface; |
|
370 |
r: TSDL_Rect; |
|
371 |
begin |
|
372 |
r.x:= X; |
|
373 |
r.y:= Y; |
|
189 | 374 |
clr.r:= $FF; |
375 |
clr.g:= $FF; |
|
376 |
clr.b:= $FF; |
|
74 | 377 |
tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, PChar(s), clr); |
198 | 378 |
TryDo(tmpsurf <> nil, errmsgRenderText, true); |
4 | 379 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
380 |
SDL_FreeSurface(tmpsurf) |
|
381 |
end; |
|
382 |
||
383 |
procedure DrawLand(X, Y: integer; Surface: PSDL_Surface); |
|
384 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024); |
|
385 |
begin |
|
386 |
DrawFromRect(X, Y, @r, LandSurface, Surface) |
|
387 |
end; |
|
388 |
||
47 | 389 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface); |
390 |
begin |
|
391 |
DrawFromRect(X, Y, Rect, StoreSurface, Surface) |
|
392 |
end; |
|
393 |
||
95 | 394 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); |
4 | 395 |
begin |
95 | 396 |
DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface) |
397 |
end; |
|
398 |
||
399 |
procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface); |
|
400 |
var r: TSDL_Rect; |
|
401 |
begin |
|
402 |
r.x:= X - Source.w div 2; |
|
403 |
r.y:= Top; |
|
404 |
r.w:= Source.w; |
|
405 |
r.h:= Source.h; |
|
406 |
SDL_UpperBlit(Source, nil, Surface, @r) |
|
4 | 407 |
end; |
408 |
||
409 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface); |
|
410 |
var r: TSDL_Rect; |
|
411 |
begin |
|
412 |
r.x:= Step * 32; |
|
413 |
r.y:= Pos * 32; |
|
414 |
if Dir = -1 then r.x:= cHHSurfaceWidth - 32 - r.x; |
|
415 |
r.w:= 32; |
|
416 |
r.h:= 32; |
|
417 |
DrawFromRect(X, Y, @r, HHSurface, Surface) |
|
418 |
end; |
|
419 |
||
420 |
procedure StoreRelease; |
|
421 |
var ii: TSprite; |
|
422 |
begin |
|
423 |
for ii:= Low(TSprite) to High(TSprite) do |
|
424 |
SDL_FreeSurface(SpritesData[ii].Surface); |
|
425 |
SDL_FreeSurface( HHSurface ); |
|
426 |
SDL_FreeSurface(LandSurface ); |
|
427 |
SDL_FreeSurface(StoreSurface ) |
|
428 |
end; |
|
429 |
||
108 | 430 |
function RenderString(s: string; Color: integer; font: THWFont): PSDL_Surface; |
95 | 431 |
var w, h: integer; |
432 |
begin |
|
108 | 433 |
TTF_SizeUTF8(Fontz[font].Handle, PChar(s), w, h); |
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
190
diff
changeset
|
434 |
Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + 6, h + 2, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, PixelFormat.AMask); |
107 | 435 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
95 | 436 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
437 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true) |
|
438 |
end; |
|
439 |
||
4 | 440 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 441 |
var s: shortstring; |
4 | 442 |
begin |
443 |
str(Hedgehog.Gear.Health, s); |
|
95 | 444 |
if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
445 |
Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Color, fnt16) |
|
4 | 446 |
end; |
447 |
||
448 |
procedure AddProgress; |
|
449 |
const Step: Longword = 0; |
|
450 |
ProgrSurf: PSDL_Surface = nil; |
|
71 | 451 |
MaxCalls = 11; // MaxCalls should be the count of calls to AddProgress to prevent memory leakage |
4 | 452 |
var r: TSDL_Rect; |
453 |
begin |
|
454 |
if Step = 0 then |
|
455 |
begin |
|
97
e7c1df9cce2c
- make the game be run from ${PREFIX}/bin with data in ${PREFIX}/share/hedgewars/Data
unc0rr
parents:
95
diff
changeset
|
456 |
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
|
457 |
ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/BigDigits', false); |
4 | 458 |
end; |
459 |
SDL_FillRect(SDLPrimSurface, nil, 0); |
|
460 |
r.x:= 0; |
|
461 |
r.w:= 32; |
|
462 |
r.h:= 32; |
|
71 | 463 |
r.y:= (Step mod 10) * 32; |
4 | 464 |
DrawFromRect(cScreenWidth div 2 - 16, cScreenHeight div 2 - 16, @r, ProgrSurf, SDLPrimSurface); |
465 |
SDL_Flip(SDLPrimSurface); |
|
466 |
inc(Step); |
|
467 |
if Step = MaxCalls then |
|
468 |
begin |
|
469 |
WriteLnToConsole('Freeing progress surface... '); |
|
470 |
SDL_FreeSurface(ProgrSurf) |
|
471 |
end; |
|
472 |
end; |
|
473 |
||
198 | 474 |
function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true; const setTransparent: boolean = true): PSDL_Surface; |
30 | 475 |
var tmpsurf: PSDL_Surface; |
4 | 476 |
begin |
477 |
WriteToConsole(msgLoading + filename + '... '); |
|
74 | 478 |
tmpsurf:= IMG_Load(PChar(filename + '.' + cBitsStr + '.png')); |
479 |
if tmpsurf = nil then |
|
480 |
tmpsurf:= IMG_Load(PChar(filename + '.png')); |
|
80 | 481 |
|
482 |
if tmpsurf = nil then |
|
483 |
if critical then OutError(msgFailed, true) |
|
484 |
else begin |
|
485 |
WriteLnToConsole(msgFailed); |
|
486 |
Result:= nil; |
|
487 |
exit |
|
488 |
end; |
|
489 |
||
198 | 490 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
80 | 491 |
if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
492 |
else Result:= SDL_DisplayFormat(tmpsurf); |
|
4 | 493 |
WriteLnToConsole(msgOK) |
494 |
end; |
|
495 |
||
496 |
end. |