4
|
1 |
(*
|
|
2 |
* Hedgewars, a worms-like game
|
47
|
3 |
* Copyright (c) 2004, 2005, 2006 Andrey Korotaev <unC0Rr@gmail.com>
|
4
|
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;
|
42
|
40 |
TRangeArray = array[0..31] of record
|
|
41 |
Left, Right: integer;
|
|
42 |
end;
|
4
|
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);
|
43
|
50 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface);
|
4
|
51 |
procedure DrawLand (X, Y: integer; Surface: PSDL_Surface);
|
|
52 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface);
|
|
53 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface; const fromTempSurf: boolean = false);
|
47
|
54 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface);
|
4
|
55 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface);
|
|
56 |
procedure DrawExplosion(X, Y, Radius: integer);
|
42
|
57 |
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: Longword; y, dY: integer; Count: Byte);
|
38
|
58 |
procedure DrawTunnel(X, Y, dX, dY: real; ticks, HalfWidth: integer);
|
4
|
59 |
procedure RenderHealth(var Hedgehog: THedgehog);
|
|
60 |
function RenderString(var s: shortstring; Color, Pos: integer): TSDL_Rect;
|
|
61 |
procedure AddProgress;
|
35
|
62 |
function LoadImage(filename: string; hasAlpha: boolean): PSDL_Surface;
|
4
|
63 |
|
|
64 |
var PixelFormat: PSDL_PixelFormat;
|
|
65 |
SDLPrimSurface: PSDL_Surface;
|
|
66 |
|
|
67 |
implementation
|
|
68 |
uses uMisc, uIO, uConsole, uLand;
|
|
69 |
|
|
70 |
var StoreSurface,
|
|
71 |
TempSurface,
|
|
72 |
HHSurface: PSDL_Surface;
|
|
73 |
|
|
74 |
procedure DrawExplosion(X, Y, Radius: integer);
|
38
|
75 |
var ty, tx, p: integer;
|
4
|
76 |
begin
|
|
77 |
for ty:= max(-Radius, -y) to min(radius, 1023 - y) do
|
|
78 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
|
79 |
Land[ty + y, tx]:= 0;
|
|
80 |
|
|
81 |
if SDL_MustLock(LandSurface) then
|
|
82 |
SDLTry(SDL_LockSurface(LandSurface) >= 0, true);
|
|
83 |
|
38
|
84 |
p:= integer(LandSurface.pixels);
|
4
|
85 |
case LandSurface.format.BytesPerPixel of
|
|
86 |
1: ;// not supported
|
|
87 |
2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
88 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
|
89 |
PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= 0;
|
|
90 |
3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
91 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
|
92 |
begin
|
|
93 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= 0;
|
|
94 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= 0;
|
|
95 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= 0;
|
|
96 |
end;
|
|
97 |
4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
98 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
|
99 |
PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= 0;
|
|
100 |
end;
|
|
101 |
|
|
102 |
inc(Radius, 4);
|
|
103 |
|
|
104 |
case LandSurface.format.BytesPerPixel of
|
|
105 |
1: ;// not supported
|
|
106 |
2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
107 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
38
|
108 |
if Land[y + ty, tx] <> 0 then
|
4
|
109 |
PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= cExplosionBorderColor;
|
|
110 |
3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
111 |
for tx:= max(0, round(x-radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(x+radius*sqrt(1-sqr(ty/radius)))) do
|
38
|
112 |
if Land[y + ty, tx] <> 0 then
|
|
113 |
begin
|
4
|
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
|
38
|
120 |
if Land[y + ty, tx] <> 0 then
|
4
|
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 |
|
42
|
130 |
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: Longword; y, dY: integer; Count: Byte);
|
4
|
131 |
var tx, ty, i, p: integer;
|
|
132 |
begin
|
|
133 |
if SDL_MustLock(LandSurface) then
|
|
134 |
SDL_LockSurface(LandSurface);
|
|
135 |
|
38
|
136 |
p:= integer(LandSurface.pixels);
|
4
|
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
|
38
|
167 |
if Land[y + ty, tx] <> 0 then
|
4
|
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
|
38
|
171 |
if Land[y + ty, tx] <> 0 then
|
|
172 |
begin
|
4
|
173 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= cExplosionBorderColor and $FF;
|
|
174 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= (cExplosionBorderColor shr 8) and $FF;
|
|
175 |
PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= (cExplosionBorderColor shr 16);
|
|
176 |
end;
|
|
177 |
4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
178 |
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
|
38
|
179 |
if Land[y + ty, tx] <> 0 then
|
4
|
180 |
PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= cExplosionBorderColor;
|
|
181 |
end;
|
|
182 |
inc(y, dY)
|
|
183 |
end;
|
|
184 |
|
|
185 |
if SDL_MustLock(LandSurface) then
|
|
186 |
SDL_UnlockSurface(LandSurface);
|
|
187 |
end;
|
|
188 |
|
38
|
189 |
//
|
|
190 |
// - (dX, dY) - direction, vector of length = 0.5
|
|
191 |
//
|
|
192 |
procedure DrawTunnel(X, Y, dX, dY: real; ticks, HalfWidth: integer);
|
|
193 |
var nx, ny: real;
|
|
194 |
i, t, tx, ty, p: integer;
|
|
195 |
begin // (-dY, dX) is (dX, dY) turned by PI/2
|
|
196 |
if SDL_MustLock(LandSurface) then
|
|
197 |
SDL_LockSurface(LandSurface);
|
|
198 |
|
|
199 |
nx:= X + dY * (HalfWidth + 8);
|
|
200 |
ny:= Y - dX * (HalfWidth + 8);
|
|
201 |
p:= integer(LandSurface.pixels);
|
|
202 |
|
|
203 |
for i:= 0 to 7 do
|
|
204 |
begin
|
|
205 |
X:= nx - 8 * dX;
|
|
206 |
Y:= ny - 8 * dY;
|
|
207 |
for t:= -8 to ticks + 8 do
|
|
208 |
{$include tunsetborder.inc}
|
|
209 |
nx:= nx - dY;
|
|
210 |
ny:= ny + dX;
|
|
211 |
end;
|
|
212 |
|
|
213 |
for i:= -HalfWidth to HalfWidth do
|
|
214 |
begin
|
|
215 |
X:= nx - dX * 8;
|
|
216 |
Y:= ny - dY * 8;
|
|
217 |
for t:= 0 to 7 do
|
|
218 |
{$include tunsetborder.inc}
|
|
219 |
X:= nx;
|
|
220 |
Y:= ny;
|
|
221 |
for t:= 0 to ticks do
|
|
222 |
begin
|
|
223 |
X:= X + dX;
|
|
224 |
Y:= Y + dY;
|
|
225 |
tx:= round(X);
|
|
226 |
ty:= round(Y);
|
|
227 |
if ((ty and $FFFFFC00) = 0) and ((tx and $FFFFF800) = 0) then
|
|
228 |
begin
|
|
229 |
Land[ty, tx]:= 0;
|
|
230 |
case LandSurface.format.BytesPerPixel of
|
|
231 |
1: ;
|
|
232 |
2: PWord(p + LandSurface.pitch * ty + tx * 2)^:= 0;
|
|
233 |
3: begin
|
|
234 |
PByte(p + LandSurface.pitch * ty + tx * 3 + 0)^:= 0;
|
|
235 |
PByte(p + LandSurface.pitch * ty + tx * 3 + 1)^:= 0;
|
|
236 |
PByte(p + LandSurface.pitch * ty + tx * 3 + 2)^:= 0;
|
|
237 |
end;
|
|
238 |
4: PLongword(p + LandSurface.pitch * ty + tx * 4)^:= 0;
|
|
239 |
end
|
|
240 |
end
|
|
241 |
end;
|
|
242 |
for t:= 0 to 7 do
|
|
243 |
{$include tunsetborder.inc}
|
|
244 |
nx:= nx - dY;
|
|
245 |
ny:= ny + dX;
|
|
246 |
end;
|
|
247 |
|
|
248 |
for i:= 0 to 7 do
|
|
249 |
begin
|
|
250 |
X:= nx - 8 * dX;
|
|
251 |
Y:= ny - 8 * dY;
|
|
252 |
for t:= -8 to ticks + 8 do
|
|
253 |
{$include tunsetborder.inc}
|
|
254 |
nx:= nx - dY;
|
|
255 |
ny:= ny + dX;
|
|
256 |
end;
|
|
257 |
|
|
258 |
if SDL_MustLock(LandSurface) then
|
|
259 |
SDL_UnlockSurface(LandSurface)
|
|
260 |
end;
|
|
261 |
|
4
|
262 |
procedure StoreInit;
|
|
263 |
begin
|
|
264 |
StoreSurface := SDL_CreateRGBSurface(SDL_HWSURFACE, 576, 1024, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0);
|
|
265 |
TryDo( StoreSurface <> nil, errmsgCreateSurface + ': store' , true);
|
37
|
266 |
SDL_FillRect(StoreSurface, nil, 0);
|
4
|
267 |
|
|
268 |
TempSurface := SDL_CreateRGBSurface(SDL_HWSURFACE, 724, 320, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0);
|
|
269 |
TryDo( TempSurface <> nil, errmsgCreateSurface + ': temp' , true);
|
|
270 |
|
|
271 |
TryDo(SDL_SetColorKey( StoreSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
|
272 |
//TryDo(SDL_SetColorKey(SpriteSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
|
273 |
TryDo(SDL_SetColorKey( TempSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
|
274 |
end;
|
|
275 |
|
|
276 |
procedure LoadToSurface(Filename: String; Surface: PSDL_Surface; X, Y: integer);
|
|
277 |
var tmpsurf: PSDL_Surface;
|
|
278 |
rr: TSDL_Rect;
|
|
279 |
begin
|
35
|
280 |
tmpsurf:= LoadImage(Filename, false);
|
4
|
281 |
rr.x:= X;
|
|
282 |
rr.y:= Y;
|
|
283 |
SDL_UpperBlit(tmpsurf, nil, Surface, @rr);
|
|
284 |
SDL_FreeSurface(tmpsurf);
|
|
285 |
end;
|
|
286 |
|
47
|
287 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface);
|
|
288 |
var r: TSDL_Rect;
|
|
289 |
begin
|
|
290 |
r:= rect^;
|
|
291 |
SDL_FillRect(Surface, @r, 0);
|
|
292 |
r.y:= rect.y + 1;
|
|
293 |
r.h:= rect.h - 2;
|
|
294 |
SDL_FillRect(Surface, @r, BorderColor);
|
|
295 |
r.x:= rect.x + 1;
|
|
296 |
r.w:= rect.w - 2;
|
|
297 |
r.y:= rect.y;
|
|
298 |
r.h:= rect.h;
|
|
299 |
SDL_FillRect(Surface, @r, BorderColor);
|
|
300 |
r.x:= rect.x + 2;
|
|
301 |
r.y:= rect.y + 1;
|
|
302 |
r.w:= rect.w - 4;
|
|
303 |
r.h:= rect.h - 2;
|
|
304 |
SDL_FillRect(Surface, @r, FillColor);
|
|
305 |
r.x:= rect.x + 1;
|
|
306 |
r.y:= rect.y + 2;
|
|
307 |
r.w:= rect.w - 2;
|
|
308 |
r.h:= rect.h - 4;
|
|
309 |
SDL_FillRect(Surface, @r, FillColor)
|
|
310 |
end;
|
|
311 |
|
4
|
312 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: integer; Color: LongWord; Font: THWFont; s: string): TSDL_Rect;
|
|
313 |
var w, h: integer;
|
|
314 |
tmpsurf: PSDL_Surface;
|
|
315 |
clr: TSDL_Color;
|
|
316 |
begin
|
|
317 |
TTF_SizeText(Fontz[Font].Handle, PChar(s), w, h);
|
|
318 |
Result.x:= X;
|
|
319 |
Result.y:= Y;
|
|
320 |
Result.w:= w + 6;
|
|
321 |
Result.h:= h + 6;
|
47
|
322 |
DrawRoundRect(@Result, cWhiteColor, cColorNearBlack, Surface);
|
4
|
323 |
SDL_GetRGB(Color, Surface.format, @clr.r, @clr.g, @clr.b);
|
|
324 |
tmpsurf:= TTF_RenderText_Blended(Fontz[Font].Handle, PChar(s), clr);
|
|
325 |
Result.x:= X + 3;
|
|
326 |
Result.y:= Y + 3;
|
|
327 |
SDL_UpperBlit(tmpsurf, nil, Surface, @Result);
|
|
328 |
SDL_FreeSurface(tmpsurf);
|
|
329 |
Result.x:= X;
|
|
330 |
Result.y:= Y;
|
|
331 |
Result.w:= w + 6;
|
|
332 |
Result.h:= h + 6
|
|
333 |
end;
|
|
334 |
|
|
335 |
procedure StoreLoad;
|
|
336 |
var i: TStuff;
|
|
337 |
ii: TSprite;
|
|
338 |
fi: THWFont;
|
|
339 |
s: string;
|
|
340 |
tmpsurf: PSDL_Surface;
|
|
341 |
|
|
342 |
procedure WriteNames(Font: THWFont);
|
|
343 |
var Team: PTeam;
|
|
344 |
i: integer;
|
47
|
345 |
r, rr: TSDL_Rect;
|
4
|
346 |
begin
|
|
347 |
r.x:= 0;
|
|
348 |
r.y:= 272;
|
|
349 |
Team:= TeamsList;
|
|
350 |
while Team<>nil do
|
|
351 |
begin
|
47
|
352 |
r.w:= 104;
|
4
|
353 |
r:= WriteInRoundRect(StoreSurface, r.x, r.y, Team.Color, Font, Team.TeamName);
|
|
354 |
Team.NameRect:= r;
|
|
355 |
inc(r.y, r.h);
|
47
|
356 |
r.w:= cTeamHealthWidth + 5;
|
|
357 |
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, StoreSurface);
|
|
358 |
Team.HealthRect:= r;
|
|
359 |
rr:= r;
|
|
360 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
|
|
361 |
DrawRoundRect(@rr, Team.Color, Team.Color, StoreSurface);
|
|
362 |
inc(r.y, r.h);
|
4
|
363 |
for i:= 0 to 7 do
|
|
364 |
if Team.Hedgehogs[i].Gear<>nil then
|
|
365 |
begin
|
|
366 |
r:= WriteInRoundRect(StoreSurface, r.x, r.y, Team.Color, Font, Team.Hedgehogs[i].Name);
|
|
367 |
Team.Hedgehogs[i].NameRect:= r;
|
|
368 |
inc(r.y, r.h)
|
|
369 |
end;
|
|
370 |
Team:= Team.Next
|
|
371 |
end;
|
|
372 |
end;
|
|
373 |
|
|
374 |
procedure MakeCrossHairs;
|
|
375 |
var Team: PTeam;
|
|
376 |
r: TSDL_Rect;
|
|
377 |
tmpsurf: PSDL_Surface;
|
|
378 |
s: string;
|
|
379 |
TransColor: Longword;
|
|
380 |
begin
|
|
381 |
r.x:= 0;
|
|
382 |
r.y:= 256;
|
|
383 |
r.w:= 16;
|
|
384 |
r.h:= 16;
|
|
385 |
s:= Pathz[ptGraphics] + cCHFileName;
|
|
386 |
WriteToConsole(msgLoading + s + ' ');
|
|
387 |
tmpsurf:= IMG_Load(PChar(s));
|
|
388 |
TryDo(tmpsurf <> nil, msgFailed, true);
|
|
389 |
WriteLnToConsole(msgOK);
|
|
390 |
TransColor:= SDL_MapRGB(tmpsurf.format, $FF, $FF, $FF);
|
|
391 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, TransColor) = 0, errmsgTransparentSet, true);
|
|
392 |
|
|
393 |
Team:= TeamsList;
|
|
394 |
while Team<>nil do
|
|
395 |
begin
|
|
396 |
SDL_FillRect(StoreSurface, @r, Team.Color);
|
|
397 |
SDL_UpperBlit(tmpsurf, nil, StoreSurface, @r);
|
|
398 |
Team.CrossHairRect:= r;
|
|
399 |
inc(r.x, 16);
|
|
400 |
Team:= Team.Next
|
|
401 |
end;
|
|
402 |
|
|
403 |
SDL_FreeSurface(tmpsurf)
|
|
404 |
end;
|
|
405 |
|
|
406 |
procedure InitHealth;
|
|
407 |
var p: PTeam;
|
|
408 |
i, t: integer;
|
|
409 |
begin
|
|
410 |
p:= TeamsList;
|
|
411 |
t:= 0;
|
|
412 |
while p <> nil do
|
|
413 |
begin
|
|
414 |
for i:= 0 to cMaxHHIndex do
|
|
415 |
if p.Hedgehogs[i].Gear <> nil then
|
|
416 |
begin
|
|
417 |
p.Hedgehogs[i].HealthRect.y:= t;
|
|
418 |
RenderHealth(p.Hedgehogs[i]);
|
|
419 |
inc(t, p.Hedgehogs[i].HealthRect.h)
|
|
420 |
end;
|
|
421 |
p:= p.Next
|
|
422 |
end
|
|
423 |
end;
|
|
424 |
|
|
425 |
procedure LoadGraves;
|
|
426 |
var p: PTeam;
|
|
427 |
l: integer;
|
|
428 |
begin
|
|
429 |
p:= TeamsList;
|
|
430 |
l:= 512;
|
|
431 |
while p <> nil do
|
|
432 |
begin
|
|
433 |
dec(l, 32);
|
|
434 |
if p.GraveName = '' then p.GraveName:= 'Simple';
|
|
435 |
LoadToSurface(Pathz[ptGraves] + p.GraveName + '.png', StoreSurface, l, 512);
|
|
436 |
p.GraveRect.x:= l;
|
|
437 |
p.GraveRect.y:= 512;
|
|
438 |
p.GraveRect.w:= 32;
|
|
439 |
p.GraveRect.h:= 256;
|
|
440 |
p:= p.Next
|
|
441 |
end
|
|
442 |
end;
|
|
443 |
|
|
444 |
procedure GetSkyColor;
|
|
445 |
var p: Longword;
|
|
446 |
begin
|
|
447 |
if SDL_MustLock(StoreSurface) then
|
|
448 |
SDLTry(SDL_LockSurface(StoreSurface) >= 0, true);
|
|
449 |
p:= Longword(StoreSurface.pixels) + Word(StuffPoz[sSky].x) * StoreSurface.format.BytesPerPixel;
|
|
450 |
case StoreSurface.format.BytesPerPixel of
|
|
451 |
1: cSkyColor:= PByte(p)^;
|
|
452 |
2: cSkyColor:= PWord(p)^;
|
|
453 |
3: cSkyColor:= (PByte(p)^) or (PByte(p + 1)^ shl 8) or (PByte(p + 2)^ shl 16);
|
|
454 |
4: cSkyColor:= PLongword(p)^;
|
|
455 |
end;
|
|
456 |
if SDL_MustLock(StoreSurface) then
|
|
457 |
SDL_UnlockSurface(StoreSurface)
|
|
458 |
end;
|
|
459 |
|
|
460 |
procedure GetExplosionBorderColor;
|
|
461 |
var f: textfile;
|
|
462 |
c: integer;
|
|
463 |
begin
|
|
464 |
s:= Pathz[ptThemeCurrent] + cThemeCFGFilename;
|
|
465 |
WriteToConsole(msgLoading + s + ' ');
|
|
466 |
AssignFile(f, s);
|
|
467 |
{$I-}
|
|
468 |
Reset(f);
|
|
469 |
Readln(f, s);
|
|
470 |
Closefile(f);
|
|
471 |
{$I+}
|
|
472 |
TryDo(IOResult = 0, msgFailed, true);
|
|
473 |
WriteLnToConsole(msgOK);
|
|
474 |
val(s, cExplosionBorderColor, c);
|
|
475 |
if cFullScreen then
|
|
476 |
cExplosionBorderColor:= SDL_MapRGB(PixelFormat, (cExplosionBorderColor shr 16) and $FF,
|
|
477 |
(cExplosionBorderColor shr 8) and $FF,
|
|
478 |
cExplosionBorderColor and $FF)
|
|
479 |
else
|
|
480 |
cExplosionBorderColor:= SDL_MapRGB(LandSurface.format, (cExplosionBorderColor shr 16) and $FF,
|
|
481 |
(cExplosionBorderColor shr 8) and $FF,
|
|
482 |
cExplosionBorderColor and $FF)
|
|
483 |
end;
|
|
484 |
|
|
485 |
begin
|
|
486 |
for fi:= Low(THWFont) to High(THWFont) do
|
|
487 |
with Fontz[fi] do
|
|
488 |
begin
|
|
489 |
s:= Pathz[ptFonts] + Name;
|
|
490 |
WriteToConsole(msgLoading + s + ' ');
|
|
491 |
Handle:= TTF_OpenFont(PChar(s), Height);
|
|
492 |
TryDo(Handle <> nil, msgFailed, true);
|
|
493 |
WriteLnToConsole(msgOK)
|
|
494 |
end;
|
|
495 |
AddProgress;
|
35
|
496 |
//s:= Pathz[ptMapCurrent] + cLandFileName;
|
|
497 |
//WriteToConsole(msgLoading + s + ' ');
|
4
|
498 |
//tmpsurf:= IMG_Load(PChar(s));
|
|
499 |
tmpsurf:= LandSurface;
|
|
500 |
TryDo(tmpsurf <> nil, msgFailed, true);
|
|
501 |
if cFullScreen then
|
|
502 |
begin
|
|
503 |
LandSurface:= SDL_DisplayFormat(tmpsurf);
|
|
504 |
SDL_FreeSurface(tmpsurf);
|
|
505 |
end else LandSurface:= tmpsurf;
|
35
|
506 |
TryDo(SDL_SetColorKey(LandSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
|
4
|
507 |
WriteLnToConsole(msgOK);
|
|
508 |
|
|
509 |
GetExplosionBorderColor;
|
|
510 |
|
|
511 |
AddProgress;
|
|
512 |
for i:= Low(TStuff) to High(TStuff) do
|
|
513 |
LoadToSurface(Pathz[StuffLoadData[i].Path] + StuffLoadData[i].FileName, StoreSurface, StuffPoz[i].x, StuffPoz[i].y);
|
|
514 |
|
|
515 |
AddProgress;
|
|
516 |
WriteNames(fnt16);
|
|
517 |
MakeCrosshairs;
|
|
518 |
LoadGraves;
|
|
519 |
|
|
520 |
GetSkyColor;
|
|
521 |
|
|
522 |
AddProgress;
|
|
523 |
for ii:= Low(TSprite) to High(TSprite) do
|
|
524 |
with SpritesData[ii] do
|
35
|
525 |
Surface:= LoadImage(Pathz[Path] + FileName, hasAlpha);
|
4
|
526 |
|
|
527 |
AddProgress;
|
35
|
528 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + cHHFileName, false);
|
|
529 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
4
|
530 |
HHSurface:= SDL_DisplayFormat(tmpsurf);
|
|
531 |
SDL_FreeSurface(tmpsurf);
|
|
532 |
|
|
533 |
InitHealth;
|
|
534 |
|
|
535 |
{$IFDEF DUMP}
|
|
536 |
SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1);
|
|
537 |
SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1);
|
|
538 |
SDL_SaveBMP_RW(TempSurface, SDL_RWFromFile('TempSurface.bmp', 'wb'), 1);
|
|
539 |
{$ENDIF}
|
|
540 |
end;
|
|
541 |
|
|
542 |
procedure DrawFromRect(X, Y: integer; r: PSDL_Rect; SourceSurface, DestSurface: PSDL_Surface);
|
|
543 |
var rr: TSDL_Rect;
|
|
544 |
begin
|
|
545 |
rr.x:= X;
|
|
546 |
rr.y:= Y;
|
|
547 |
rr.w:= r.w;
|
|
548 |
rr.h:= r.h;
|
|
549 |
if SDL_UpperBlit(SourceSurface, r, DestSurface, @rr) < 0 then
|
|
550 |
begin
|
43
|
551 |
OutError('Blit: ' + SDL_GetError, true);
|
4
|
552 |
exit
|
|
553 |
end;
|
|
554 |
end;
|
|
555 |
|
|
556 |
procedure DrawGear(Stuff: TStuff; X, Y: integer; Surface: PSDL_Surface);
|
|
557 |
begin
|
|
558 |
DrawFromRect(X, Y, @StuffPoz[Stuff], StoreSurface, Surface)
|
|
559 |
end;
|
|
560 |
|
|
561 |
procedure DrawSpriteFromRect(r: TSDL_Rect; X, Y, Height, Position: integer; Surface: PSDL_Surface);
|
|
562 |
begin
|
|
563 |
r.y:= r.y + Height * Position;
|
|
564 |
r.h:= Height;
|
|
565 |
DrawFromRect(X, Y, @r, StoreSurface, Surface)
|
|
566 |
end;
|
|
567 |
|
|
568 |
procedure DrawSprite(Sprite: TSprite; X, Y, Position: integer; Surface: PSDL_Surface);
|
|
569 |
var r: TSDL_Rect;
|
|
570 |
begin
|
|
571 |
r.x:= 0;
|
|
572 |
r.w:= SpritesData[Sprite].Width;
|
|
573 |
r.y:= Position * SpritesData[Sprite].Height;
|
|
574 |
r.h:= SpritesData[Sprite].Height;
|
|
575 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface)
|
|
576 |
end;
|
|
577 |
|
43
|
578 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface);
|
|
579 |
var r: TSDL_Rect;
|
|
580 |
begin
|
|
581 |
r.x:= FrameX * SpritesData[Sprite].Width;
|
|
582 |
r.w:= SpritesData[Sprite].Width;
|
|
583 |
r.y:= FrameY * SpritesData[Sprite].Height;
|
|
584 |
r.h:= SpritesData[Sprite].Height;
|
|
585 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Surface, Surface)
|
|
586 |
end;
|
|
587 |
|
4
|
588 |
procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface);
|
|
589 |
var clr: TSDL_Color;
|
|
590 |
tmpsurf: PSDL_Surface;
|
|
591 |
r: TSDL_Rect;
|
|
592 |
begin
|
|
593 |
r.x:= X;
|
|
594 |
r.y:= Y;
|
|
595 |
SDL_GetRGB(cWhiteColor, PixelFormat, @clr.r, @clr.g, @clr.b);
|
|
596 |
tmpsurf:= TTF_RenderText_Solid(Fontz[Font].Handle, PChar(s), clr);
|
|
597 |
SDL_UpperBlit(tmpsurf, nil, Surface, @r);
|
|
598 |
SDL_FreeSurface(tmpsurf)
|
|
599 |
end;
|
|
600 |
|
|
601 |
procedure DrawLand(X, Y: integer; Surface: PSDL_Surface);
|
|
602 |
const r: TSDL_Rect = (x: 0; y: 0; w: 2048; h: 1024);
|
|
603 |
begin
|
|
604 |
DrawFromRect(X, Y, @r, LandSurface, Surface)
|
|
605 |
end;
|
|
606 |
|
47
|
607 |
procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface);
|
|
608 |
begin
|
|
609 |
DrawFromRect(X, Y, Rect, StoreSurface, Surface)
|
|
610 |
end;
|
|
611 |
|
4
|
612 |
procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface; const fromTempSurf: boolean = false);
|
|
613 |
begin
|
|
614 |
if fromTempSurf then DrawFromRect(X - (Rect.w) div 2, Y, @Rect, TempSurface, Surface)
|
|
615 |
else DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface)
|
|
616 |
end;
|
|
617 |
|
|
618 |
procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface);
|
|
619 |
var r: TSDL_Rect;
|
|
620 |
begin
|
|
621 |
r.x:= Step * 32;
|
|
622 |
r.y:= Pos * 32;
|
|
623 |
if Dir = -1 then r.x:= cHHSurfaceWidth - 32 - r.x;
|
|
624 |
r.w:= 32;
|
|
625 |
r.h:= 32;
|
|
626 |
DrawFromRect(X, Y, @r, HHSurface, Surface)
|
|
627 |
end;
|
|
628 |
|
|
629 |
procedure StoreRelease;
|
|
630 |
var ii: TSprite;
|
|
631 |
begin
|
|
632 |
for ii:= Low(TSprite) to High(TSprite) do
|
|
633 |
SDL_FreeSurface(SpritesData[ii].Surface);
|
|
634 |
SDL_FreeSurface( HHSurface );
|
|
635 |
SDL_FreeSurface(TempSurface );
|
|
636 |
SDL_FreeSurface(LandSurface );
|
|
637 |
SDL_FreeSurface(StoreSurface )
|
|
638 |
end;
|
|
639 |
|
|
640 |
procedure RenderHealth(var Hedgehog: THedgehog);
|
30
|
641 |
var s: string[15];
|
4
|
642 |
begin
|
|
643 |
str(Hedgehog.Gear.Health, s);
|
|
644 |
Hedgehog.HealthRect:= WriteInRoundRect(TempSurface, Hedgehog.HealthRect.x, Hedgehog.HealthRect.y, Hedgehog.Team.Color, fnt16, s);
|
|
645 |
if Hedgehog.Gear.Damage > 0 then
|
|
646 |
begin
|
|
647 |
str(Hedgehog.Gear.Damage, s);
|
|
648 |
Hedgehog.HealthTagRect:= WriteInRoundRect(TempSurface, Hedgehog.HealthRect.x + Hedgehog.HealthRect.w, Hedgehog.HealthRect.y, Hedgehog.Team.Color, fnt16, s)
|
|
649 |
end;
|
|
650 |
end;
|
|
651 |
|
|
652 |
function RenderString(var s: shortstring; Color, Pos: integer): TSDL_Rect;
|
|
653 |
begin
|
|
654 |
Result:= WriteInRoundRect(TempSurface, 64, Pos * Fontz[fntBig].Height, Color, fntBig, s);
|
|
655 |
end;
|
|
656 |
|
|
657 |
procedure AddProgress;
|
|
658 |
const Step: Longword = 0;
|
|
659 |
ProgrSurf: PSDL_Surface = nil;
|
|
660 |
MaxCalls = 10; // MaxCalls should be the count of calls to AddProgress to prevent memory leakage
|
|
661 |
var r: TSDL_Rect;
|
|
662 |
begin
|
|
663 |
if Step = 0 then
|
|
664 |
begin
|
|
665 |
WriteToConsole(msgLoading + 'progress sprite... ');
|
|
666 |
ProgrSurf:= IMG_Load(PChar(string('Data/Graphics/BigDigits.png')));
|
|
667 |
SDLTry(ProgrSurf <> nil, true);
|
|
668 |
WriteLnToConsole(msgOK)
|
|
669 |
end;
|
|
670 |
SDL_FillRect(SDLPrimSurface, nil, 0);
|
|
671 |
r.x:= 0;
|
|
672 |
r.w:= 32;
|
|
673 |
r.h:= 32;
|
|
674 |
r.y:= Step * 32;
|
|
675 |
DrawFromRect(cScreenWidth div 2 - 16, cScreenHeight div 2 - 16, @r, ProgrSurf, SDLPrimSurface);
|
|
676 |
SDL_Flip(SDLPrimSurface);
|
|
677 |
inc(Step);
|
|
678 |
if Step = MaxCalls then
|
|
679 |
begin
|
|
680 |
WriteLnToConsole('Freeing progress surface... ');
|
|
681 |
SDL_FreeSurface(ProgrSurf)
|
|
682 |
end;
|
|
683 |
end;
|
|
684 |
|
35
|
685 |
function LoadImage(filename: string; hasAlpha: boolean): PSDL_Surface;
|
30
|
686 |
var tmpsurf: PSDL_Surface;
|
4
|
687 |
begin
|
|
688 |
WriteToConsole(msgLoading + filename + '... ');
|
30
|
689 |
tmpsurf:= IMG_Load(PChar(filename));
|
|
690 |
TryDo(tmpsurf <> nil, msgFailed, true);
|
35
|
691 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
|
30
|
692 |
if cFullScreen then
|
|
693 |
begin
|
35
|
694 |
if hasAlpha then Result:= SDL_DisplayFormatAlpha(tmpsurf)
|
|
695 |
else Result:= SDL_DisplayFormat(tmpsurf);
|
30
|
696 |
SDL_FreeSurface(tmpsurf);
|
|
697 |
end else Result:= tmpsurf;
|
4
|
698 |
WriteLnToConsole(msgOK)
|
|
699 |
end;
|
|
700 |
|
|
701 |
end.
|