author | unc0rr |
Sun, 15 Jul 2007 20:52:03 +0000 | |
changeset 561 | 19d2d422ff84 |
parent 549 | 4278a80140a8 |
child 567 | b6de36975a3c |
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); |
|
547 | 135 |
var t: LongInt; |
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; |
547 | 143 |
for t:= 0 to Pred(TeamsCount) do |
144 |
with TeamsArray[t]^ do |
|
4 | 145 |
begin |
47 | 146 |
r.w:= 104; |
549 | 147 |
NameTag:= RenderString(TeamName, Clan^.Color, Font); |
47 | 148 |
r.w:= cTeamHealthWidth + 5; |
547 | 149 |
r.h:= NameTag^.h; |
351 | 150 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, StoreSurface, true); |
547 | 151 |
HealthRect:= r; |
47 | 152 |
rr:= r; |
153 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
549 | 154 |
DrawRoundRect(@rr, Clan^.AdjColor, Clan^.AdjColor, StoreSurface, false); |
47 | 155 |
inc(r.y, r.h); |
49 | 156 |
dec(drY, r.h + 2); |
547 | 157 |
DrawHealthY:= drY; |
4 | 158 |
for i:= 0 to 7 do |
547 | 159 |
with Hedgehogs[i] do |
95 | 160 |
if Gear <> nil then |
549 | 161 |
NameTag:= RenderString(Name, Clan^.Color, fnt16); |
4 | 162 |
end; |
163 |
end; |
|
164 |
||
165 |
procedure MakeCrossHairs; |
|
547 | 166 |
var t: LongInt; |
4 | 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 |
|
547 | 173 |
for t:= 0 to Pred(TeamsCount) do |
174 |
with TeamsArray[t]^ do |
|
4 | 175 |
begin |
547 | 176 |
CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, tmpsurf^.w, tmpsurf^.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
177 |
TryDo(CrosshairSurf <> nil, errmsgCreateSurface, true); |
|
549 | 178 |
SDL_FillRect(CrosshairSurf, nil, Clan^.AdjColor); |
547 | 179 |
SDL_UpperBlit(tmpsurf, nil, CrosshairSurf, nil); |
180 |
TryDo(SDL_SetColorKey(CrosshairSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
|
4 | 181 |
end; |
351 | 182 |
|
4 | 183 |
SDL_FreeSurface(tmpsurf) |
184 |
end; |
|
185 |
||
186 |
procedure InitHealth; |
|
547 | 187 |
var i, t: LongInt; |
4 | 188 |
begin |
547 | 189 |
for t:= 0 to Pred(TeamsCount) do |
190 |
if TeamsArray[t] <> nil then |
|
191 |
with TeamsArray[t]^ do |
|
4 | 192 |
begin |
193 |
for i:= 0 to cMaxHHIndex do |
|
547 | 194 |
if Hedgehogs[i].Gear <> nil then |
195 |
RenderHealth(Hedgehogs[i]); |
|
4 | 196 |
end |
197 |
end; |
|
198 |
||
199 |
procedure LoadGraves; |
|
547 | 200 |
var t, l: LongInt; |
4 | 201 |
begin |
202 |
l:= 512; |
|
547 | 203 |
for t:= 0 to Pred(TeamsCount) do |
204 |
if TeamsArray[t] <> nil then |
|
205 |
with TeamsArray[t]^ do |
|
4 | 206 |
begin |
207 |
dec(l, 32); |
|
547 | 208 |
if GraveName = '' then GraveName:= 'Simple'; |
209 |
LoadToSurface(Pathz[ptGraves] + '/' + GraveName, StoreSurface, l, 512); |
|
210 |
GraveRect.x:= l; |
|
211 |
GraveRect.y:= 512; |
|
212 |
GraveRect.w:= 32; |
|
213 |
GraveRect.h:= 256; |
|
4 | 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); |
|
351 | 222 |
p:= SpritesData[sprSky].Surface^.pixels; |
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; |
|
371 | 235 |
c: LongInt; |
4 | 236 |
begin |
80 | 237 |
s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename; |
4 | 238 |
WriteToConsole(msgLoading + s + ' '); |
351 | 239 |
Assign(f, s); |
4 | 240 |
{$I-} |
241 |
Reset(f); |
|
242 |
Readln(f, s); |
|
351 | 243 |
Close(f); |
4 | 244 |
{$I+} |
245 |
TryDo(IOResult = 0, msgFailed, true); |
|
246 |
WriteLnToConsole(msgOK); |
|
247 |
val(s, cExplosionBorderColor, c); |
|
495 | 248 |
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
|
249 |
AdjustColor(cExplosionBorderColor); |
4 | 250 |
end; |
251 |
||
252 |
begin |
|
253 |
for fi:= Low(THWFont) to High(THWFont) do |
|
254 |
with Fontz[fi] do |
|
255 |
begin |
|
53 | 256 |
s:= Pathz[ptFonts] + '/' + Name; |
200 | 257 |
WriteToConsole(msgLoading + s + '... '); |
355 | 258 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
200 | 259 |
SDLTry(Handle <> nil, true); |
202 | 260 |
TTF_SetFontStyle(Handle, style); |
4 | 261 |
WriteLnToConsole(msgOK) |
262 |
end; |
|
263 |
AddProgress; |
|
53 | 264 |
|
105 | 265 |
WriteToConsole('LandSurface tuning... '); |
4 | 266 |
tmpsurf:= LandSurface; |
267 |
TryDo(tmpsurf <> nil, msgFailed, true); |
|
268 |
if cFullScreen then |
|
269 |
begin |
|
270 |
LandSurface:= SDL_DisplayFormat(tmpsurf); |
|
271 |
SDL_FreeSurface(tmpsurf); |
|
272 |
end else LandSurface:= tmpsurf; |
|
35 | 273 |
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
4 | 274 |
WriteLnToConsole(msgOK); |
275 |
||
276 |
GetExplosionBorderColor; |
|
277 |
||
278 |
AddProgress; |
|
279 |
for i:= Low(TStuff) to High(TStuff) do |
|
53 | 280 |
LoadToSurface(Pathz[StuffLoadData[i].Path] + '/' + StuffLoadData[i].FileName, StoreSurface, StuffPoz[i].x, StuffPoz[i].y); |
4 | 281 |
|
282 |
AddProgress; |
|
283 |
WriteNames(fnt16); |
|
70 | 284 |
MakeCrossHairs; |
4 | 285 |
LoadGraves; |
286 |
||
287 |
AddProgress; |
|
288 |
for ii:= Low(TSprite) to High(TSprite) do |
|
289 |
with SpritesData[ii] do |
|
80 | 290 |
begin |
291 |
if AltPath = ptNone then |
|
351 | 292 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, true, true) |
80 | 293 |
else begin |
351 | 294 |
Surface:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false, true); |
80 | 295 |
if Surface = nil then |
351 | 296 |
Surface:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha, true, true) |
80 | 297 |
end; |
351 | 298 |
if Width = 0 then Width:= Surface^.w; |
299 |
if Height = 0 then Height:= Surface^.h |
|
80 | 300 |
end; |
301 |
||
302 |
GetSkyColor; |
|
4 | 303 |
|
304 |
AddProgress; |
|
351 | 305 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, false, true, true); |
35 | 306 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
4 | 307 |
HHSurface:= SDL_DisplayFormat(tmpsurf); |
308 |
SDL_FreeSurface(tmpsurf); |
|
309 |
||
310 |
InitHealth; |
|
311 |
||
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
312 |
PauseSurface:= RenderString(trmsg[sidPaused], $FFFF00, fntBig); |
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
313 |
|
4 | 314 |
{$IFDEF DUMP} |
315 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
316 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
317 |
{$ENDIF} |
|
318 |
end; |
|
319 |
||
371 | 320 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface); |
4 | 321 |
var rr: TSDL_Rect; |
322 |
begin |
|
323 |
rr.x:= X; |
|
324 |
rr.y:= Y; |
|
351 | 325 |
rr.w:= r^.w; |
326 |
rr.h:= r^.h; |
|
4 | 327 |
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then |
328 |
begin |
|
43 | 329 |
OutError('Blit: ' + SDL_GetError, true); |
4 | 330 |
exit |
331 |
end; |
|
332 |
end; |
|
333 |
||
371 | 334 |
procedure DrawGear(Stuff: TStuff; X, Y: LongInt; Surface: PSDL_Surface); |
4 | 335 |
begin |
336 |
DrawFromRect(X, Y, @StuffPoz[Stuff], StoreSurface, Surface) |
|
337 |
end; |
|
338 |
||
371 | 339 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface); |
4 | 340 |
begin |
341 |
r.y:= r.y + Height * Position; |
|
342 |
r.h:= Height; |
|
343 |
DrawFromRect(X, Y, @r, StoreSurface, Surface) |
|
344 |
end; |
|
345 |
||
371 | 346 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt; Surface: PSDL_Surface); |
4 | 347 |
begin |
198 | 348 |
DrawSurfSprite(X, Y, SpritesData[Sprite].Height, Frame, SpritesData[Sprite].Surface, Surface) |
4 | 349 |
end; |
350 |
||
371 | 351 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt; Surface: PSDL_Surface); |
43 | 352 |
var r: TSDL_Rect; |
353 |
begin |
|
354 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
355 |
r.w:= SpritesData[Sprite].Width; |
|
356 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
357 |
r.h:= SpritesData[Sprite].Height; |
|
358 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
|
359 |
end; |
|
360 |
||
371 | 361 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source, Surface: PSDL_Surface); |
198 | 362 |
var r: TSDL_Rect; |
363 |
begin |
|
364 |
r.x:= 0; |
|
351 | 365 |
r.w:= Source^.w; |
198 | 366 |
r.y:= Frame * Height; |
367 |
r.h:= Height; |
|
368 |
DrawFromRect(X, Y, @r, Source, Surface) |
|
369 |
end; |
|
370 |
||
371 | 371 |
procedure DXOutText(X, Y: LongInt; Font: THWFont; s: string; Surface: PSDL_Surface); |
4 | 372 |
var clr: TSDL_Color; |
373 |
tmpsurf: PSDL_Surface; |
|
374 |
r: TSDL_Rect; |
|
375 |
begin |
|
376 |
r.x:= X; |
|
377 |
r.y:= Y; |
|
189 | 378 |
clr.r:= $FF; |
379 |
clr.g:= $FF; |
|
380 |
clr.b:= $FF; |
|
355 | 381 |
tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, Str2PChar(s), clr.value); |
208 | 382 |
if tmpsurf = nil then |
383 |
begin |
|
384 |
SetKB(1); |
|
385 |
exit |
|
386 |
end; |
|
4 | 387 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
388 |
SDL_FreeSurface(tmpsurf) |
|
389 |
end; |
|
390 |
||
371 | 391 |
procedure DrawLand(X, Y: LongInt; Surface: PSDL_Surface); |
4 | 392 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024); |
393 |
begin |
|
394 |
DrawFromRect(X, Y, @r, LandSurface, Surface) |
|
395 |
end; |
|
396 |
||
371 | 397 |
procedure DrawFromStoreRect(X, Y: LongInt; Rect: PSDL_Rect; Surface: PSDL_Surface); |
47 | 398 |
begin |
399 |
DrawFromRect(X, Y, Rect, StoreSurface, Surface) |
|
400 |
end; |
|
401 |
||
371 | 402 |
procedure DrawCaption(X, Y: LongInt; Rect: TSDL_Rect; Surface: PSDL_Surface); |
4 | 403 |
begin |
95 | 404 |
DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface) |
405 |
end; |
|
406 |
||
371 | 407 |
procedure DrawCentered(X, Top: LongInt; Source, Surface: PSDL_Surface); |
95 | 408 |
var r: TSDL_Rect; |
409 |
begin |
|
351 | 410 |
r.x:= X - Source^.w div 2; |
95 | 411 |
r.y:= Top; |
351 | 412 |
r.w:= Source^.w; |
413 |
r.h:= Source^.h; |
|
95 | 414 |
SDL_UpperBlit(Source, nil, Surface, @r) |
4 | 415 |
end; |
416 |
||
371 | 417 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface); |
4 | 418 |
var r: TSDL_Rect; |
419 |
begin |
|
420 |
r.x:= Step * 32; |
|
421 |
r.y:= Pos * 32; |
|
351 | 422 |
if Dir = -1 then r.x:= HHSurface^.w - 32 - r.x; |
4 | 423 |
r.w:= 32; |
424 |
r.h:= 32; |
|
425 |
DrawFromRect(X, Y, @r, HHSurface, Surface) |
|
426 |
end; |
|
427 |
||
428 |
procedure StoreRelease; |
|
429 |
var ii: TSprite; |
|
430 |
begin |
|
431 |
for ii:= Low(TSprite) to High(TSprite) do |
|
432 |
SDL_FreeSurface(SpritesData[ii].Surface); |
|
433 |
SDL_FreeSurface( HHSurface ); |
|
434 |
SDL_FreeSurface(LandSurface ); |
|
435 |
SDL_FreeSurface(StoreSurface ) |
|
436 |
end; |
|
437 |
||
351 | 438 |
function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
432 | 439 |
var w, h: LongInt; |
351 | 440 |
Result: PSDL_Surface; |
95 | 441 |
begin |
355 | 442 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
202 | 443 |
Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
351 | 444 |
cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
107 | 445 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
95 | 446 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
351 | 447 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
448 |
RenderString:= Result |
|
95 | 449 |
end; |
450 |
||
4 | 451 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 452 |
var s: shortstring; |
4 | 453 |
begin |
351 | 454 |
str(Hedgehog.Gear^.Health, s); |
95 | 455 |
if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
549 | 456 |
Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Clan^.Color, fnt16) |
4 | 457 |
end; |
458 |
||
518 | 459 |
function LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
30 | 460 |
var tmpsurf: PSDL_Surface; |
351 | 461 |
Result: PSDL_Surface; |
355 | 462 |
s: shortstring; |
4 | 463 |
begin |
464 |
WriteToConsole(msgLoading + filename + '... '); |
|
355 | 465 |
s:= filename + '.' + cBitsStr + '.png'; |
466 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 467 |
|
74 | 468 |
if tmpsurf = nil then |
351 | 469 |
begin |
355 | 470 |
s:= filename + '.png'; |
471 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 472 |
end; |
80 | 473 |
|
474 |
if tmpsurf = nil then |
|
475 |
if critical then OutError(msgFailed, true) |
|
476 |
else begin |
|
477 |
WriteLnToConsole(msgFailed); |
|
351 | 478 |
exit(nil) |
80 | 479 |
end; |
351 | 480 |
|
198 | 481 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
80 | 482 |
if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
483 |
else Result:= SDL_DisplayFormat(tmpsurf); |
|
351 | 484 |
WriteLnToConsole(msgOK); |
485 |
LoadImage:= Result |
|
4 | 486 |
end; |
487 |
||
510 | 488 |
//////////////////////////////////////////////////////////////////////////////// |
489 |
var ProgrSurf: PSDL_Surface = nil; |
|
534 | 490 |
Step: integer = 0; |
510 | 491 |
|
492 |
procedure AddProgress; |
|
493 |
var r: TSDL_Rect; |
|
494 |
begin |
|
495 |
if Step = 0 then |
|
496 |
begin |
|
497 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
498 |
ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
|
499 |
end; |
|
500 |
SDL_FillRect(SDLPrimSurface, nil, 0); |
|
501 |
r.x:= 0; |
|
502 |
r.w:= ProgrSurf^.w; |
|
503 |
r.h:= ProgrSurf^.w; |
|
504 |
r.y:= (Step mod (ProgrSurf^.h div ProgrSurf^.w)) * ProgrSurf^.w; |
|
505 |
DrawFromRect((cScreenWidth - ProgrSurf^.w) div 2, |
|
506 |
(cScreenHeight - ProgrSurf^.w) div 2, @r, ProgrSurf, SDLPrimSurface); |
|
507 |
SDL_Flip(SDLPrimSurface); |
|
508 |
inc(Step); |
|
509 |
end; |
|
510 |
||
511 |
procedure FinishProgress; |
|
512 |
begin |
|
513 |
WriteLnToConsole('Freeing progress surface... '); |
|
514 |
SDL_FreeSurface(ProgrSurf) |
|
515 |
end; |
|
516 |
||
4 | 517 |
end. |