author | displacer |
Thu, 16 Aug 2007 14:10:06 +0000 | |
changeset 571 | a6cea9fbbc59 |
parent 567 | b6de36975a3c |
child 620 | 451cabd49241 |
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; |
|
567 | 305 |
|
306 |
HHSurface:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, true, true, true); |
|
4 | 307 |
|
308 |
InitHealth; |
|
309 |
||
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
310 |
PauseSurface:= RenderString(trmsg[sidPaused], $FFFF00, fntBig); |
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
311 |
|
4 | 312 |
{$IFDEF DUMP} |
313 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
314 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
315 |
{$ENDIF} |
|
316 |
end; |
|
317 |
||
371 | 318 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface); |
4 | 319 |
var rr: TSDL_Rect; |
320 |
begin |
|
321 |
rr.x:= X; |
|
322 |
rr.y:= Y; |
|
351 | 323 |
rr.w:= r^.w; |
324 |
rr.h:= r^.h; |
|
4 | 325 |
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then |
326 |
begin |
|
43 | 327 |
OutError('Blit: ' + SDL_GetError, true); |
4 | 328 |
exit |
329 |
end; |
|
330 |
end; |
|
331 |
||
371 | 332 |
procedure DrawGear(Stuff: TStuff; X, Y: LongInt; Surface: PSDL_Surface); |
4 | 333 |
begin |
334 |
DrawFromRect(X, Y, @StuffPoz[Stuff], StoreSurface, Surface) |
|
335 |
end; |
|
336 |
||
371 | 337 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface); |
4 | 338 |
begin |
339 |
r.y:= r.y + Height * Position; |
|
340 |
r.h:= Height; |
|
341 |
DrawFromRect(X, Y, @r, StoreSurface, Surface) |
|
342 |
end; |
|
343 |
||
371 | 344 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt; Surface: PSDL_Surface); |
4 | 345 |
begin |
198 | 346 |
DrawSurfSprite(X, Y, SpritesData[Sprite].Height, Frame, SpritesData[Sprite].Surface, Surface) |
4 | 347 |
end; |
348 |
||
371 | 349 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt; Surface: PSDL_Surface); |
43 | 350 |
var r: TSDL_Rect; |
351 |
begin |
|
352 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
353 |
r.w:= SpritesData[Sprite].Width; |
|
354 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
355 |
r.h:= SpritesData[Sprite].Height; |
|
356 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface) |
|
357 |
end; |
|
358 |
||
371 | 359 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source, Surface: PSDL_Surface); |
198 | 360 |
var r: TSDL_Rect; |
361 |
begin |
|
362 |
r.x:= 0; |
|
351 | 363 |
r.w:= Source^.w; |
198 | 364 |
r.y:= Frame * Height; |
365 |
r.h:= Height; |
|
366 |
DrawFromRect(X, Y, @r, Source, Surface) |
|
367 |
end; |
|
368 |
||
371 | 369 |
procedure DXOutText(X, Y: LongInt; Font: THWFont; s: string; Surface: PSDL_Surface); |
4 | 370 |
var clr: TSDL_Color; |
371 |
tmpsurf: PSDL_Surface; |
|
372 |
r: TSDL_Rect; |
|
373 |
begin |
|
374 |
r.x:= X; |
|
375 |
r.y:= Y; |
|
189 | 376 |
clr.r:= $FF; |
377 |
clr.g:= $FF; |
|
378 |
clr.b:= $FF; |
|
355 | 379 |
tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, Str2PChar(s), clr.value); |
208 | 380 |
if tmpsurf = nil then |
381 |
begin |
|
382 |
SetKB(1); |
|
383 |
exit |
|
384 |
end; |
|
4 | 385 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
386 |
SDL_FreeSurface(tmpsurf) |
|
387 |
end; |
|
388 |
||
371 | 389 |
procedure DrawLand(X, Y: LongInt; Surface: PSDL_Surface); |
4 | 390 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024); |
391 |
begin |
|
392 |
DrawFromRect(X, Y, @r, LandSurface, Surface) |
|
393 |
end; |
|
394 |
||
371 | 395 |
procedure DrawFromStoreRect(X, Y: LongInt; Rect: PSDL_Rect; Surface: PSDL_Surface); |
47 | 396 |
begin |
397 |
DrawFromRect(X, Y, Rect, StoreSurface, Surface) |
|
398 |
end; |
|
399 |
||
371 | 400 |
procedure DrawCaption(X, Y: LongInt; Rect: TSDL_Rect; Surface: PSDL_Surface); |
4 | 401 |
begin |
95 | 402 |
DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface) |
403 |
end; |
|
404 |
||
371 | 405 |
procedure DrawCentered(X, Top: LongInt; Source, Surface: PSDL_Surface); |
95 | 406 |
var r: TSDL_Rect; |
407 |
begin |
|
351 | 408 |
r.x:= X - Source^.w div 2; |
95 | 409 |
r.y:= Top; |
351 | 410 |
r.w:= Source^.w; |
411 |
r.h:= Source^.h; |
|
95 | 412 |
SDL_UpperBlit(Source, nil, Surface, @r) |
4 | 413 |
end; |
414 |
||
371 | 415 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface); |
4 | 416 |
var r: TSDL_Rect; |
417 |
begin |
|
418 |
r.x:= Step * 32; |
|
419 |
r.y:= Pos * 32; |
|
351 | 420 |
if Dir = -1 then r.x:= HHSurface^.w - 32 - r.x; |
4 | 421 |
r.w:= 32; |
422 |
r.h:= 32; |
|
423 |
DrawFromRect(X, Y, @r, HHSurface, Surface) |
|
424 |
end; |
|
425 |
||
426 |
procedure StoreRelease; |
|
427 |
var ii: TSprite; |
|
428 |
begin |
|
429 |
for ii:= Low(TSprite) to High(TSprite) do |
|
430 |
SDL_FreeSurface(SpritesData[ii].Surface); |
|
431 |
SDL_FreeSurface( HHSurface ); |
|
432 |
SDL_FreeSurface(LandSurface ); |
|
433 |
SDL_FreeSurface(StoreSurface ) |
|
434 |
end; |
|
435 |
||
351 | 436 |
function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
432 | 437 |
var w, h: LongInt; |
351 | 438 |
Result: PSDL_Surface; |
95 | 439 |
begin |
355 | 440 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
202 | 441 |
Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
351 | 442 |
cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
107 | 443 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
95 | 444 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
351 | 445 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
446 |
RenderString:= Result |
|
95 | 447 |
end; |
448 |
||
4 | 449 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 450 |
var s: shortstring; |
4 | 451 |
begin |
351 | 452 |
str(Hedgehog.Gear^.Health, s); |
95 | 453 |
if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
549 | 454 |
Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Clan^.Color, fnt16) |
4 | 455 |
end; |
456 |
||
518 | 457 |
function LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
30 | 458 |
var tmpsurf: PSDL_Surface; |
351 | 459 |
Result: PSDL_Surface; |
355 | 460 |
s: shortstring; |
4 | 461 |
begin |
462 |
WriteToConsole(msgLoading + filename + '... '); |
|
355 | 463 |
s:= filename + '.' + cBitsStr + '.png'; |
464 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 465 |
|
74 | 466 |
if tmpsurf = nil then |
351 | 467 |
begin |
355 | 468 |
s:= filename + '.png'; |
469 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 470 |
end; |
80 | 471 |
|
472 |
if tmpsurf = nil then |
|
473 |
if critical then OutError(msgFailed, true) |
|
474 |
else begin |
|
475 |
WriteLnToConsole(msgFailed); |
|
351 | 476 |
exit(nil) |
80 | 477 |
end; |
351 | 478 |
|
198 | 479 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
80 | 480 |
if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
481 |
else Result:= SDL_DisplayFormat(tmpsurf); |
|
351 | 482 |
WriteLnToConsole(msgOK); |
483 |
LoadImage:= Result |
|
4 | 484 |
end; |
485 |
||
510 | 486 |
//////////////////////////////////////////////////////////////////////////////// |
487 |
var ProgrSurf: PSDL_Surface = nil; |
|
534 | 488 |
Step: integer = 0; |
510 | 489 |
|
490 |
procedure AddProgress; |
|
491 |
var r: TSDL_Rect; |
|
492 |
begin |
|
493 |
if Step = 0 then |
|
494 |
begin |
|
495 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
496 |
ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
|
497 |
end; |
|
498 |
SDL_FillRect(SDLPrimSurface, nil, 0); |
|
499 |
r.x:= 0; |
|
500 |
r.w:= ProgrSurf^.w; |
|
501 |
r.h:= ProgrSurf^.w; |
|
502 |
r.y:= (Step mod (ProgrSurf^.h div ProgrSurf^.w)) * ProgrSurf^.w; |
|
503 |
DrawFromRect((cScreenWidth - ProgrSurf^.w) div 2, |
|
504 |
(cScreenHeight - ProgrSurf^.w) div 2, @r, ProgrSurf, SDLPrimSurface); |
|
505 |
SDL_Flip(SDLPrimSurface); |
|
506 |
inc(Step); |
|
507 |
end; |
|
508 |
||
509 |
procedure FinishProgress; |
|
510 |
begin |
|
511 |
WriteLnToConsole('Freeing progress surface... '); |
|
512 |
SDL_FreeSurface(ProgrSurf) |
|
513 |
end; |
|
514 |
||
4 | 515 |
end. |