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