-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathASSETS.PAS
180 lines (141 loc) · 4.32 KB
/
ASSETS.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
{$A+,B-,E+,F-,G+,I-,N+,P-,Q-,R-,S-,T-,V-,X+}
unit Assets;
interface
uses GDGfx, GDIFF, Maps, Shared;
type
UIFrameBitmaps = array[0..9] of PBitmap;
var
pal : Palette;
fnt : Font;
chunkyFnt : Font;
tiles : array[0..99] of PBitmap;
sprites : array[0..99] of PBitmap;
titleMain : PBitmap;
titleSelectLevel : PBitmap;
titleChooseFruit : PBitmap;
titleHelp : PBitmap;
titleResults : PBitmap;
titlePause : PBitmap;
uiTomatoFrame : UIFrameBitmaps;
uiGrapesFrame : UIFrameBitmaps;
uiGeneralFrame : UIFrameBitmaps;
function LoadTilesAndSprites(filename : string) : boolean;
function LoadImages(filename : string) : boolean;
function LoadMap(filename : string) : boolean;
implementation
uses Toolbox;
function LoadTilesAndSprites(filename : string) : boolean;
var
i, x, y, offset : integer;
puiFrame : ^UIFrameBitmaps;
label return;
begin
LoadTilesAndSprites := false;
UseLayer(BACKBUFFER_LAYER);
if LoadIFF(filename, @pal) <> IFFOk then goto return;
{ environment tiles are on the left }
offset := 0;
i := 0;
for y := 0 to 9 do begin
for x := 0 to 9 do begin
AllocBitmap(16, 16, tiles[i]);
GrabBitmap((x*16)+offset, y*16, 16, 16, tiles[i]);
inc(i);
end;
end;
{ sprites are on the right }
offset := 160;
i := 0;
for y := 0 to 9 do begin
for x := 0 to 9 do begin
AllocBitmap(16, 16, sprites[i]);
GrabBitmap((x*16)+offset, y*16, 16, 16, sprites[i]);
inc(i);
end;
end;
{ other things that are not in a uniform 16x16 grid }
for i := 0 to 2 do begin
case i of
0: puiFrame := @uiTomatoFrame;
1: puiFrame := @uiGrapesFrame;
2: puiFrame := @uiGeneralFrame;
end;
x := i * 48;
AllocBitmap(16, 16, puiFrame^[0]);
AllocBitmap(8, 8, puiFrame^[1]);
AllocBitmap(16, 16, puiFrame^[2]);
AllocBitmap(8, 8, puiFrame^[3]);
AllocBitmap(8, 8, puiFrame^[4]);
AllocBitmap(8, 8, puiFrame^[5]);
AllocBitmap(16, 16, puiFrame^[6]);
AllocBitmap(8, 8, puiFrame^[7]);
AllocBitmap(16, 16, puiFrame^[8]);
GrabBitmap(x+0, 176, 16, 16, puiFrame^[0]);
GrabBitmap(x+16, 176, 8, 8, puiFrame^[1]);
GrabBitmap(x+32, 176, 16, 16, puiFrame^[2]);
GrabBitmap(x+0, 184, 8, 8, puiFrame^[3]);
GrabBitmap(x+8, 184, 8, 8, puiFrame^[4]);
GrabBitmap(x+40, 184, 8, 8, puiFrame^[5]);
GrabBitmap(x+0, 184, 16, 16, puiFrame^[6]);
GrabBitmap(x+16, 192, 8, 8, puiFrame^[7]);
GrabBitmap(x+32, 184, 16, 16, puiFrame^[8]);
end;
LoadTilesAndSprites := true;
return:
UseLayer(SCREEN_LAYER);
end;
function LoadImages(filename : string) : boolean;
label return;
begin
LoadImages := false;
UseLayer(BACKBUFFER_LAYER);
if LoadIFF(filename, nil) <> IFFOk then goto return;
AllocBitmap(98, 38, titlePause);
GrabBitmap(3, 2, 98, 38, titlePause);
AllocBitmap(124, 39, titleResults);
GrabBitmap(121, 2, 124, 39, titleResults);
AllocBitmap(164, 37, titleSelectLevel);
GrabBitmap(2, 42, 164, 37, titleSelectLevel);
AllocBitmap(262, 35, titleChooseFruit);
GrabBitmap(2, 79, 262, 35, titleChooseFruit);
AllocBitmap(196, 40, titleHelp);
GrabBitmap(2, 112, 196, 40, titleHelp);
AllocBitmap(272, 48, titleMain);
GrabBitmap(2, 150, 272, 48, titleMain);
LoadImages := true;
return:
UseLayer(SCREEN_LAYER);
end;
function LoadMap(filename : string) : boolean;
var
f : file;
n : integer;
header : array[0..2] of char;
label ioError;
begin
LoadMap := false;
Assign(f, filename);
Reset(f, 1);
if IOResult <> 0 then begin
Close(f);
n := IOResult; { clear i/o error flag }
exit;
end;
{ validate file type by checking for expected header }
BlockRead(f, header, SizeOf(header));
if (header[0] <> 'M') or (header[1] <> 'A') or (header[2] <> 'P') then
goto ioError;
MemFill(@map, 0, SizeOf(map));
BlockRead(f, map, SizeOf(map), n);
if n <> SizeOf(map) then goto ioError;
isMapDirty := true;
LoadMap := true;
Close(f);
n := IOResult; { clear i/o error flag }
exit;
ioError:
LoadMap := false;
Close(f);
n := IOResult; { clear i/o error flag }
end;
end.