This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcnossus.bas
1633 lines (1491 loc) · 39 KB
/
cnossus.bas
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
' Escape from Cnossus -- a roguelike for the ZX Spectrum
' 2013-07-10 Felix Plesoianu <[email protected]>
'
' Permission is hereby granted, free of charge, to any person obtaining a copy
' of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights
' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is
' furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in
' all copies or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
' THE SOFTWARE.
#include <print64.bas>
const BLACK as ubyte = 0
const BLUE as ubyte = 1
const RED as ubyte = 2
const MAGENTA as ubyte = 3
const GREEN as ubyte = 4
const CYAN as ubyte = 5
const YELLOW as ubyte = 6
const WHITE as ubyte = 7
const MWIDTH as ubyte = 30
const MHEIGHT as ubyte = 20
const MAXLEVEL as ubyte = 20
const MAXMOBS as ubyte = MHEIGHT
const MAXITEMS as ubyte = MHEIGHT
const APREFRESH as ubyte = 20 ' Action point refresh.
const BLANK as ubyte = 0
const DOT as ubyte = 1
const COMMA as ubyte = 2
const VBAR as ubyte = 3
const STAR as ubyte = 4
const TILDA as ubyte = 5
const HASH as ubyte = 6
const GT as ubyte = 7
const ANDSIGN as ubyte = 8
dim tileChar(0 to 8) as string
tileChar(BLANK) = " "
tileChar(DOT) = "!"
tileChar(COMMA) = chr$(34)
tileChar(VBAR) = "#"
tileChar(STAR) = "$"
tileChar(TILDA) = "%"
tileChar(HASH) = "&"
tileChar(GT) = "'"
tileChar(ANDSIGN) = "("
dim tileName(0 to 8) as string
tileName(BLANK) = "void"
tileName(DOT) = "floor"
tileName(COMMA) = "mosaic"
tileName(VBAR) = "column"
tileName(STAR) = "basin"
tileName(TILDA) = "pool"
tileName(HASH) = "wall"
tileName(GT) = "stairs down"
tileName(ANDSIGN) = "statue"
dim tileInk(0 to 8) as ubyte => _
{BLACK, WHITE, MAGENTA, RED, CYAN, CYAN, YELLOW, WHITE, MAGENTA}
dim canWalk(0 to 8) as ubyte => {0, 1, 1, 0, 0, 0, 0, 1, 0}
const ITEMTYPES as ubyte = 23
const NOTHING as ubyte = 0
const CANDLE as ubyte = 1
const TORCH as ubyte = 2
const KNIFE as ubyte = 3
const SICKLE as ubyte = 4
const ADZE as ubyte = 5
const AXE as ubyte = 6
const DOUBLEAXE as ubyte = 7
const SWORD as ubyte = 8
const SPEAR as ubyte = 9
const RAWMEAT as ubyte = 10
const DRIEDFRUIT as ubyte = 11
const CHEESE as ubyte = 12
const OILLAMP as ubyte = 13
const BAG as ubyte = 14
const JAR as ubyte = 15
const COFFER as ubyte = 16
const GREAVE as ubyte = 17
const ARMGUARD as ubyte = 18
const PAULDRON as ubyte = 19
const CLOTH as ubyte = 20
const LEATHER as ubyte = 21
const SCALE as ubyte = 22
const SHIELD as ubyte = 23
dim itemChar(1 to ITEMTYPES) as string
itemChar(CANDLE) = ")" '\'
itemChar(TORCH) = "*"
itemChar(KNIFE) = "+" '(
itemChar(SICKLE) = ","
itemChar(ADZE) = "-"
itemChar(AXE) = "." ')
itemChar(DOUBLEAXE) = "/"
itemChar(SWORD) = "0" '/
itemChar(SPEAR) = "1"
itemChar(RAWMEAT) = "2" '%
itemChar(DRIEDFRUIT) = "3"
itemChar(CHEESE) = "4"
itemChar(OILLAMP) = "5" '\'
itemChar(BAG) = "6" '?
itemChar(JAR) = "7" '!
itemChar(COFFER) = "8" '=
itemChar(GREAVE) = "9" '[
itemChar(ARMGUARD) = ":"
itemChar(PAULDRON) = ";"
itemChar(CLOTH) = "<" ']
itemChar(LEATHER) = "="
itemChar(SCALE) = ">"
itemChar(SHIELD) = "?"
dim itemName(0 to ITEMTYPES) as string
itemName(NOTHING) = "nothing"
itemName(CANDLE) = "candle"
itemName(TORCH) = "torch"
itemName(KNIFE) = "knife"
itemName(SICKLE) = "sickle"
itemName(ADZE) = "adze"
itemName(AXE) = "axe"
itemName(DOUBLEAXE) = "double axe"
itemName(SWORD) = "short sword"
itemName(SPEAR) = "spear"
itemName(RAWMEAT) = "raw meat"
itemName(DRIEDFRUIT) = "dried fruit"
itemName(CHEESE) = "cheese"
itemName(OILLAMP) = "oil lamp"
itemName(BAG) = "bag"
itemName(JAR) = "big jar"
itemName(COFFER) = "coffer"
itemName(GREAVE) = "greave"
itemName(ARMGUARD) = "armguard"
itemName(PAULDRON) = "pauldron"
itemName(CLOTH) = "linen tunic"
itemName(LEATHER) = "leather vest"
itemName(SCALE) = "scale mail"
itemName(SHIELD) = "shield"
dim itemInk(1 to ITEMTYPES) as ubyte => _
{YELLOW, RED, _
YELLOW, YELLOW, YELLOW, YELLOW, YELLOW, YELLOW, YELLOW, _
RED, BLUE, WHITE, WHITE, WHITE, _
WHITE, RED, _
YELLOW, RED, RED, WHITE, RED, YELLOW, YELLOW}
dim maxCarry(1 to ITEMTYPES) as byte => _
{-1, -1, _
1, 1, 1, 1, 1, 1, 1, _
-1, -1, -1, -1, 1, _
0, 0, _
2, 2, 2, 1, 1, 1, 1}
dim itemAttack(1 to ITEMTYPES) as ubyte => _
{0, 0, 2, 3, 5, 8, 10, 12, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
dim itemDefense(1 to ITEMTYPES) as ubyte => _
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 3, 5}
const MOBTYPES as ubyte = 16
const NOBODY as ubyte = 0
const TAUR as ubyte = 1
const SNAKE as ubyte = 2
const SPIDER as ubyte = 3
const RAT as ubyte = 4
const SCORPION as ubyte = 5
const CENTIPEDE as ubyte = 6
const CERBERUS as ubyte = 7
const HARPY as ubyte = 8
const CHIMERA as ubyte = 9
const MANTICORE as ubyte = 10
const CROC as ubyte = 11
const DRAKON as ubyte = 12
const BOAR as ubyte = 13
const GRIFFIN as ubyte = 14
const SPHINX as ubyte = 15
const BULL as ubyte = 16
dim mobChar(1 to MOBTYPES) as string
mobChar(TAUR) = "@"
mobChar(SNAKE) = "s"
mobChar(SPIDER) = "m"
mobChar(RAT) = "r"
mobChar(SCORPION) = "i"
mobChar(CENTIPEDE) = "j"
mobChar(CERBERUS) = "c"
mobChar(HARPY) = "h"
mobChar(CHIMERA) = "H"
mobChar(MANTICORE) = "M"
mobChar(CROC) = "C"
mobChar(DRAKON) = "D"
mobChar(BOAR) = "b"
mobChar(GRIFFIN) = "G"
mobChar(SPHINX) = "X"
mobChar(BULL) = "B"
dim mobName(1 to MOBTYPES) as string
mobName(TAUR) = "minotaur"
mobName(SNAKE) = "snake"
mobName(SPIDER) = "spider"
mobName(RAT) = "sewer rat"
mobName(SCORPION) = "scorpion"
mobName(CENTIPEDE) = "centipede"
mobName(CERBERUS) = "cerberus"
mobName(HARPY) = "harpy"
mobName(CHIMERA) = "chimera"
mobName(MANTICORE) = "manticore"
mobName(CROC) = "crocodile"
mobName(DRAKON) = "drakon"
mobName(BOAR) = "wild boar"
mobName(GRIFFIN) = "griffin"
mobName(SPHINX) = "sphinx"
mobName(BULL) = "bull"
dim mobInk(1 to MOBTYPES) as ubyte => _
{WHITE, GREEN, RED, RED, RED, WHITE, _
BLUE, WHITE, YELLOW, YELLOW, GREEN, GREEN, _
RED, YELLOW, YELLOW, BLUE}
dim mobDice(1 to MOBTYPES) as ubyte => _
{10, 8, 4, 6, 4, 6, 8, 8, 12, 12, 12, 20, 8, 12, 12, 12}
dim mobHostility(1 to MOBTYPES) as ubyte => _
{0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 2}
dim mobPoison(1 to MOBTYPES) as ubyte => _
{0, 6, 4, 0, 8, 8, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0}
dim mobDrops(1 to MOBTYPES, 0 to 2) as ubyte => _
{{NOTHING, NOTHING, NOTHING}, _
{RAWMEAT, ARMGUARD, NOTHING}, _
{NOTHING, NOTHING, NOTHING}, _
{RAWMEAT, NOTHING, NOTHING}, _
{NOTHING, NOTHING, NOTHING}, _
{NOTHING, NOTHING, NOTHING}, _
{NOTHING, NOTHING, NOTHING}, _
{NOTHING, NOTHING, NOTHING}, _
{NOTHING, NOTHING, NOTHING}, _
{NOTHING, NOTHING, NOTHING}, _
{RAWMEAT, LEATHER, NOTHING}, _
{SHIELD, SHIELD, NOTHING}, _
{RAWMEAT, RAWMEAT, NOTHING}, _
{NOTHING, NOTHING, NOTHING}, _
{NOTHING, NOTHING, NOTHING}, _
{RAWMEAT, RAWMEAT, RAWMEAT}}
dim levelCellSize(0 to 4, 0 to 1) as ubyte => _
{{7, 7}, {7, 5}, {5, 5}, {5, 3}, {3, 3}}
dim levelMobs(1 to MAXLEVEL, 0 to 4) as ubyte => _
{{SNAKE, BOAR, CERBERUS, NOBODY, NOBODY}, _
{CENTIPEDE, BOAR, HARPY, NOBODY, NOBODY}, _
{SNAKE, CERBERUS, RAT, NOBODY, NOBODY}, _
{CENTIPEDE, HARPY, RAT, NOBODY, NOBODY}, _
{SNAKE, CERBERUS, BOAR, NOBODY, NOBODY}, _
{CENTIPEDE, HARPY, BOAR, NOBODY, NOBODY}, _
{SNAKE, NOBODY, CERBERUS, RAT, NOBODY}, _
{SPIDER, RAT, NOBODY, HARPY, NOBODY}, _
{SCORPION, BOAR, CROC, NOBODY, NOBODY}, _
{SPIDER, BOAR, HARPY, NOBODY, NOBODY}, _
{SCORPION, CROC, RAT, RAT, NOBODY}, _
{SPIDER, RAT, CERBERUS, HARPY, NOBODY}, _
{SCORPION, CROC, BOAR, NOBODY, NOBODY}, _
{SPIDER, BOAR, RAT, HARPY, NOBODY}, _
{MANTICORE, GRIFFIN, CROC, NOBODY, NOBODY}, _
{GRIFFIN, BULL, SPIDER, NOBODY, NOBODY}, _
{SPHINX, MANTICORE, BULL, NOBODY, NOBODY}, _
{SPHINX, CHIMERA, BULL, NOBODY, NOBODY}, _
{MANTICORE, CHIMERA, BULL, NOBODY, NOBODY}, _
{DRAKON, GRIFFIN, BULL, NOBODY, NOBODY}}
dim levelItems(1 to MAXLEVEL, 0 to 4) as ubyte => _
{{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, NOTHING, COFFER, NOTHING, TORCH}, _
{JAR, DOUBLEAXE, COFFER, NOTHING, TORCH}, _
{JAR, DOUBLEAXE, COFFER, NOTHING, TORCH}, _
{JAR, DOUBLEAXE, COFFER, NOTHING, TORCH}, _
{JAR, SPEAR, COFFER, SHIELD, TORCH}, _
{JAR, SPEAR, COFFER, SHIELD, TORCH}, _
{JAR, SPEAR, COFFER, SHIELD, TORCH}}
dim jarDrops(1 to MAXLEVEL, 0 to 4) as ubyte => _
{{DRIEDFRUIT, CANDLE, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, NOTHING, NOTHING, NOTHING}, _
{NOTHING, CANDLE, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, NOTHING, NOTHING, NOTHING}, _
{NOTHING, NOTHING, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, NOTHING, NOTHING, NOTHING}, _
{NOTHING, NOTHING, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, NOTHING, NOTHING, NOTHING}, _
{DRIEDFRUIT, NOTHING, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, NOTHING, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, NOTHING, CHEESE, NOTHING, NOTHING}, _
{DRIEDFRUIT, CANDLE, CHEESE, NOTHING, NOTHING}}
dim cofferDrops(1 to MAXLEVEL, 0 to 4) as ubyte => _
{{CLOTH, NOTHING, KNIFE, NOTHING, BAG}, _
{CLOTH, NOTHING, KNIFE, NOTHING, BAG}, _
{LEATHER, NOTHING, KNIFE, NOTHING, BAG}, _
{CLOTH, NOTHING, KNIFE, NOTHING, BAG}, _
{CLOTH, NOTHING, SICKLE, NOTHING, BAG}, _
{GREAVE, NOTHING, SICKLE, NOTHING, BAG}, _
{GREAVE, NOTHING, SICKLE, NOTHING, BAG}, _
{GREAVE, NOTHING, SICKLE, NOTHING, BAG}, _
{ARMGUARD, NOTHING, ADZE, NOTHING, BAG}, _
{ARMGUARD, NOTHING, ADZE, NOTHING, BAG}, _
{ARMGUARD, NOTHING, ADZE, NOTHING, OILLAMP}, _
{PAULDRON, NOTHING, ADZE, NOTHING, BAG}, _
{PAULDRON, NOTHING, AXE, NOTHING, OILLAMP}, _
{PAULDRON, NOTHING, AXE, NOTHING, BAG}, _
{LEATHER, NOTHING, AXE, NOTHING, OILLAMP}, _
{LEATHER, NOTHING, AXE, NOTHING, BAG}, _
{LEATHER, NOTHING, SWORD, NOTHING, OILLAMP}, _
{SCALE, NOTHING, SWORD, NOTHING, BAG}, _
{SCALE, NOTHING, SWORD, NOTHING, OILLAMP}, _
{SCALE, NOTHING, SWORD, NOTHING, BAG}}
dim gameover as byte = 0
dim map(1 to MHEIGHT, 1 to MWIDTH) as ubyte
sub fillMap(tile as ubyte)
dim x, y as ubyte
for y = 1 to MHEIGHT
for x = 1 to MWIDTH
map(y, x) = tile
next x
next y
end sub
sub furnishRoom(x1 as ubyte, y1 as ubyte, x2 as ubyte, y2 as ubyte)
dim w, h, x, y as ubyte
w = x2 - x1 + 1
h = y2 - y1 + 1
if w = 3 and h = 3 then
if rnd() < 0.5 then
map(y1 + 1, x1 + 1) = STAR
else
map(y1 + 1, x1 + 1) = ANDSIGN
end if
elseif w = 3 then
for y = y1 + 1 to y2 - 1 step 2
map(y, x1 + 1) = VBAR
next y
if h mod 2 = 0 then
if rnd() < 0.5 then
map(y2, x2 - 1) = STAR
else
map(y2, x2 - 1) = ANDSIGN
end if
end if
elseif h = 3 then
for x = x1 + 1 to x2 - 1 step 2
map(y1 + 1, x) = VBAR
next x
if w mod 2 = 0 then
if rnd() < 0.5 then
map(y2 - 1, x2) = STAR
else
map(y2 - 1, x2) = ANDSIGN
end if
end if
elseif w = 4 or h = 4 then
for y = y1 + 1 to y2 - 1
for x = x1 + 1 to x2 - 1
map(y, x) = TILDA
next x
next y
'elseif w = 5 and h = 5 then
' map(y1 + 1, x1 + 1) = VBAR
' map(y1 + 1, x2 - 1) = VBAR
' map(y2 - 1, x1 + 1) = VBAR
' map(y2 - 1, x2 - 1) = VBAR
elseif w = 5 then
for y = y1 + 1 to y2 - 1 step 2
map(y, x1 + 1) = VBAR
map(y, x2 - 1) = VBAR
next y
if h mod 2 = 0 then
if rnd() < 0.5 then
map(y2, x2 - 2) = STAR
else
map(y2, x2 - 2) = ANDSIGN
end if
end if
elseif h = 5 then
for x = x1 + 1 to x2 - 1 step 2
map(y1 + 1, x) = VBAR
map(y2 - 1, x) = VBAR
next x
if w mod 2 = 0 then
if rnd() < 0.5 then
map(y2 - 2, x2) = STAR
else
map(y2 - 2, x2) = ANDSIGN
end if
end if
elseif w = 7 and h = 7 then
for y = y1 + 1 to y2 - 1 step 2
for x = x1 + 1 to x2 - 1 step 2
map(y, x) = VBAR
next x
next y
if rnd() < 0.5 then
map(y1 + 3, x1 + 3) = STAR
else
map(y1 + 3, x1 + 3) = ANDSIGN
end if
elseif w > 2 and h > 2 then
for y = y1 to y2
map(y, x1) = COMMA
map(y, x2) = COMMA
next y
for x = x1 to x2
map(y1, x) = COMMA
map(y2, x) = COMMA
next x
if w = 6 and h = 6 then
furnishRoom(x1 + 1, y1 + 1, x2 - 1, y2 - 1)
elseif w = 9 and h = 9 then
furnishRoom(x1 + 1, y1 + 1, x2 - 1, y2 - 1)
end if
end if
end sub
dim cellwidth, cellheight as ubyte
function subdivideWide(x1 as ubyte, y1 as ubyte, x2 as ubyte, y2 as ubyte) _
as ubyte
dim w, h, x, y, wall1, wall2, doory as ubyte
w = x2 - x1 + 1
h = y2 - y1 + 1
' You have to check both dimensions
' or you'll get oddly skewed levels.
if w < cellwidth or h < cellheight or w = h then
furnishRoom(x1, y1, x2, y2)
return 0
end if
if w = 3 then
x = x1 + 1
else
x = x1 + 1 + int(rnd() * (w - 2))
end if
for y = y1 to y2
map(y, x) = HASH
next y
wall1 = subdivideHigh(x1, y1, x - 1, y2)
wall2 = subdivideHigh(x + 1, y1, x2, y2)
' Make door.
do
doory = y1 + int(rnd() * h)
loop while doory = wall1 or doory = wall2
map(doory, x) = DOT
' Not superfluous!
map(doory, x - 1) = DOT
map(doory, x + 1) = DOT
return x
end function
function subdivideHigh(x1 as ubyte, y1 as ubyte, x2 as ubyte, y2 as ubyte) _
as ubyte
dim w, h, x, y, wall1, wall2, doorx as ubyte
w = x2 - x1 + 1
h = y2 - y1 + 1
' You have to check both dimensions
' or you'll get oddly skewed levels.
if w < cellwidth or h < cellheight or w = h then
furnishRoom(x1, y1, x2, y2)
return 0
end if
if h = 3 then
y = y1 + 1
else
y = y1 + 1 + int(rnd() * (h - 2))
end if
for x = x1 to x2
map(y, x) = HASH
next x
wall1 = subdivideWide(x1, y1, x2, y - 1)
wall2 = subdivideWide(x1, y + 1, x2, y2)
' Make door.
do
doorx = x1 + int(rnd() * w)
loop while doorx = wall1 or doorx = wall2
map(y, doorx) = DOT
' Not superfluous!
map(y - 1, doorx) = DOT
map(y + 1, doorx) = DOT
return y
end function
sub generatePalaceFloor(levelNum as ubyte)
dim x, y, r as ubyte
fillMap(DOT)
for x = 1 to MWIDTH
map(1, x) = HASH
map(MHEIGHT, x) = HASH
next x
for y = 1 to MHEIGHT
map(y, 1) = HASH
map(y, MWIDTH) = HASH
next y
r = int(rnd() * 5)
cellwidth = levelCellSize(r, 0)
cellheight = levelCellSize(r, 1)
subdivideWide(2, 2, MWIDTH - 1, MHEIGHT - 1)
if levelNum mod 2 = 1 then
map(MHEIGHT - 1, MWIDTH - 1) = GT
else
map(MHEIGHT - 1, 2) = GT
end if
end sub
' Coords are x, y for any mob from 0 to MAXMOBS
' Mob 0 (zero) is always the player.
dim mobCoords(0 to MAXMOBS, 0 to 1) as ubyte
dim mobs(0 to MAXMOBS) as ubyte
dim mobLife(0 to MAXMOBS) as byte ' It can get negative from a hit!
dim mobActions(0 to MAXMOBS) as byte
dim heroDepth as ubyte = 0
dim heroMaxLife as ubyte
dim heroMaxActions as ubyte = APREFRESH
dim heroDamageBonus as ubyte = 0
heroMaxLife = 2 * mobDice(TAUR)
dim heroWeapon as ubyte = NOTHING
dim heroArmor as ubyte = NOTHING
dim poisonTimer as ubyte = 0
dim lightTimer as ubyte = 0
dim inventory(1 to ITEMTYPES) as ubyte
sub populateLevel(levelNum as ubyte)
dim x, y, mobNum as ubyte
for y = 2 to MHEIGHT - 1
mobNum = y
mobs(mobNum) = levelMobs(levelNum, int(rnd() * 5))
mobLife(mobNum) = 2 * mobDice(mobs(mobNum))
do
x = int(rnd() * (MWIDTH - 2)) + 1
loop until canWalk(map(y, x))
mobCoords(mobNum, 0) = x
mobCoords(mobNum, 1) = y
mobActions(mobNum) = APREFRESH
next y
end sub
function getMobAt(x as ubyte, y as ubyte) as integer
dim i as ubyte
for i = 0 to MAXMOBS
if mobs(i) then
if mobCoords(i, 0) = x then
if mobCoords(i, 1) = y then
return i
end if
end if
end if
next i
return -1
end function
sub interactWith(mobNum as ubyte)
print at 22, 0; ink 7; "Why, hello there."
end sub
function diceRoll(dice as ubyte, size as ubyte) as ubyte
dim roll as ubyte = 0
dim i as ubyte
for i = 1 to dice
roll = roll + int(rnd() * size) + 1
next i
return roll
end function
function damageBonus(mobNum as ubyte) as ubyte
if mobNum = 0 then
return heroDamageBonus
else
return 0
end if
end function
function attackBonus(mobNum as ubyte) as ubyte
if mobNum = 0 then
return itemAttack(heroWeapon)
else
return int(heroDepth / 2)
end if
end function
function defenseBonus(mobNum as ubyte) as ubyte
if mobNum = 0 then
return itemDefense(heroArmor)
else
return int(heroDepth / 2)
end if
end function
sub handleAttackByOn(attacker as ubyte, defender as ubyte)
dim att, def, attRoll, defRoll as ubyte
dim margin as byte
att = mobs(attacker)
def = mobs(defender)
attRoll = diceRoll(2, mobDice(att)) + attackBonus(attacker)
defRoll = diceRoll(2, mobDice(def)) + defenseBonus(defender)
margin = attRoll - defRoll
if attacker = 0 or defender = 0 then
blankLine(22): ink 7: print at 22, 0;
end if
if margin > 0 then
margin = margin + damageBonus(attacker) - damageBonus(defender)
if margin < 0 then margin = 0: end if
mobLife(defender) = mobLife(defender) - margin
if mobLife(defender) <= 0 then
handleMobDrop(defender)
mobs(defender) = NOBODY
if attacker = 0 then
print "You kill the "; mobName(def); "!"
elseif defender = 0 then
print "The "; mobName(att); " kills you!!"
'printHeroStats()
playDeath()
gameover = 1
end if
else
if attacker = 0 then
print "You strike the "; mobName(def); "."
elseif defender = 0 then
if mobPoison(att) > 0 then
poisonTimer = poisonTimer _
+ int(rnd()*mobPoison(att))+1
end if
print "The "; mobName(att); " wounds you. Oof."
'printHeroStats()
end if
end if
elseif margin = 0 then
if attacker = 0 then
print "You graze the "; mobName(def); "."
elseif defender = 0 then
if mobPoison(att) > 0 then
poisonTimer = poisonTimer _
+ int(rnd() * mobPoison(att)) + 1
'printHeroStats()
end if
print "The "; mobName(att); " grazes you. Whee."
end if
else
if attacker = 0 then
print "You miss the "; mobName(def); "."
elseif defender = 0 then
print "The "; mobName(att); " misses you. Ha."
end if
end if
if attacker = 0 or defender = 0 then
pause 10 ' Give player at least a chance to read the message.
end if
end sub
sub moveMob(mobNum as ubyte, dx as byte, dy as byte)
dim newx, newy as ubyte
dim otherMob as integer
newx = mobCoords(mobNum, 0) + dx
newy = mobCoords(mobNum, 1) + dy
if newx < 1 or newx > MWIDTH or newy < 1 or newy > MHEIGHT then
return
elseif not canWalk(map(newy, newx)) then
return
end if
otherMob = getMobAt(newx, newy)
if otherMob > -1 then
if mobs(mobNum) <> mobs(otherMob) then ' Not the same species.
handleAttackByOn(mobNum, otherMob)
end if
else
mobCoords(mobNum, 0) = newx
mobCoords(mobNum, 1) = newy
end if
end sub
sub moveHero(dx as byte, dy as byte)
dim newx, newy, hostility as ubyte
dim otherMob as integer
newx = mobCoords(0, 0) + dx
newy = mobCoords(0, 1) + dy
blankLine(22)
if newx < 1 or newx > MWIDTH or newy < 1 or newy > MHEIGHT then
print at 22, 0; ink 7; "You have nowhere else to go."
return
elseif not canWalk(map(newy, newx)) then
ink 7
print at 22, 0; "The way is barred by a ";
print tileName(map(newy, newx)); "."
return
end if
otherMob = getMobAt(newx, newy)
if otherMob > 0 then
hostility = mobHostility(mobs(otherMob))
if hostility > 0 then
handleAttackByOn(0, otherMob)
else
interactWith(otherMob)
end if
else
mobCoords(0, 0) = newx
mobCoords(0, 1) = newy
end if
end sub
sub moveHeroDown()
blankLine(22)
if map(mobCoords(0, 1), mobCoords(0, 0)) = GT then
heroDepth = heroDepth + 1
blankViewport()
print at 10, 2; ink 7; " You stumble in darkness, "
print at 11, 2; ink 7; "stairs crumbling behind you!"
if heroDepth <= MAXLEVEL then
generatePalaceFloor(heroDepth)
mobLife(0) = mobLife(0) + 1
populateLevel(heroDepth)
createItems(heroDepth)
'pause 25
levelUp()
blankViewport()
clearSeen()
printLevelNum()
'printHeroStats()
if heroDepth mod 2 = 1 then
mobCoords(0, 0) = 2
else
mobCoords(0, 0) = MWIDTH - 1
end if
mobCoords(0, 1) = 2
else
blankViewport()
playEnding()
gameover = 1
end if
else
print at 22, 0; ink 7; "There's no way down from here."
end if
end sub
sub moveHeroUp()
blankLine(22)
print at 22, 0; ink 7; "There's no going back."
end sub
sub levelUp()
dim k as string
dim c as ubyte
blankViewport()
ink 7
print at 5, 2; "You feel:"
print at 8, 2; "1) stronger"
print at 10, 2; "2) sturdier"
print at 12, 2; "3) faster"
print at 15, 2; "0) whatever"
pause 0
k = inkey$()
if k = "1" then
heroDamageBonus = heroDamageBonus + 1
elseif k = "2" then
heroMaxLife = heroMaxLife + 1
elseif k = "3" then
heroMaxActions = heroMaxActions + 1
else
c = int(rnd() * 3)
if c = 1 then
heroDamageBonus = heroDamageBonus + 1
elseif c = 2 then
heroMaxLife = heroMaxLife + 1
elseif c = 3 then
heroMaxActions = heroMaxActions + 1
end if
end if
end sub
sub mobWander(mobNum as ubyte)
dim rndir as ubyte
rndir = int(rnd() * 4)
if rndir = 0 then
moveMob(mobNum, 0, -1)
elseif rndir = 1 then
moveMob(mobNum, 0, 1)
elseif rndir = 2 then
moveMob(mobNum, 0, -1)
elseif rndir = 3 then
moveMob(mobNum, 0, 1)
end if
end sub
sub mobHuntHero(mobNum as ubyte)
dim myx, myy, herox, heroy as byte
myx = mobCoords(mobNum, 0)
myy = mobCoords(mobNum, 1)
herox = mobCoords(0, 0)
heroy = mobCoords(0, 1)
if myx = herox then
if myy > heroy then
moveMob(mobNum, 0, -1)
else
moveMob(mobNum, 0, 1)
end if
elseif myy = heroy then
if myx > herox then
moveMob(mobNum, -1, 0)
else
moveMob(mobNum, 1, 0)
end if
else
mobWander(mobNum)
end if
end sub
sub mobRunFromHero(mobNum as ubyte)
dim myx, myy, herox, heroy as byte
myx = mobCoords(mobNum, 0)
myy = mobCoords(mobNum, 1)
herox = mobCoords(0, 0)
heroy = mobCoords(0, 1)
if myx = herox then
if myy < heroy then
moveMob(mobNum, 0, -1)
else
moveMob(mobNum, 0, 1)
end if
elseif myy = heroy then
if myx < herox then
moveMob(mobNum, -1, 0)
else
moveMob(mobNum, 1, 0)
end if
else
mobWander(mobNum)
end if
end sub
sub processMobs()
dim i as ubyte
for i = 1 to MAXMOBS ' Skip the player!
if mobs(i) then
if mobActions(i) > 0 then
mobActions(i) = _
mobActions(i) - mobDice(mobs(i))
if mobHostility(mobs(i)) < 2 then
if lightTimer < 1 then
mobWander(i)
else
mobRunFromHero(i)
end if
else
if lightTimer < 1 then
mobHuntHero(i)
else
mobWander(i)
end if
end if
else
mobActions(i) = mobActions(i) + APREFRESH
end if
end if
next i
end sub
sub processPoison()
if poisonTimer > 0 then
mobLife(0) = mobLife(0) - 1
poisonTimer = poisonTimer - 1
'printHeroStats()
if mobLife(0) < 1 then
blankLine(22)
print at 22, 0; "You succumb to the poison!!"
playDeath()
gameover = 1
end if
end if
end sub
sub processLight()
if lightTimer > 0 then
lightTimer = lightTimer - 1
if lightTimer < 1 then
blankLine(22)
print at 22, 0; ink 7; "Your light runs out."
end if
end if
end sub
dim itemCoords(1 to MAXITEMS, 0 to 1) as ubyte
dim items(1 to MAXITEMS) as ubyte
dim itemHere as ubyte = 0
sub createItems(levelNum as ubyte)
dim x, y as ubyte
items(1) = NOTHING
for y = 2 to MHEIGHT - 1
items(y) = levelItems(levelNum, int(rnd() * 5))
if items(y) <> NOTHING then
do
x = int(rnd() * (MWIDTH - 2)) + 1
loop until canWalk(map(y, x))
itemCoords(y, 0) = x
itemCoords(y, 1) = y
end if
next y
items(MHEIGHT) = NOTHING
end sub
function getFreeItemSlot() as ubyte
dim i as ubyte = 0
for i = 1 to MHEIGHT
if items(i) = 0
return i
end if
next i
return i
end function
sub handleMobDrop(mobNum)
dim item as ubyte
item = getFreeItemSlot()
if item > 0 then
items(item) = mobDrops(mobs(mobNum), int(rnd() * 3))
itemCoords(item, 0) = mobCoords(mobNum, 0)
itemCoords(item, 1) = mobCoords(mobNum, 1)
end if
end sub
sub legend()
dim i, mob as ubyte
blankLine(22)
print at 22, 0;
for i = 0 to 2
mob = levelMobs(heroDepth, i)
print ink mobInk(mob); mobChar(mob); " ";
print ink 7; mobName(mob); " ";
next i
end sub
function openItem(item as ubyte) as ubyte
dim found as ubyte
blankLine(22)