author | unc0rr |
Sat, 26 Jan 2008 10:55:34 +0000 | |
changeset 759 | 8da05b316d81 |
parent 756 | 2b307457fd68 |
child 761 | 63ae90011a52 |
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 |
759 | 303 |
if SourceTexture^.h = 0 then exit; |
4 | 304 |
rr.x:= X; |
305 |
rr.y:= Y; |
|
351 | 306 |
rr.w:= r^.w; |
307 |
rr.h:= r^.h; |
|
755 | 308 |
|
309 |
t:= r^.y / SourceTexture^.h; |
|
310 |
b:= (r^.y + r^.h) / SourceTexture^.h; |
|
311 |
||
312 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
313 |
glEnable(GL_TEXTURE_2D); |
|
314 |
||
315 |
glBegin(GL_QUADS); |
|
316 |
||
317 |
glTexCoord2f(0, t); |
|
318 |
glVertex2i(X, Y); |
|
319 |
||
320 |
glTexCoord2f(1, t); |
|
321 |
glVertex2i(rr.w + X, Y); |
|
322 |
||
323 |
glTexCoord2f(1, b); |
|
324 |
glVertex2i(rr.w + X, rr.h + Y); |
|
325 |
||
326 |
glTexCoord2f(0, b); |
|
327 |
glVertex2i(X, rr.h + Y); |
|
328 |
||
329 |
glEnd(); |
|
4 | 330 |
end; |
331 |
||
689 | 332 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt; Surface: PSDL_Surface); |
4 | 333 |
begin |
334 |
r.y:= r.y + Height * Position; |
|
335 |
r.h:= Height; |
|
755 | 336 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture, Surface) |
4 | 337 |
end; |
338 |
||
371 | 339 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt; Surface: PSDL_Surface); |
755 | 340 |
var r: TSDL_Rect; |
4 | 341 |
begin |
755 | 342 |
r.x:= 0; |
343 |
r.w:= SpritesData[Sprite].Width; |
|
344 |
r.y:= Frame * SpritesData[Sprite].Height; |
|
345 |
r.h:= SpritesData[Sprite].Height; |
|
346 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture, 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; |
|
755 | 356 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture, Surface) |
43 | 357 |
end; |
358 |
||
755 | 359 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: GLuint; Surface: PSDL_Surface); |
360 |
//var r: TSDL_Rect; |
|
198 | 361 |
begin |
755 | 362 |
//r.x:= 0; |
363 |
//r.w:= Source^.w; |
|
364 |
//r.y:= Frame * Height; |
|
365 |
//r.h:= Height; |
|
366 |
//DrawFromRect(X, Y, @r, Source, Surface) |
|
198 | 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); |
755 | 390 |
//const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024); |
4 | 391 |
begin |
755 | 392 |
glBindTexture(GL_TEXTURE_2D, LandTexture^.id); |
753 | 393 |
glEnable(GL_TEXTURE_2D); |
394 |
||
755 | 395 |
glBegin(GL_QUADS); |
753 | 396 |
|
755 | 397 |
glTexCoord2i(0, 0); |
398 |
glVertex2i(X, Y); |
|
753 | 399 |
|
755 | 400 |
glTexCoord2i(1, 0); |
401 |
glVertex2i(2048 + X, Y); |
|
753 | 402 |
|
755 | 403 |
glTexCoord2i(1, 1); |
404 |
glVertex2i(2048 + X, 1024 + Y); |
|
753 | 405 |
|
755 | 406 |
glTexCoord2i(0, 1); |
407 |
glVertex2i(X, 1024 + Y); |
|
753 | 408 |
|
755 | 409 |
glEnd(); |
753 | 410 |
//DrawFromRect(X, Y, @r, LandSurface, Surface) |
4 | 411 |
end; |
412 |
||
371 | 413 |
procedure DrawCentered(X, Top: LongInt; Source, Surface: PSDL_Surface); |
95 | 414 |
var r: TSDL_Rect; |
415 |
begin |
|
351 | 416 |
r.x:= X - Source^.w div 2; |
95 | 417 |
r.y:= Top; |
351 | 418 |
r.w:= Source^.w; |
419 |
r.h:= Source^.h; |
|
95 | 420 |
SDL_UpperBlit(Source, nil, Surface, @r) |
4 | 421 |
end; |
422 |
||
371 | 423 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Surface: PSDL_Surface); |
4 | 424 |
var r: TSDL_Rect; |
425 |
begin |
|
426 |
r.x:= Step * 32; |
|
427 |
r.y:= Pos * 32; |
|
351 | 428 |
if Dir = -1 then r.x:= HHSurface^.w - 32 - r.x; |
4 | 429 |
r.w:= 32; |
430 |
r.h:= 32; |
|
755 | 431 |
//DrawFromRect(X, Y, @r, HHSurface, Surface) |
4 | 432 |
end; |
433 |
||
434 |
procedure StoreRelease; |
|
435 |
var ii: TSprite; |
|
436 |
begin |
|
437 |
for ii:= Low(TSprite) to High(TSprite) do |
|
759 | 438 |
FreeTexture(SpritesData[ii].Texture); |
4 | 439 |
SDL_FreeSurface( HHSurface ); |
690 | 440 |
SDL_FreeSurface(LandSurface ) |
4 | 441 |
end; |
442 |
||
351 | 443 |
function RenderString(s: string; Color: Longword; font: THWFont): PSDL_Surface; |
432 | 444 |
var w, h: LongInt; |
351 | 445 |
Result: PSDL_Surface; |
95 | 446 |
begin |
355 | 447 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
202 | 448 |
Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
351 | 449 |
cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask); |
107 | 450 |
TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
95 | 451 |
WriteInRoundRect(Result, 0, 0, Color, font, s); |
351 | 452 |
TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
453 |
RenderString:= Result |
|
95 | 454 |
end; |
455 |
||
4 | 456 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 457 |
var s: shortstring; |
4 | 458 |
begin |
351 | 459 |
str(Hedgehog.Gear^.Health, s); |
95 | 460 |
if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); |
549 | 461 |
Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Clan^.Color, fnt16) |
4 | 462 |
end; |
463 |
||
518 | 464 |
function LoadImage(const filename: string; hasAlpha: boolean; critical, setTransparent: boolean): PSDL_Surface; |
30 | 465 |
var tmpsurf: PSDL_Surface; |
753 | 466 |
//Result: PSDL_Surface; |
355 | 467 |
s: shortstring; |
4 | 468 |
begin |
469 |
WriteToConsole(msgLoading + filename + '... '); |
|
355 | 470 |
s:= filename + '.' + cBitsStr + '.png'; |
471 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 472 |
|
74 | 473 |
if tmpsurf = nil then |
351 | 474 |
begin |
355 | 475 |
s:= filename + '.png'; |
476 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
351 | 477 |
end; |
80 | 478 |
|
479 |
if tmpsurf = nil then |
|
480 |
if critical then OutError(msgFailed, true) |
|
481 |
else begin |
|
482 |
WriteLnToConsole(msgFailed); |
|
351 | 483 |
exit(nil) |
80 | 484 |
end; |
351 | 485 |
|
198 | 486 |
if setTransparent then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); |
753 | 487 |
//if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf) |
488 |
// else Result:= SDL_DisplayFormat(tmpsurf); |
|
620 | 489 |
{$IFDEF DEBUGFILE}WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');{$ENDIF} |
351 | 490 |
WriteLnToConsole(msgOK); |
753 | 491 |
LoadImage:= tmpsurf//Result |
492 |
end; |
|
493 |
||
494 |
procedure SetupOpenGL; |
|
495 |
var aspect: real; |
|
496 |
begin |
|
497 |
aspect:= cScreenWidth / cScreenHeight; |
|
498 |
||
756 | 499 |
glLoadIdentity; |
753 | 500 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
754 | 501 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
502 |
glTranslatef(-cScreenWidth / 2, -cScreenHeight / 2, 0); |
|
756 | 503 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
753 | 504 |
glMatrixMode(GL_MODELVIEW) |
4 | 505 |
end; |
506 |
||
510 | 507 |
//////////////////////////////////////////////////////////////////////////////// |
508 |
var ProgrSurf: PSDL_Surface = nil; |
|
534 | 509 |
Step: integer = 0; |
510 | 510 |
|
511 |
procedure AddProgress; |
|
512 |
var r: TSDL_Rect; |
|
513 |
begin |
|
514 |
if Step = 0 then |
|
515 |
begin |
|
516 |
WriteToConsole(msgLoading + 'progress sprite: '); |
|
517 |
ProgrSurf:= LoadImage(Pathz[ptGraphics] + '/Progress', false, true, true); |
|
518 |
end; |
|
519 |
SDL_FillRect(SDLPrimSurface, nil, 0); |
|
520 |
r.x:= 0; |
|
521 |
r.w:= ProgrSurf^.w; |
|
522 |
r.h:= ProgrSurf^.w; |
|
523 |
r.y:= (Step mod (ProgrSurf^.h div ProgrSurf^.w)) * ProgrSurf^.w; |
|
755 | 524 |
//DrawFromRect((cScreenWidth - ProgrSurf^.w) div 2, |
525 |
// (cScreenHeight - ProgrSurf^.w) div 2, @r, ProgrSurf, SDLPrimSurface); |
|
510 | 526 |
SDL_Flip(SDLPrimSurface); |
527 |
inc(Step); |
|
528 |
end; |
|
529 |
||
530 |
procedure FinishProgress; |
|
531 |
begin |
|
532 |
WriteLnToConsole('Freeing progress surface... '); |
|
533 |
SDL_FreeSurface(ProgrSurf) |
|
534 |
end; |
|
535 |
||
4 | 536 |
end. |