-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvaders.b2c
More file actions
executable file
·458 lines (427 loc) · 9.59 KB
/
vaders.b2c
File metadata and controls
executable file
·458 lines (427 loc) · 9.59 KB
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
font "mini_normal_font"
inline Font_set_fixed(mini_normal_font, 1);
inline Font_set_spacing(mini_normal_font, 6);
dim xvader0[20] as char
dim xvader1[20] as char
dim xvader2[20] as char
dim vader0[20] as char
dim vader1[20] as char
dim vader2[20] as char
dim spaces[20] as char
dim tones[10] as int
dim nt as int
dim score as long
dim lives as int
dim level as int
dim killed as int
dim xxx[2] as char
dim bottom_row as int
dim fire_key as int
dim cw as int
dim ch as int
dim x as int
dim y as int
dim z as int
dim dir as int
dim mx as int
dim my as int
dim missile as int
dim delay as int
dim curr_delay as int
dim row as int
dim col as int
dim max_key_delay as int
dim key_delay as int
dim status[40] as char
'''''''''''''''''''''''''''''
''' return true if odd
'''''''''''''''''''''''''''''
function odd(x as int)
inline x=x%2;
odd = x
end function
'''''''''''''''''''''''''''''
''' return width of string
'''''''''''''''''''''''''''''
function str_width(str as long)
inline _str_width = Font_string_width(mini_normal_font, (char *)str);
end function
'''''''''''''''''''''''''''''
''' return height of string
'''''''''''''''''''''''''''''
function str_height(str as long)
inline _str_height = Font_get_char_height(mini_normal_font);
end function
'''''''''''''''''''''''''''''
''' return length of string
'''''''''''''''''''''''''''''
function len(str as long)
inline _len = strlen((char *)str);
end function
'''''''''''''''''''''''''''''
''' repaint the main display
'''''''''''''''''''''''''''''
sub repaint(x as int, y as int)
cls
font "mini_bold_font"
inline sprintf(status, "Score: %4d Lives: %d Level: %d", score, lives, level);
printxy -80,49,status
font "mini_normal_font"
if odd(nt) then
printxy x,y,vader0
printxy x,y-ch,vader1
printxy x,y-ch-ch,vader2
else
printxy x,y,xvader0
printxy x,y-ch,xvader1
printxy x,y-ch-ch,xvader2
end if
printxy z-cw,-50+ch,"/ \"
if missile then
printxy mx,my,"|"
end if
end sub
'''''''''''''''''''''''''''''
''' redraw main display in reverse
''' and dislay SQUASHED!
'''''''''''''''''''''''''''''
sub squashed
ink 0
paper 3
repaint(x,y)
font "cool_bold_font"
printxy -50,6,"S Q U A S H E D !"
font "mini_normal_font"
beep -1
wait 5
beep 40
wait 5
beep 10
wait 5
beep 40
wait 5
beep -1
wait 5
ink 3
paper 0
end sub
''''''''''''''''''''
''' game over screen
''''''''''''''''''''
sub game_over
ink 0
paper 3
cls
font "cool_bold_font"
printxy -32,12,"G A M E"
printxy -20,-12,"O V E R"
font "mini_bold_font"
inline sprintf(status, "Score: %4d Lives: %d Level: %d", score, lives, level);
printxy -80,49,status
beep -1
wait 5
beep 10
wait 5
beep 40
wait 5
beep 10
wait 5
beep -1
wait 5
ink 3
paper 0
inline set_clicks_enabled(1);
while 1
wend
end sub
'''''''''''''''''''''''''''''
''' redraw the LEVEL screen
'''''''''''''''''''''''''''''
sub redraw_level
ink 0
paper 3
cls
beep -1
font "cool_bold_font"
printxy -30, 6, "Level: ", level
font "mini_normal_font"
ink 3
paper 0
wait 5
beep 10
wait 5
beep 40
wait 5
beep 10
wait 5
beep -1
wait 5
end sub
'''''''''''''''''''''''''''''
''' return length of longest row of vaders
'''''''''''''''''''''''''''''
function maxlen as int
dim width as int
maxlen = str_width(vader0);
width = str_width(vader1);
if width > maxlen then
maxlen = width
end if
width = str_width(vader2);
if width > maxlen then
maxlen = width
end if
end function
'''''''''''''''''''''''''''''
''' reinitialize variables for next level
'''''''''''''''''''''''''''''
sub next_level
bottom_row = 3
level = level + 1
redraw_level
if curr_delay > 50 then curr_delay = curr_delay - 50
if curr_delay < 50 then curr_delay = 50
delay = curr_delay
if max_key_delay > 13 then max_key_delay = max_key_delay - 13
if max_key_delay < 13 then max_key_delay = 13
key_delay = max_key_delay
dir = 1
missile = 0
nt = 0
killed = 0
x = -80
y = 49-ch
for q=0 to 15
if odd(q) then
vader0[q]=32
vader1[q]=32
vader2[q]=32
xvader0[q]=32
xvader1[q]=32
xvader2[q]=32
else
vader0[q]=171
vader1[q]=171
vader2[q]=171
xvader0[q]=170
xvader1[q]=170
xvader2[q]=170
end if
next
end sub
'''''''''''''''''''''''''''''
''' initialize the whole game
'''''''''''''''''''''''''''''
sub init
ink 0
paper 3
cls
font "cool_bold_font"
printxy -32,25,"V A D E R S"
font "mini_bold_font"
printxy -36,0,"By Greg Smith"
printxy -24,-25, "(C) 2001"
font "mini_normal_font"
ink 3
paper 0
wait 20
lives=3
level=0
curr_delay = 400
max_key_delay = 100
tones[0] = 5
tones[1] = 4
tones[2] = 3
tones[3] = 2
tones[4] = 1
xxx[0]=161
xxx[1]=0
cw = str_width(xxx)
ch = str_height(xxx)
inline set_clicks_enabled(0);
end sub
'''''''''''''''''''''''''''''
''' play a raw tone
'''''''''''''''''''''''''''''
sub raw(tone as int)
inline play_raw(tone);
end sub
'''''''''''''''''''''''''''''
''' return absolute value
'''''''''''''''''''''''''''''
function abs(a as int) as int
abs = a
if (a < 0) then
abs = -a
end if
end function
'''''''''''''''''''''''''''''
''' play the next vaders note
'''''''''''''''''''''''''''''
sub nexttone
beep tones[nt]+missile*10
nt = nt + 1
if nt >=4 then
nt = 0
end if
end sub
'''''''''''''''''''''''''''''
''' trim the spaces off the end of the string
'''''''''''''''''''''''''''''
sub trim(s as long)
inline char *xx = (char *)s;
inline xx = &xx[strlen(xx)-1];
inline while(*xx==' ') {*xx=0; xx--;}
end sub
'''''''''''''''''''''''''''''
''' return the character at r,c in the vaders arrays
'''''''''''''''''''''''''''''
function get_vaders(r as int, c as int) as int
if r=0 then
get_vaders = vader0[c]
elseif r=1 then
get_vaders = vader1[c]
else
get_vaders = vader2[c]
end if
end function
'''''''''''''''''''''''''''''
''' set the vaders(r,c) to z
''' and trim appropriately
'''''''''''''''''''''''''''''
sub set_vaders(r as int, c as int, z as int)
if r=0 then
vader0[c] = z
xvader0[c] = z
trim(vader0)
trim(xvader0)
elseif r=1 then
vader1[c] = z
xvader1[c] = z
trim(vader1)
trim(xvader1)
else
vader2[c] = z
xvader2[c] = z
trim(vader2)
trim(xvader2)
end if
while (vader0[0]=32) and (vader1[0]=32) and (vader2[0]=32)
inline strcpy(vader0, &vader0[2]);
inline memset(&vader0[strlen(vader0)], 0, 2);
inline strcpy(vader1, &vader1[2]);
inline memset(&vader1[strlen(vader1)], 0, 2);
inline strcpy(vader2, &vader2[2]);
inline memset(&vader2[strlen(vader2)], 0, 2);
inline strcpy(xvader0, &xvader0[2]);
inline strcpy(xvader1, &xvader1[2]);
inline strcpy(xvader2, &xvader2[2]);
x = x + cw + cw
wend
if vader0[0] <> 0 then bottom_row=1
if vader1[0] <> 0 then bottom_row=2
if vader2[0] <> 0 then bottom_row=3
end sub
'''''''''''''''''''''''''''''
''' move the vaders along
'''''''''''''''''''''''''''''
sub update_vaders
nexttone
x=x+cw*dir
if (x<=-80) or (x+str_width(vader0) >= 80) or (x+str_width(vader1) >= 80) or (x+str_width(vader2) >= 80) then
dir=-dir
y = y-ch
end if
end sub
'''''''''''''''''''''''''''''
''' move the missile along
'''''''''''''''''''''''''''''
sub update_missile
my=my+ch
beep abs(my)
if (my-ch > y-ch*3) and (my-ch < y) then
if (mx < x+cw*16) and (mx > x) then
row = (y-(my-ch))/ch
col = (mx-x)/cw
if (get_vaders(row,col) = -85) then
killed = killed + 1
set_vaders(row,col,32)
score = score + 10
for i=30 to 39
beep i
next
missile = 0
end if
end if
end if
if my >= 49 then
missile=0
else
printxy mx, my-ch, "|"
end if
end sub
'''''''''''''''''''''''''''''
''' watch the up, down, and enter keys
'''''''''''''''''''''''''''''
sub handle_keys
if key(264) then 'left
z=z-cw
if z <=-80 then
z=z+cw
end if
end if
if key(266) then 'right
z=z+cw
if z >=80 then
z=z-cw
end if
end if
if key(272) and fire_key=0 then 'enter
fire_key = 1
missile=1
mx=z+2
my=-45
end if
if key(272)=0 and fire_key=1 then ' key released
fire_key=0
end if
end sub
'''''''''''''''''''''''''''''
''' the main function
'''''''''''''''''''''''''''''
sub main0
init
lives=3
call next_level
while lives > 0
while(killed <> 24)
delay = delay - 1
if delay = 0 then
delay = curr_delay
call update_vaders
call repaint(x,y)
end if
if missile then
call update_missile
end if
key_delay = key_delay-1
if key_delay = 0 then
call handle_keys
key_delay = max_key_delay
end if
if y-ch*bottom_row <= -50 then
call squashed
lives = lives - 1
level = level - 1 'hack city
goto Die
end if
wend
Die:
if lives <> 0 then next_level
wend
end sub
'''''''''''''''''''''''''''''
''' call the main function
'''''''''''''''''''''''''''''
main0
game_over