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