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