author | unc0rr |
Fri, 25 Jan 2008 23:55:03 +0000 | |
changeset 756 | 2b307457fd68 |
parent 755 | edf26e9554ac |
child 759 | 8da05b316d81 |
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 |
|
755 | 21 |
uses uConsts, uTeams, SDLh, uFloat, GL; |
4 | 22 |
{$INCLUDE options.inc} |
23 |
||
24 |
procedure StoreInit; |
|
25 |
procedure StoreLoad; |
|
26 |
procedure StoreRelease; |
|
689 | 27 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface); |
371 | 28 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt; Surface: PSDL_Surface); |
29 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt; Surface: PSDL_Surface); |
|
755 | 30 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: GLuint; Surface: PSDL_Surface); |
371 | 31 |
procedure DrawLand (X, Y: LongInt; Surface: PSDL_Surface); |
32 |
procedure DXOutText(X, Y: LongInt; Font: THWFont; s: string; Surface: PSDL_Surface); |
|
33 |
procedure DrawCentered(X, Top: LongInt; Source, Surface: PSDL_Surface); |
|
755 | 34 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture; DestSurface: PSDL_Surface); |
371 | 35 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface); |
351 | 36 |
function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
4 | 37 |
procedure RenderHealth(var Hedgehog: THedgehog); |
38 |
procedure AddProgress; |
|
510 | 39 |
procedure FinishProgress; |
518 | 40 |
function LoadImage(const filename: string; hasAlpha, critical, setTransparent: boolean): PSDL_Surface; |
753 | 41 |
procedure SetupOpenGL; |
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 |
|
755 | 48 |
uses uMisc, uConsole, uLand, uLocale, GLU; |
4 | 49 |
|
690 | 50 |
var |
51 |
HHSurface: PSDL_Surface; |
|
4 | 52 |
|
53 |
procedure StoreInit; |
|
54 |
begin |
|
55 |
||
56 |
end; |
|
57 |
||
351 | 58 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 59 |
var r: TSDL_Rect; |
60 |
begin |
|
61 |
r:= rect^; |
|
83 | 62 |
if Clear then SDL_FillRect(Surface, @r, 0); |
351 | 63 |
r.y:= rect^.y + 1; |
64 |
r.h:= rect^.h - 2; |
|
47 | 65 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 66 |
r.x:= rect^.x + 1; |
67 |
r.w:= rect^.w - 2; |
|
68 |
r.y:= rect^.y; |
|
69 |
r.h:= rect^.h; |
|
47 | 70 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 71 |
r.x:= rect^.x + 2; |
72 |
r.y:= rect^.y + 1; |
|
73 |
r.w:= rect^.w - 4; |
|
74 |
r.h:= rect^.h - 2; |
|
47 | 75 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 76 |
r.x:= rect^.x + 1; |
77 |
r.y:= rect^.y + 2; |
|
78 |
r.w:= rect^.w - 2; |
|
79 |
r.h:= rect^.h - 4; |
|
47 | 80 |
SDL_FillRect(Surface, @r, FillColor) |
81 |
end; |
|
82 |
||
371 | 83 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
351 | 84 |
var w, h: LongInt; |
4 | 85 |
tmpsurf: PSDL_Surface; |
86 |
clr: TSDL_Color; |
|
351 | 87 |
Result: TSDL_Rect; |
4 | 88 |
begin |
355 | 89 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
4 | 90 |
Result.x:= X; |
91 |
Result.y:= Y; |
|
202 | 92 |
Result.w:= w + FontBorder * 2 + 4; |
93 |
Result.h:= h + FontBorder * 2; |
|
351 | 94 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface, true); |
189 | 95 |
clr.r:= Color shr 16; |
96 |
clr.g:= (Color shr 8) and $FF; |
|
97 |
clr.b:= Color and $FF; |
|
355 | 98 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr.value); |
202 | 99 |
Result.x:= X + FontBorder + 2; |
100 |
Result.y:= Y + FontBorder; |
|
199 | 101 |
SDLTry(tmpsurf <> nil, true); |
4 | 102 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result); |
103 |
SDL_FreeSurface(tmpsurf); |
|
104 |
Result.x:= X; |
|
105 |
Result.y:= Y; |
|
202 | 106 |
Result.w:= w + FontBorder * 2 + 4; |
351 | 107 |
Result.h:= h + FontBorder * 2; |
108 |
WriteInRoundRect:= Result |
|
4 | 109 |
end; |
110 |
||
111 |
procedure StoreLoad; |
|
689 | 112 |
var ii: TSprite; |
4 | 113 |
fi: THWFont; |
114 |
s: string; |
|
115 |
tmpsurf: PSDL_Surface; |
|
116 |
||
117 |
procedure WriteNames(Font: THWFont); |
|
547 | 118 |
var t: LongInt; |
371 | 119 |
i: LongInt; |
47 | 120 |
r, rr: TSDL_Rect; |
371 | 121 |
drY: LongInt; |
4 | 122 |
begin |
123 |
r.x:= 0; |
|
690 | 124 |
r.y:= 0; |
70 | 125 |
drY:= cScreenHeight - 4; |
547 | 126 |
for t:= 0 to Pred(TeamsCount) do |
127 |
with TeamsArray[t]^ do |
|
4 | 128 |
begin |
549 | 129 |
NameTag:= RenderString(TeamName, Clan^.Color, Font); |
690 | 130 |
|
47 | 131 |
r.w:= cTeamHealthWidth + 5; |
547 | 132 |
r.h:= NameTag^.h; |
690 | 133 |
|
134 |
HealthSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, r.w, r.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
|
135 |
TryDo(HealthSurf <> nil, errmsgCreateSurface, true); |
|
704 | 136 |
TryDo(SDL_SetColorKey(HealthSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
690 | 137 |
|
138 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, HealthSurf, true); |
|
47 | 139 |
rr:= r; |
140 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
690 | 141 |
DrawRoundRect(@rr, Clan^.AdjColor, Clan^.AdjColor, HealthSurf, false); |
142 |
||
49 | 143 |
dec(drY, r.h + 2); |
547 | 144 |
DrawHealthY:= drY; |
4 | 145 |
for i:= 0 to 7 do |
547 | 146 |
with Hedgehogs[i] do |
95 | 147 |
if Gear <> nil then |
549 | 148 |
NameTag:= RenderString(Name, Clan^.Color, fnt16); |
4 | 149 |
end; |
150 |
end; |
|
151 |
||
152 |
procedure MakeCrossHairs; |
|
547 | 153 |
var t: LongInt; |
4 | 154 |
tmpsurf: PSDL_Surface; |
155 |
s: string; |
|
156 |
begin |
|
53 | 157 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
351 | 158 |
tmpsurf:= LoadImage(s, true, true, false); |
4 | 159 |
|
547 | 160 |
for t:= 0 to Pred(TeamsCount) do |
161 |
with TeamsArray[t]^ do |
|
4 | 162 |
begin |
547 | 163 |
CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, tmpsurf^.w, tmpsurf^.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
164 |
TryDo(CrosshairSurf <> nil, errmsgCreateSurface, true); |
|
549 | 165 |
SDL_FillRect(CrosshairSurf, nil, Clan^.AdjColor); |
547 | 166 |
SDL_UpperBlit(tmpsurf, nil, CrosshairSurf, nil); |
167 |
TryDo(SDL_SetColorKey(CrosshairSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
|
4 | 168 |
end; |
351 | 169 |
|
4 | 170 |
SDL_FreeSurface(tmpsurf) |
171 |
end; |
|
172 |
||
173 |
procedure InitHealth; |
|
547 | 174 |
var i, t: LongInt; |
4 | 175 |
begin |
547 | 176 |
for t:= 0 to Pred(TeamsCount) do |
177 |
if TeamsArray[t] <> nil then |
|
178 |
with TeamsArray[t]^ do |
|
4 | 179 |
begin |
180 |
for i:= 0 to cMaxHHIndex do |
|
547 | 181 |
if Hedgehogs[i].Gear <> nil then |
182 |
RenderHealth(Hedgehogs[i]); |
|
4 | 183 |
end |
184 |
end; |
|
185 |
||
186 |
procedure LoadGraves; |
|
689 | 187 |
var 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 |
547 | 193 |
if GraveName = '' then GraveName:= 'Simple'; |
689 | 194 |
GraveSurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, false, true, true); |
4 | 195 |
end |
196 |
end; |
|
197 |
||
198 |
procedure GetSkyColor; |
|
755 | 199 |
// var p: PByteArray; |
4 | 200 |
begin |
755 | 201 |
(* if SDL_MustLock(SpritesData[sprSky].Surface) then |
80 | 202 |
SDLTry(SDL_LockSurface(SpritesData[sprSky].Surface) >= 0, true); |
351 | 203 |
p:= SpritesData[sprSky].Surface^.pixels; |
204 |
case SpritesData[sprSky].Surface^.format^.BytesPerPixel of |
|
4 | 205 |
1: cSkyColor:= PByte(p)^; |
206 |
2: cSkyColor:= PWord(p)^; |
|
107 | 207 |
3: cSkyColor:= (p^[0]) or (p^[1] shl 8) or (p^[2] shl 16); |
4 | 208 |
4: cSkyColor:= PLongword(p)^; |
755 | 209 |
end;*) |
210 |
cSkyColor:= $3030A0; |
|
753 | 211 |
glClearColor((cSkyColor shr 16) / 255, ((cSkyColor shr 8) and $FF) / 255, (cSkyColor and $FF) / 255, 0); |
212 |
||
755 | 213 |
// if SDL_MustLock(SpritesData[sprSky].Surface) then |
214 |
// SDL_UnlockSurface(SpritesData[sprSky].Surface) |
|
4 | 215 |
end; |
216 |
||
217 |
procedure GetExplosionBorderColor; |
|
218 |
var f: textfile; |
|
371 | 219 |
c: LongInt; |
4 | 220 |
begin |
80 | 221 |
s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename; |
4 | 222 |
WriteToConsole(msgLoading + s + ' '); |
351 | 223 |
Assign(f, s); |
4 | 224 |
{$I-} |
225 |
Reset(f); |
|
226 |
Readln(f, s); |
|
351 | 227 |
Close(f); |
4 | 228 |
{$I+} |
229 |
TryDo(IOResult = 0, msgFailed, true); |
|
230 |
WriteLnToConsole(msgOK); |
|
231 |
val(s, cExplosionBorderColor, c); |
|
495 | 232 |
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
|
233 |
AdjustColor(cExplosionBorderColor); |
4 | 234 |
end; |
235 |
||
236 |
begin |
|
237 |
for fi:= Low(THWFont) to High(THWFont) do |
|
238 |
with Fontz[fi] do |
|
239 |
begin |
|
53 | 240 |
s:= Pathz[ptFonts] + '/' + Name; |
200 | 241 |
WriteToConsole(msgLoading + s + '... '); |
355 | 242 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
200 | 243 |
SDLTry(Handle <> nil, true); |
202 | 244 |
TTF_SetFontStyle(Handle, style); |
4 | 245 |
WriteLnToConsole(msgOK) |
246 |
end; |
|
247 |
AddProgress; |
|
53 | 248 |
|
105 | 249 |
WriteToConsole('LandSurface tuning... '); |
4 | 250 |
tmpsurf:= LandSurface; |
251 |
TryDo(tmpsurf <> nil, msgFailed, true); |
|
252 |
if cFullScreen then |
|
253 |
begin |
|
254 |
LandSurface:= SDL_DisplayFormat(tmpsurf); |
|
255 |
SDL_FreeSurface(tmpsurf); |
|
256 |
end else LandSurface:= tmpsurf; |
|
35 | 257 |
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
4 | 258 |
WriteLnToConsole(msgOK); |
259 |
||
260 |
GetExplosionBorderColor; |
|
261 |
||
262 |
AddProgress; |
|
263 |
WriteNames(fnt16); |
|
70 | 264 |
MakeCrossHairs; |
4 | 265 |
LoadGraves; |
266 |
||
267 |
AddProgress; |
|
268 |
for ii:= Low(TSprite) to High(TSprite) do |
|
269 |
with SpritesData[ii] do |
|
80 | 270 |
begin |
271 |
if AltPath = ptNone then |
|
755 | 272 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, true, true) |
80 | 273 |
else begin |
755 | 274 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, hasAlpha, false, true); |
275 |
if tmpsurf = nil then |
|
276 |
tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, hasAlpha, true, true) |
|
80 | 277 |
end; |
755 | 278 |
if Width = 0 then Width:= tmpsurf^.w; |
279 |
if Height = 0 then Height:= tmpsurf^.h; |
|
280 |
Texture:= Surface2Tex(tmpsurf) |
|
80 | 281 |
end; |
282 |
||
283 |
GetSkyColor; |
|
4 | 284 |
|
285 |
AddProgress; |
|
567 | 286 |
|
287 |
HHSurface:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, true, true, true); |
|
4 | 288 |
|
289 |
InitHealth; |
|
290 |
||
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
291 |
PauseSurface:= RenderString(trmsg[sidPaused], $FFFF00, fntBig); |
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
292 |
|
4 | 293 |
{$IFDEF DUMP} |
294 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
295 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
296 |
{$ENDIF} |
|
297 |
end; |
|
298 |
||
755 | 299 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture; DestSurface: PSDL_Surface); |
4 | 300 |
var rr: TSDL_Rect; |
755 | 301 |
t, b: real; |
4 | 302 |
begin |
303 |
rr.x:= X; |
|
304 |
rr.y:= Y; |
|
351 | 305 |
rr.w:= r^.w; |
306 |
rr.h:= r^.h; |
|
755 | 307 |
|
308 |
t:= r^.y / SourceTexture^.h; |
|
309 |
b:= (r^.y + r^.h) / SourceTexture^.h; |
|
310 |
||
311 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
312 |
glEnable(GL_TEXTURE_2D); |
|
313 |
||
314 |
glBegin(GL_QUADS); |
|
315 |
||
316 |
glTexCoord2f(0, t); |
|
317 |
glVertex2i(X, Y); |
|
318 |
||
319 |
glTexCoord2f(1, t); |
|
320 |
glVertex2i(rr.w + X, Y); |
|
321 |
||
322 |
glTexCoord2f(1, b); |
|
323 |
glVertex2i(rr.w + X, rr.h + Y); |
|
324 |
||
325 |
glTexCoord2f(0, b); |
|
326 |
glVertex2i(X, rr.h + Y); |
|
327 |
||
328 |
glEnd(); |
|
4 | 329 |
end; |
330 |
||
689 | 331 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface); |
4 | 332 |
begin |
333 |
r.y:= r.y + Height * Position; |
|
334 |
r.h:= Height; |
|
755 | 335 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture, Surface) |
4 | 336 |
end; |
337 |
||
371 | 338 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt; Surface: PSDL_Surface); |
755 | 339 |
var r: TSDL_Rect; |
4 | 340 |
begin |
755 | 341 |
r.x:= 0; |
342 |
r.w:= SpritesData[Sprite].Width; |
|
343 |
r.y:= Frame * SpritesData[Sprite].Height; |
|
344 |
r.h:= SpritesData[Sprite].Height; |
|
345 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture, Surface) |
|
4 | 346 |
end; |
347 |
||
371 | 348 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt; Surface: PSDL_Surface); |
43 | 349 |
var r: TSDL_Rect; |
350 |
begin |
|
351 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
352 |
r.w:= SpritesData[Sprite].Width; |
|
353 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
354 |
r.h:= SpritesData[Sprite].Height; |
|
755 | 355 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture, Surface) |
43 | 356 |
end; |
357 |
||
755 | 358 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: GLuint; Surface: PSDL_Surface); |
359 |
//var r: TSDL_Rect; |
|
198 | 360 |
begin |
755 | 361 |
//r.x:= 0; |
362 |
//r.w:= Source^.w; |
|
363 |
//r.y:= Frame * Height; |
|
364 |
//r.h:= Height; |
|
365 |
//DrawFromRect(X, Y, @r, Source, Surface) |
|
198 | 366 |
end; |
367 |
||
371 | 368 |
procedure DXOutText(X, Y: LongInt; Font: THWFont; s: string; Surface: PSDL_Surface); |
4 | 369 |
var clr: TSDL_Color; |
370 |
tmpsurf: PSDL_Surface; |
|
371 |
r: TSDL_Rect; |
|
372 |
begin |
|
373 |
r.x:= X; |
|
374 |
r.y:= Y; |
|
189 | 375 |
clr.r:= $FF; |
376 |
clr.g:= $FF; |
|
377 |
clr.b:= $FF; |
|
355 | 378 |
tmpsurf:= TTF_RenderUTF8_Solid(Fontz[Font].Handle, Str2PChar(s), clr.value); |
208 | 379 |
if tmpsurf = nil then |
380 |
begin |
|
381 |
SetKB(1); |
|
382 |
exit |
|
383 |
end; |
|
4 | 384 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r); |
385 |
SDL_FreeSurface(tmpsurf) |
|
386 |
end; |
|
387 |
||
371 | 388 |
procedure DrawLand(X, Y: LongInt; Surface: PSDL_Surface); |
755 | 389 |
//const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024); |
4 | 390 |
begin |
755 | 391 |
glBindTexture(GL_TEXTURE_2D, LandTexture^.id); |
753 | 392 |
glEnable(GL_TEXTURE_2D); |
393 |
||
755 | 394 |
glBegin(GL_QUADS); |
753 | 395 |
|
755 | 396 |
glTexCoord2i(0, 0); |
397 |
glVertex2i(X, Y); |
|
753 | 398 |
|
755 | 399 |
glTexCoord2i(1, 0); |
400 |
glVertex2i(2048 + X, Y); |
|
753 | 401 |
|
755 | 402 |
glTexCoord2i(1, 1); |
403 |
glVertex2i(2048 + X, 1024 + Y); |
|
753 | 404 |
|
755 | 405 |
glTexCoord2i(0, 1); |
406 |
glVertex2i(X, 1024 + Y); |
|
753 | 407 |
|
755 | 408 |
glEnd(); |
753 | 409 |
//DrawFromRect(X, Y, @r, LandSurface, Surface) |
4 | 410 |
end; |
411 |
||
371 | 412 |
procedure DrawCentered(X, Top: LongInt; Source, Surface: PSDL_Surface); |
95 | 413 |
var r: TSDL_Rect; |
414 |
begin |
|
351 | 415 |
r.x:= X - Source^.w div 2; |
95 | 416 |
r.y:= Top; |
351 | 417 |
r.w:= Source^.w; |
418 |
r.h:= Source^.h; |
|
95 | 419 |
SDL_UpperBlit(Source, nil, Surface, @r) |
4 | 420 |
end; |
421 |
||
371 | 422 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface); |
4 | 423 |
var r: TSDL_Rect; |
424 |
begin |
|
425 |
r.x:= Step * 32; |
|
426 |
r.y:= Pos * 32; |
|
351 | 427 |
if Dir = -1 then r.x:= HHSurface^.w - 32 - r.x; |
4 | 428 |
r.w:= 32; |
429 |
r.h:= 32; |
|
755 | 430 |
//DrawFromRect(X, Y, @r, HHSurface, Surface) |
4 | 431 |
end; |
432 |
||
433 |
procedure StoreRelease; |
|
434 |
var ii: TSprite; |
|
435 |
begin |
|
436 |
for ii:= Low(TSprite) to High(TSprite) do |
|
755 | 437 |
glDeleteTextures(1, @SpritesData[ii].Texture); |
4 | 438 |
SDL_FreeSurface( HHSurface ); |
690 | 439 |
SDL_FreeSurface(LandSurface ) |
4 | 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); |
549 | 460 |
Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Clan^.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; |
753 | 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); |
753 | 486 |
//if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
487 |
// else Result:= SDL_DisplayFormat(tmpsurf); |
|
620 | 488 |
{$IFDEF DEBUGFILE}WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');{$ENDIF} |
351 | 489 |
WriteLnToConsole(msgOK); |
753 | 490 |
LoadImage:= tmpsurf//Result |
491 |
end; |
|
492 |
||
493 |
procedure SetupOpenGL; |
|
494 |
var aspect: real; |
|
495 |
begin |
|
496 |
aspect:= cScreenWidth / cScreenHeight; |
|
497 |
||
756 | 498 |
glLoadIdentity; |
753 | 499 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
754 | 500 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
501 |
glTranslatef(-cScreenWidth / 2, -cScreenHeight / 2, 0); |
|
756 | 502 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
753 | 503 |
glMatrixMode(GL_MODELVIEW) |
4 | 504 |
end; |
505 |
||
510 | 506 |
//////////////////////////////////////////////////////////////////////////////// |
507 |
var ProgrSurf: PSDL_Surface = nil; |
|
534 | 508 |
Step: integer = 0; |
510 | 509 |
|
510 |
procedure AddProgress; |
|
511 |
var r: TSDL_Rect; |
|
512 |
begin |
|
513 |
if Step = 0 then |
|
514 |
begin |
|
515 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
516 |
ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
|
517 |
end; |
|
518 |
SDL_FillRect(SDLPrimSurface, nil, 0); |
|
519 |
r.x:= 0; |
|
520 |
r.w:= ProgrSurf^.w; |
|
521 |
r.h:= ProgrSurf^.w; |
|
522 |
r.y:= (Step mod (ProgrSurf^.h div ProgrSurf^.w)) * ProgrSurf^.w; |
|
755 | 523 |
//DrawFromRect((cScreenWidth - ProgrSurf^.w) div 2, |
524 |
// (cScreenHeight - ProgrSurf^.w) div 2, @r, ProgrSurf, SDLPrimSurface); |
|
510 | 525 |
SDL_Flip(SDLPrimSurface); |
526 |
inc(Step); |
|
527 |
end; |
|
528 |
||
529 |
procedure FinishProgress; |
|
530 |
begin |
|
531 |
WriteLnToConsole('Freeing progress surface... '); |
|
532 |
SDL_FreeSurface(ProgrSurf) |
|
533 |
end; |
|
534 |
||
4 | 535 |
end. |