This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDISPLAY.PAS
276 lines (224 loc) · 6.55 KB
/
DISPLAY.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
(*
** Display functions, game objects display codes
*)
unit Display;
(**********************************************************)
(**) (**)
(**) INTERFACE (**)
(**) (**)
(**********************************************************)
uses Crt,
Global;
const
(*$IFDEF CO80*)
sx = 80; (* game screen dimension *)
(*$IFDEF LN50*)
sy = 47;
ScreenMode = CO80+Font8x8;
(*$ELSE*)
sy = 22;
ScreenMode = CO80;
(*$ENDIF*)
(*$ELSE*)
sx = 40;
sy = 22;
ScreenMode = CO40;
(*$ENDIF*)
const
(*
** game images, chars
*)
ShipBodyCh = '#'; (* player *)
ShipShieldCh = ' ';
ShipFrontCh = '>';
ShipWingCh = '>';
ExtraCh = '$'; (* extra *)
MissileNormalCh = 'o'; (* shoot *)
MissileDoubleCh = '8';
BombCh = 'v';
ExplosionCh1 = '*'; (* explosion *)
ExplosionCh2 = '+';
HillUpCh = '/'; (* landscape *)
HillDownCh = '\';
HillFloorCh = '_';
CityCh = ':';
(*$IFDEF TEST*)
HillSolidCh = 'X';
SpaceCh = ':';
(*$ELSE*)
HillSolidCh = #0;
SpaceCh = ' ';
(*$ENDIF*)
NufinCh = #33;
RobotNeckCh1 = '['; (* robot neck *)
RobotNeckCh2 = '=';
RobotNeckCh3 = ']';
var
(*
** game objects images
*)
goShipBody, (* player *)
goShipFront,
goShipWing,
goShipShield,
goMissile, (* bullets *)
goMissileNormal,
goMissileDouble,
goBomb,
goRocket, (* enemies *)
goBase,
goUfo,
goRobotNeck1, (* robot neck *)
goRobotNeck2,
goRobotNeck3,
goExplosion1,
goExplosion2,
goHillUp, (* landscape *)
goHillDown,
goHillFloor,
goCity,
goHillSolid,
goNufin, (* don't change display ID *)
goExtra, (* extra *)
goSpace : word;
(*
** colors
*)
ColorStd,
ColorInv,
ColorLit: byte;
oldTextMode: byte;
oldTextAttr: byte;
scr : array[1..sy, 1..sx] of word;
ScrollCounter : byte;
ScreenBase: pointer;
UpdateInfo: byte; (* update score & co. display *)
type
PosType = integer; (* position type *)
speedType = shortInt; (* speed type *)
procedure setScr(x,y: PosType; wd: word);
function getScr(x,y: PosType): word;
function go( ch: char; col: byte ): word;
procedure WriteColXY( x,y: byte; s: string );
procedure WriteCtr( y: byte; s: string );
procedure WriteMessage(msg: string);
(**********************************************************)
(**) (**)
(**) IMPLEMENTATION (**)
(**) (**)
(**********************************************************)
(*
** set/getScr: set/get a screen char
*)
procedure setScr(x,y: PosType; wd: word);
begin
if (x>0) and (x<=sx) and (y>0) and (y<=sy) then
scr[y,x] := wd;
end;
function getScr(x,y: PosType): word;
begin
if (x>0) and (x<=sx) and (y>0) and (y<=sy) then
getScr := scr[y,x]
else
getScr := goHillSolid;
end;
(*
** go: convert ch & col to display-ch
*)
function go( ch: char; col: byte ): word;
begin
go := ord(ch) + word(col) shl 8;
end;
(*
** WriteColXY
*)
procedure WriteColXY( x,y: byte; s: string );
var
i: byte; (* loop var *)
begin
GotoXY(x,y); (* set cursor *)
for i := 1 to length(s) do (* write string *)
if s[i] <> '^' then (* is next char a '^'? *)
Write( s[i] ) (* N-> write it to screen *)
else begin (* Y-> set color *)
inc(i);
case s[i] of
'S': TextAttr := ColorStd; (* standard color *)
'I': TextAttr := ColorInv; (* invers color *)
'H': TextAttr := ColorLit; (* highlighted color *)
end;
end;
end;
(*
** WriteCtr
**
** write string to screen, adjusting it to center;
** supports also '^S' and '^I' to change color in string
*)
procedure WriteCtr( y: byte; s: string );
var
i : byte; (* loop var *)
colCmdNum: byte; (* num. of '^' found in s *)
begin
colCmdNum := 0; (* calc num of '^' in s *)
for i := 1 to length(s) do
if s[i] = '^' then
inc(colCmdNum);
WriteColXY( (sx-length(s)+2*colCmdNum) div 2, y, s );
end;
procedure WriteMessage(msg: string);
var
key: char;
begin
if length(msg) >= (sx-5) then
msg := copy(msg,1,sx-8) + '..';
GotoXY(1,sy+2);
TextAttr := ColorInv;
Write(msg);
ClrEol;
GotoXY(sx-5,sy+2);
Write( '[CR]' );
TextAttr := ColorStd;
key := ReadKey;
end;
(*
** Initialisation
*)
begin
oldTextAttr := TextAttr; (* remember screen data *)
oldTextMode := LastMode;
if LastMode = Mono then
ScreenBase := ptr($b000, 0)
else
ScreenBase := ptr($b800, 0);
ColorStd := TextAttr;
ColorInv := (ColorStd shr 4) + (ColorStd and 7) shl 4;
ColorLit := ColorStd xor 8;
goShipBody := go( ShipBodyCh, ColorInv );
goShipShield := go( ShipShieldCh, ColorInv );
goShipFront := go( ShipFrontCh, ColorLit );
goShipWing := goShipFront;
goMissileNormal := go( MissileNormalCh, ColorStd );
goMissileDouble := go( MissileDoubleCh, ColorStd );
goBomb := go( BombCh, ColorStd );
goExtra := go( ExtraCh, ColorInv );
goExplosion1 := go( ExplosionCh1, ColorStd );
goExplosion2 := go( ExplosionCh2, ColorStd );
goHillUp := go( HillUpCh , ColorStd );
goHillDown := go( HillDownCh , ColorStd );
goHillFloor := go( HillFloorCh, ColorStd );
goCity := go( CityCh , ColorInv );
goRobotNeck1 := go( RobotNeckCh1, ColorStd );
goRobotNeck2 := go( RobotNeckCh2, ColorStd );
goRobotNeck3 := go( RobotNeckCh3, ColorStd );
(*$IFDEF TEST*)
goHillSolid := go( HillSolidCh, ColorLit );
goSpace := go( SpaceCh , ColorStd );
(*$ELSE*)
goHillSolid := go( HillSolidCh, 0 );
goSpace := go( SpaceCh, ColorStd );
(*$ENDIF*)
goNufin := go( NufinCh, ColorInv );
TextMode( ScreenMode );
end.