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