4
|
1 |
(*
|
|
2 |
* Hedgewars, a worms-like game
|
|
3 |
* Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com>
|
|
4 |
*
|
|
5 |
* Distributed under the terms of the BSD-modified licence:
|
|
6 |
*
|
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8 |
* of this software and associated documentation files (the "Software"), to deal
|
|
9 |
* with the Software without restriction, including without limitation the
|
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is
|
|
12 |
* furnished to do so, subject to the following conditions:
|
|
13 |
*
|
|
14 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
15 |
* this list of conditions and the following disclaimer.
|
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
17 |
* this list of conditions and the following disclaimer in the documentation
|
|
18 |
* and/or other materials provided with the distribution.
|
|
19 |
* 3. The name of the author may not be used to endorse or promote products
|
|
20 |
* derived from this software without specific prior written permission.
|
|
21 |
*
|
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32 |
*)
|
|
33 |
|
|
34 |
unit uStore;
|
|
35 |
interface
|
|
36 |
uses uConsts, uTeams, SDLh;
|
|
37 |
{$INCLUDE options.inc}
|
|
38 |
|
|
39 |
type PRangeArray = ^TRangeArray;
|
|
40 |
TRangeArray = array[byte] of record
|
|
41 |
Left, Right: integer;
|
|
42 |
end;
|
|
43 |
|
|
44 |
procedure StoreInit;
|
|
45 |
procedure StoreLoad;
|
|
46 |
procedure StoreRelease;
|
|
47 |
procedure DrawGear(Stuff : TStuff; X, Y: integer; Surface: PSDL_Surface);
|
|
48 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface);
|
|
49 |
procedure DrawSprite (Sprite: TSprite; X, Y, Position: integer; Surface: PSDL_Surface);
|
|
50 |
procedure DrawLand (X, Y: integer; Surface: PSDL_Surface);
|
|
51 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface);
|
|
52 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface; const fromTempSurf: boolean = false);
|
|
53 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface);
|
|
54 |
procedure DrawExplosion(X, Y, Radius: integer);
|
|
55 |
procedure DrawLineExplosions(ar: PRangeArray; Radius: Longword; y, dY: integer; Count: Byte);
|
|
56 |
procedure RenderHealth(var Hedgehog: THedgehog);
|
|
57 |
function RenderString(var s: shortstring; Color, Pos: integer): TSDL_Rect;
|
|
58 |
procedure AddProgress;
|
35
|
59 |
function LoadImage(filename: string; hasAlpha: boolean): PSDL_Surface;
|
4
|
60 |
|
|
61 |
var PixelFormat: PSDL_PixelFormat;
|
|
62 |
SDLPrimSurface: PSDL_Surface;
|
|
63 |
|
|
64 |
implementation
|
|
65 |
uses uMisc, uIO, uConsole, uLand;
|
|
66 |
|
|
67 |
var StoreSurface,
|
|
68 |
TempSurface,
|
|
69 |
HHSurface: PSDL_Surface;
|
|
70 |
|
|
71 |
procedure DrawExplosion(X, Y, Radius: integer);
|
|
72 |
var ty, tx: integer;
|
|
73 |
p: integer;
|
|
74 |
begin
|
|
75 |
for ty:= max(-Radius, -y) to min(radius, 1023 - y) do
|
|
76 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
|
77 |
Land[ty + y, tx]:= 0;
|
|
78 |
|
|
79 |
if SDL_MustLock(LandSurface) then
|
|
80 |
SDLTry(SDL_LockSurface(LandSurface) >= 0, true);
|
|
81 |
|
|
82 |
p:= Longword(LandSurface.pixels);
|
|
83 |
case LandSurface.format.BytesPerPixel of
|
|
84 |
1: ;// not supported
|
|
85 |
2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
86 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
|
87 |
PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= 0;
|
|
88 |
3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
89 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
|
90 |
begin
|
|
91 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= 0;
|
|
92 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= 0;
|
|
93 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= 0;
|
|
94 |
end;
|
|
95 |
4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
96 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
|
97 |
PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= 0;
|
|
98 |
end;
|
|
99 |
|
|
100 |
inc(Radius, 4);
|
|
101 |
|
|
102 |
case LandSurface.format.BytesPerPixel of
|
|
103 |
1: ;// not supported
|
|
104 |
2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
105 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
|
106 |
if PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^ <> 0 then
|
|
107 |
PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= cExplosionBorderColor;
|
|
108 |
3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
109 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
|
110 |
if (PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^ <> 0)
|
|
111 |
or (PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^ <> 0)
|
|
112 |
or (PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^ <> 0)
|
|
113 |
then begin
|
|
114 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= cExplosionBorderColor and $FF;
|
|
115 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= (cExplosionBorderColor shr 8) and $FF;
|
|
116 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= (cExplosionBorderColor shr 16);
|
|
117 |
end;
|
|
118 |
4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
119 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
|
120 |
if PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^ <> 0 then
|
|
121 |
PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= cExplosionBorderColor;
|
|
122 |
end;
|
|
123 |
|
|
124 |
if SDL_MustLock(LandSurface) then
|
|
125 |
SDL_UnlockSurface(LandSurface);
|
|
126 |
|
|
127 |
SDL_UpdateRect(LandSurface, X - Radius, Y - Radius, Radius * 2, Radius * 2)
|
|
128 |
end;
|
|
129 |
|
|
130 |
procedure DrawLineExplosions(ar: PRangeArray; Radius: Longword; y, dY: integer; Count: Byte);
|
|
131 |
var tx, ty, i, p: integer;
|
|
132 |
begin
|
|
133 |
if SDL_MustLock(LandSurface) then
|
|
134 |
SDL_LockSurface(LandSurface);
|
|
135 |
|
|
136 |
p:= Longword(LandSurface.pixels);
|
|
137 |
for i:= 0 to Pred(Count) do
|
|
138 |
begin
|
|
139 |
case LandSurface.format.BytesPerPixel of
|
|
140 |
1: ;
|
|
141 |
2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
142 |
for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
|
|
143 |
PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= 0;
|
|
144 |
3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
145 |
for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
|
|
146 |
begin
|
|
147 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= 0;
|
|
148 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= 0;
|
|
149 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= 0;
|
|
150 |
end;
|
|
151 |
4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
152 |
for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
|
|
153 |
PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= 0;
|
|
154 |
end;
|
|
155 |
inc(y, dY)
|
|
156 |
end;
|
|
157 |
|
|
158 |
inc(Radius, 4);
|
|
159 |
dec(y, Count*dY);
|
|
160 |
|
|
161 |
for i:= 0 to Pred(Count) do
|
|
162 |
begin
|
|
163 |
case LandSurface.format.BytesPerPixel of
|
|
164 |
1: ;
|
|
165 |
2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
166 |
for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
|
|
167 |
if PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^ <> 0 then
|
|
168 |
PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= cExplosionBorderColor;
|
|
169 |
3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
170 |
for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
|
|
171 |
if (PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^ <> 0)
|
|
172 |
or (PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^ <> 0)
|
|
173 |
or (PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^ <> 0)
|
|
174 |
then begin
|
|
175 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= cExplosionBorderColor and $FF;
|
|
176 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= (cExplosionBorderColor shr 8) and $FF;
|
|
177 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= (cExplosionBorderColor shr 16);
|
|
178 |
end;
|
|
179 |
4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
180 |
for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
|
|
181 |
if PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^ <> 0 then
|
|
182 |
PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= cExplosionBorderColor;
|
|
183 |
end;
|
|
184 |
inc(y, dY)
|
|
185 |
end;
|
|
186 |
|
|
187 |
if SDL_MustLock(LandSurface) then
|
|
188 |
SDL_UnlockSurface(LandSurface);
|
|
189 |
end;
|
|
190 |
|
|
191 |
procedure StoreInit;
|
35
|
192 |
var r: TSDL_Rect;
|
4
|
193 |
begin
|
|
194 |
StoreSurface := SDL_CreateRGBSurface(SDL_HWSURFACE, 576, 1024, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0);
|
|
195 |
TryDo( StoreSurface <> nil, errmsgCreateSurface + ': store' , true);
|
35
|
196 |
r.x:= 0;
|
|
197 |
r.y:= 0;
|
|
198 |
r.w:= 576;
|
|
199 |
r.h:= 1024;
|
|
200 |
SDL_FillRect(StoreSurface, @r, 0);
|
4
|
201 |
|
|
202 |
TempSurface := SDL_CreateRGBSurface(SDL_HWSURFACE, 724, 320, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0);
|
|
203 |
TryDo( TempSurface <> nil, errmsgCreateSurface + ': temp' , true);
|
|
204 |
|
|
205 |
TryDo(SDL_SetColorKey( StoreSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
|
206 |
//TryDo(SDL_SetColorKey(SpriteSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
|
207 |
TryDo(SDL_SetColorKey( TempSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
|
208 |
end;
|
|
209 |
|
|
210 |
procedure LoadToSurface(Filename: String; Surface: PSDL_Surface; X, Y: integer);
|
|
211 |
var tmpsurf: PSDL_Surface;
|
|
212 |
rr: TSDL_Rect;
|
|
213 |
begin
|
35
|
214 |
tmpsurf:= LoadImage(Filename, false);
|
4
|
215 |
rr.x:= X;
|
|
216 |
rr.y:= Y;
|
|
217 |
SDL_UpperBlit(tmpsurf, nil, Surface, @rr);
|
|
218 |
SDL_FreeSurface(tmpsurf);
|
|
219 |
end;
|
|
220 |
|
|
221 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: integer; Color: LongWord; Font: THWFont; s: string): TSDL_Rect;
|
|
222 |
var w, h: integer;
|
|
223 |
tmpsurf: PSDL_Surface;
|
|
224 |
clr: TSDL_Color;
|
|
225 |
begin
|
|
226 |
TTF_SizeText(Fontz[Font].Handle, PChar(s), w, h);
|
|
227 |
Result.x:= X;
|
|
228 |
Result.y:= Y;
|
|
229 |
Result.w:= w + 6;
|
|
230 |
Result.h:= h + 6;
|
|
231 |
SDL_FillRect(Surface, @Result, 0);
|
|
232 |
Result.w:= 1;
|
|
233 |
Result.y:= Y + 1;
|
|
234 |
Result.h:= h + 4;
|
|
235 |
SDL_FillRect(Surface, @Result, cWhiteColor);
|
|
236 |
Result.x:= X + w + 5;
|
|
237 |
SDL_FillRect(Surface, @Result, cWhiteColor);
|
|
238 |
Result.x:= X + 1;
|
|
239 |
Result.w:= w + 4;
|
|
240 |
Result.y:= Y;
|
|
241 |
Result.h:= 1;
|
|
242 |
SDL_FillRect(Surface, @Result, cWhiteColor);
|
|
243 |
Result.y:= Y + h + 5;
|
|
244 |
SDL_FillRect(Surface, @Result, cWhiteColor);
|
|
245 |
Result.x:= X + 1;
|
|
246 |
Result.y:= Y + 1;
|
|
247 |
Result.h:= h + 4;
|
|
248 |
SDL_FillRect(Surface, @Result, cColorNearBlack);
|
|
249 |
SDL_GetRGB(Color, Surface.format, @clr.r, @clr.g, @clr.b);
|
|
250 |
tmpsurf:= TTF_RenderText_Blended(Fontz[Font].Handle, PChar(s), clr);
|
|
251 |
Result.x:= X + 3;
|
|
252 |
Result.y:= Y + 3;
|
|
253 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result);
|
|
254 |
SDL_FreeSurface(tmpsurf);
|
|
255 |
Result.x:= X;
|
|
256 |
Result.y:= Y;
|
|
257 |
Result.w:= w + 6;
|
|
258 |
Result.h:= h + 6
|
|
259 |
end;
|
|
260 |
|
|
261 |
procedure StoreLoad;
|
|
262 |
var i: TStuff;
|
|
263 |
ii: TSprite;
|
|
264 |
fi: THWFont;
|
|
265 |
s: string;
|
|
266 |
tmpsurf: PSDL_Surface;
|
|
267 |
|
|
268 |
procedure WriteNames(Font: THWFont);
|
|
269 |
var Team: PTeam;
|
|
270 |
i: integer;
|
|
271 |
r: TSDL_Rect;
|
|
272 |
begin
|
|
273 |
r.x:= 0;
|
|
274 |
r.y:= 272;
|
|
275 |
Team:= TeamsList;
|
|
276 |
while Team<>nil do
|
|
277 |
begin
|
|
278 |
r.w:= 1968;
|
|
279 |
r:= WriteInRoundRect(StoreSurface, r.x, r.y, Team.Color, Font, Team.TeamName);
|
|
280 |
Team.NameRect:= r;
|
|
281 |
inc(r.y, r.h);
|
|
282 |
for i:= 0 to 7 do
|
|
283 |
if Team.Hedgehogs[i].Gear<>nil then
|
|
284 |
begin
|
|
285 |
r:= WriteInRoundRect(StoreSurface, r.x, r.y, Team.Color, Font, Team.Hedgehogs[i].Name);
|
|
286 |
Team.Hedgehogs[i].NameRect:= r;
|
|
287 |
inc(r.y, r.h)
|
|
288 |
end;
|
|
289 |
Team:= Team.Next
|
|
290 |
end;
|
|
291 |
end;
|
|
292 |
|
|
293 |
procedure MakeCrossHairs;
|
|
294 |
var Team: PTeam;
|
|
295 |
r: TSDL_Rect;
|
|
296 |
tmpsurf: PSDL_Surface;
|
|
297 |
s: string;
|
|
298 |
TransColor: Longword;
|
|
299 |
begin
|
|
300 |
r.x:= 0;
|
|
301 |
r.y:= 256;
|
|
302 |
r.w:= 16;
|
|
303 |
r.h:= 16;
|
|
304 |
s:= Pathz[ptGraphics] + cCHFileName;
|
|
305 |
WriteToConsole(msgLoading + s + ' ');
|
|
306 |
tmpsurf:= IMG_Load(PChar(s));
|
|
307 |
TryDo(tmpsurf <> nil, msgFailed, true);
|
|
308 |
WriteLnToConsole(msgOK);
|
|
309 |
TransColor:= SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF);
|
|
310 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, TransColor) = 0, errmsgTransparentSet, true);
|
|
311 |
|
|
312 |
Team:= TeamsList;
|
|
313 |
while Team<>nil do
|
|
314 |
begin
|
|
315 |
SDL_FillRect(StoreSurface, @r, Team.Color);
|
|
316 |
SDL_UpperBlit(tmpsurf, nil, StoreSurface, @r);
|
|
317 |
Team.CrossHairRect:= r;
|
|
318 |
inc(r.x, 16);
|
|
319 |
Team:= Team.Next
|
|
320 |
end;
|
|
321 |
|
|
322 |
SDL_FreeSurface(tmpsurf)
|
|
323 |
end;
|
|
324 |
|
|
325 |
procedure InitHealth;
|
|
326 |
var p: PTeam;
|
|
327 |
i, t: integer;
|
|
328 |
begin
|
|
329 |
p:= TeamsList;
|
|
330 |
t:= 0;
|
|
331 |
while p <> nil do
|
|
332 |
begin
|
|
333 |
for i:= 0 to cMaxHHIndex do
|
|
334 |
if p.Hedgehogs[i].Gear <> nil then
|
|
335 |
begin
|
|
336 |
p.Hedgehogs[i].HealthRect.y:= t;
|
|
337 |
RenderHealth(p.Hedgehogs[i]);
|
|
338 |
inc(t, p.Hedgehogs[i].HealthRect.h)
|
|
339 |
end;
|
|
340 |
p:= p.Next
|
|
341 |
end
|
|
342 |
end;
|
|
343 |
|
|
344 |
procedure LoadGraves;
|
|
345 |
var p: PTeam;
|
|
346 |
l: integer;
|
|
347 |
begin
|
|
348 |
p:= TeamsList;
|
|
349 |
l:= 512;
|
|
350 |
while p <> nil do
|
|
351 |
begin
|
|
352 |
dec(l, 32);
|
|
353 |
if p.GraveName = '' then p.GraveName:= 'Simple';
|
|
354 |
LoadToSurface(Pathz[ptGraves] + p.GraveName + '.png', StoreSurface, l, 512);
|
|
355 |
p.GraveRect.x:= l;
|
|
356 |
p.GraveRect.y:= 512;
|
|
357 |
p.GraveRect.w:= 32;
|
|
358 |
p.GraveRect.h:= 256;
|
|
359 |
p:= p.Next
|
|
360 |
end
|
|
361 |
end;
|
|
362 |
|
|
363 |
procedure GetSkyColor;
|
|
364 |
var p: Longword;
|
|
365 |
begin
|
|
366 |
if SDL_MustLock(StoreSurface) then
|
|
367 |
SDLTry(SDL_LockSurface(StoreSurface) >= 0, true);
|
|
368 |
p:= Longword(StoreSurface.pixels) + Word(StuffPoz[sSky].x) * StoreSurface.format.BytesPerPixel;
|
|
369 |
case StoreSurface.format.BytesPerPixel of
|
|
370 |
1: cSkyColor:= PByte(p)^;
|
|
371 |
2: cSkyColor:= PWord(p)^;
|
|
372 |
3: cSkyColor:= (PByte(p)^) or (PByte(p + 1)^ shl 8) or (PByte(p + 2)^ shl 16);
|
|
373 |
4: cSkyColor:= PLongword(p)^;
|
|
374 |
end;
|
|
375 |
if SDL_MustLock(StoreSurface) then
|
|
376 |
SDL_UnlockSurface(StoreSurface)
|
|
377 |
end;
|
|
378 |
|
|
379 |
procedure GetExplosionBorderColor;
|
|
380 |
var f: textfile;
|
|
381 |
c: integer;
|
|
382 |
begin
|
|
383 |
s:= Pathz[ptThemeCurrent] + cThemeCFGFilename;
|
|
384 |
WriteToConsole(msgLoading + s + ' ');
|
|
385 |
AssignFile(f, s);
|
|
386 |
{$I-}
|
|
387 |
Reset(f);
|
|
388 |
Readln(f, s);
|
|
389 |
Closefile(f);
|
|
390 |
{$I+}
|
|
391 |
TryDo(IOResult = 0, msgFailed, true);
|
|
392 |
WriteLnToConsole(msgOK);
|
|
393 |
val(s, cExplosionBorderColor, c);
|
|
394 |
if cFullScreen then
|
|
395 |
cExplosionBorderColor:= SDL_MapRGB(PixelFormat, (cExplosionBorderColor shr 16) and $FF,
|
|
396 |
(cExplosionBorderColor shr 8) and $FF,
|
|
397 |
cExplosionBorderColor and $FF)
|
|
398 |
else
|
|
399 |
cExplosionBorderColor:= SDL_MapRGB(LandSurface.format, (cExplosionBorderColor shr 16) and $FF,
|
|
400 |
(cExplosionBorderColor shr 8) and $FF,
|
|
401 |
cExplosionBorderColor and $FF)
|
|
402 |
end;
|
|
403 |
|
|
404 |
begin
|
|
405 |
for fi:= Low(THWFont) to High(THWFont) do
|
|
406 |
with Fontz[fi] do
|
|
407 |
begin
|
|
408 |
s:= Pathz[ptFonts] + Name;
|
|
409 |
WriteToConsole(msgLoading + s + ' ');
|
|
410 |
Handle:= TTF_OpenFont(PChar(s), Height);
|
|
411 |
TryDo(Handle <> nil, msgFailed, true);
|
|
412 |
WriteLnToConsole(msgOK)
|
|
413 |
end;
|
|
414 |
AddProgress;
|
35
|
415 |
//s:= Pathz[ptMapCurrent] + cLandFileName;
|
|
416 |
//WriteToConsole(msgLoading + s + ' ');
|
4
|
417 |
//tmpsurf:= IMG_Load(PChar(s));
|
|
418 |
tmpsurf:= LandSurface;
|
|
419 |
TryDo(tmpsurf <> nil, msgFailed, true);
|
|
420 |
if cFullScreen then
|
|
421 |
begin
|
|
422 |
LandSurface:= SDL_DisplayFormat(tmpsurf);
|
|
423 |
SDL_FreeSurface(tmpsurf);
|
|
424 |
end else LandSurface:= tmpsurf;
|
35
|
425 |
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
|
4
|
426 |
WriteLnToConsole(msgOK);
|
|
427 |
|
|
428 |
GetExplosionBorderColor;
|
|
429 |
|
|
430 |
AddProgress;
|
|
431 |
for i:= Low(TStuff) to High(TStuff) do
|
|
432 |
LoadToSurface(Pathz[StuffLoadData[i].Path] + StuffLoadData[i].FileName, StoreSurface, StuffPoz[i].x, StuffPoz[i].y);
|
|
433 |
|
|
434 |
AddProgress;
|
|
435 |
WriteNames(fnt16);
|
|
436 |
MakeCrosshairs;
|
|
437 |
LoadGraves;
|
|
438 |
|
|
439 |
GetSkyColor;
|
|
440 |
|
|
441 |
AddProgress;
|
|
442 |
for ii:= Low(TSprite) to High(TSprite) do
|
|
443 |
with SpritesData[ii] do
|
35
|
444 |
Surface:= LoadImage(Pathz[Path] + FileName, hasAlpha);
|
4
|
445 |
|
|
446 |
AddProgress;
|
35
|
447 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + cHHFileName, false);
|
|
448 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
4
|
449 |
HHSurface:= SDL_DisplayFormat(tmpsurf);
|
|
450 |
SDL_FreeSurface(tmpsurf);
|
|
451 |
|
|
452 |
InitHealth;
|
|
453 |
|
|
454 |
{$IFDEF DUMP}
|
|
455 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1);
|
|
456 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1);
|
|
457 |
SDL_SaveBMP_RW(TempSurface, SDL_RWFromFile('TempSurface.bmp', 'wb'), 1);
|
|
458 |
{$ENDIF}
|
|
459 |
end;
|
|
460 |
|
|
461 |
procedure DrawFromRect(X, Y: integer; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface);
|
|
462 |
var rr: TSDL_Rect;
|
|
463 |
begin
|
|
464 |
rr.x:= X;
|
|
465 |
rr.y:= Y;
|
|
466 |
rr.w:= r.w;
|
|
467 |
rr.h:= r.h;
|
|
468 |
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then
|
|
469 |
begin
|
|
470 |
Writeln('Blit: ', SDL_GetError);
|
|
471 |
exit
|
|
472 |
end;
|
|
473 |
end;
|
|
474 |
|
|
475 |
procedure DrawGear(Stuff: TStuff; X, Y: integer; Surface: PSDL_Surface);
|
|
476 |
begin
|
|
477 |
DrawFromRect(X, Y, @StuffPoz[Stuff], StoreSurface, Surface)
|
|
478 |
end;
|
|
479 |
|
|
480 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface);
|
|
481 |
begin
|
|
482 |
r.y:= r.y + Height * Position;
|
|
483 |
r.h:= Height;
|
|
484 |
DrawFromRect(X, Y, @r, StoreSurface, Surface)
|
|
485 |
end;
|
|
486 |
|
|
487 |
procedure DrawSprite(Sprite: TSprite; X, Y, Position: integer; Surface: PSDL_Surface);
|
|
488 |
var r: TSDL_Rect;
|
|
489 |
begin
|
|
490 |
r.x:= 0;
|
|
491 |
r.w:= SpritesData[Sprite].Width;
|
|
492 |
r.y:= Position * SpritesData[Sprite].Height;
|
|
493 |
r.h:= SpritesData[Sprite].Height;
|
|
494 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface)
|
|
495 |
end;
|
|
496 |
|
|
497 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface);
|
|
498 |
var clr: TSDL_Color;
|
|
499 |
tmpsurf: PSDL_Surface;
|
|
500 |
r: TSDL_Rect;
|
|
501 |
begin
|
|
502 |
r.x:= X;
|
|
503 |
r.y:= Y;
|
|
504 |
SDL_GetRGB(cWhiteColor, PixelFormat, @clr.r, @clr.g, @clr.b);
|
|
505 |
tmpsurf:= TTF_RenderText_Solid(Fontz[Font].Handle, PChar(s), clr);
|
|
506 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r);
|
|
507 |
SDL_FreeSurface(tmpsurf)
|
|
508 |
end;
|
|
509 |
|
|
510 |
procedure DrawLand(X, Y: integer; Surface: PSDL_Surface);
|
|
511 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024);
|
|
512 |
begin
|
|
513 |
DrawFromRect(X, Y, @r, LandSurface, Surface)
|
|
514 |
end;
|
|
515 |
|
|
516 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface; const fromTempSurf: boolean = false);
|
|
517 |
begin
|
|
518 |
if fromTempSurf then DrawFromRect(X - (Rect.w) div 2, Y, @Rect, TempSurface, Surface)
|
|
519 |
else DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface)
|
|
520 |
end;
|
|
521 |
|
|
522 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface);
|
|
523 |
var r: TSDL_Rect;
|
|
524 |
begin
|
|
525 |
r.x:= Step * 32;
|
|
526 |
r.y:= Pos * 32;
|
|
527 |
if Dir = -1 then r.x:= cHHSurfaceWidth - 32 - r.x;
|
|
528 |
r.w:= 32;
|
|
529 |
r.h:= 32;
|
|
530 |
DrawFromRect(X, Y, @r, HHSurface, Surface)
|
|
531 |
end;
|
|
532 |
|
|
533 |
procedure StoreRelease;
|
|
534 |
var ii: TSprite;
|
|
535 |
begin
|
|
536 |
for ii:= Low(TSprite) to High(TSprite) do
|
|
537 |
SDL_FreeSurface(SpritesData[ii].Surface);
|
|
538 |
SDL_FreeSurface( HHSurface );
|
|
539 |
SDL_FreeSurface(TempSurface );
|
|
540 |
SDL_FreeSurface(LandSurface );
|
|
541 |
SDL_FreeSurface(StoreSurface )
|
|
542 |
end;
|
|
543 |
|
|
544 |
procedure RenderHealth(var Hedgehog: THedgehog);
|
30
|
545 |
var s: string[15];
|
4
|
546 |
begin
|
|
547 |
str(Hedgehog.Gear.Health, s);
|
|
548 |
Hedgehog.HealthRect:= WriteInRoundRect(TempSurface, Hedgehog.HealthRect.x, Hedgehog.HealthRect.y, Hedgehog.Team.Color, fnt16, s);
|
|
549 |
if Hedgehog.Gear.Damage > 0 then
|
|
550 |
begin
|
|
551 |
str(Hedgehog.Gear.Damage, s);
|
|
552 |
Hedgehog.HealthTagRect:= WriteInRoundRect(TempSurface, Hedgehog.HealthRect.x + Hedgehog.HealthRect.w, Hedgehog.HealthRect.y, Hedgehog.Team.Color, fnt16, s)
|
|
553 |
end;
|
|
554 |
end;
|
|
555 |
|
|
556 |
function RenderString(var s: shortstring; Color, Pos: integer): TSDL_Rect;
|
|
557 |
begin
|
|
558 |
Result:= WriteInRoundRect(TempSurface, 64, Pos * Fontz[fntBig].Height, Color, fntBig, s);
|
|
559 |
end;
|
|
560 |
|
|
561 |
procedure AddProgress;
|
|
562 |
const Step: Longword = 0;
|
|
563 |
ProgrSurf: PSDL_Surface = nil;
|
|
564 |
MaxCalls = 10; // MaxCalls should be the count of calls to AddProgress to prevent memory leakage
|
|
565 |
var r: TSDL_Rect;
|
|
566 |
begin
|
|
567 |
if Step = 0 then
|
|
568 |
begin
|
|
569 |
WriteToConsole(msgLoading + 'progress sprite... ');
|
|
570 |
ProgrSurf:= IMG_Load(PChar(string('Data/Graphics/BigDigits.png')));
|
|
571 |
SDLTry(ProgrSurf <> nil, true);
|
|
572 |
WriteLnToConsole(msgOK)
|
|
573 |
end;
|
|
574 |
SDL_FillRect(SDLPrimSurface, nil, 0);
|
|
575 |
r.x:= 0;
|
|
576 |
r.w:= 32;
|
|
577 |
r.h:= 32;
|
|
578 |
r.y:= Step * 32;
|
|
579 |
DrawFromRect(cScreenWidth div 2 - 16, cScreenHeight div 2 - 16, @r, ProgrSurf, SDLPrimSurface);
|
|
580 |
SDL_Flip(SDLPrimSurface);
|
|
581 |
inc(Step);
|
|
582 |
if Step = MaxCalls then
|
|
583 |
begin
|
|
584 |
WriteLnToConsole('Freeing progress surface... ');
|
|
585 |
SDL_FreeSurface(ProgrSurf)
|
|
586 |
end;
|
|
587 |
end;
|
|
588 |
|
35
|
589 |
function LoadImage(filename: string; hasAlpha: boolean): PSDL_Surface;
|
30
|
590 |
var tmpsurf: PSDL_Surface;
|
4
|
591 |
begin
|
|
592 |
WriteToConsole(msgLoading + filename + '... ');
|
30
|
593 |
tmpsurf:= IMG_Load(PChar(filename));
|
|
594 |
TryDo(tmpsurf <> nil, msgFailed, true);
|
35
|
595 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
30
|
596 |
if cFullScreen then
|
|
597 |
begin
|
35
|
598 |
if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf)
|
|
599 |
else Result:= SDL_DisplayFormat(tmpsurf);
|
30
|
600 |
SDL_FreeSurface(tmpsurf);
|
|
601 |
end else Result:= tmpsurf;
|
4
|
602 |
WriteLnToConsole(msgOK)
|
|
603 |
end;
|
|
604 |
|
|
605 |
end.
|