please find attached the latest version of the code.
i have made it so that bag entries (B) and exits (X) will not be erased upon use. now, placing a bag will make entries and exits are permanent each play through.
currently the game is about 8 KB, and comes in at about 250 lines.
ideas:
- record game play events and allow an ‘infinite’ undo button, for the purpose of correcting mistakes
- need to explore better colours
- fix the draw speed problem (perhaps put the play field right at the bottom of the screen)
- now that the core functionality of the game is working properly, something inside me thinks I should add more items, or at least tinker with the keys/doors, loot/goblins pairing, which i feel could be more creative
- a 2D play field seems possible
0 rem bagquest
1 rem public domain licence
5 rem constants
9 rem character colour codes
10 white = 5
11 red = 28
12 yellow = 158
13 blue = 154
14 green = 30
15 lightred = 150
16 purple = 156
17 dark = 151
19 brown = 129
rem border and bg colour codes
rem
rem 0 - black
rem 1 - white
rem 2 - red
rem 3 - cyan
rem 4 - purple
rem 5 - green
rem 6 - blue
rem 7 - yellow
rem 8 - orange
rem 9 - brown
rem 10 - light red
rem 11 - dark grey
rem 12 - grey
rem 13 - light green
rem 14 - light blue
rem 15 - light grey
99 rem initialisation
100 print chr$(147)
110 poke 53280,7:rem set border yellow
120 poke 53281,14:rem set bg light blue
130 dim w(40,10):rem world array
140 dim b(10):rem bag parent connection
150 dim bx(10):rem bag entry positions
160 dim by(10):rem bag exit positions
170 cb = 1:rem start in bag 1 (main world)
180 p = int(rnd(1)*40)+1:rem player position on init
190 hb=10:rem start with 10 bags (??)
200 bf=1
210 l=0:rem loot
220 k=0:rem keys
230 mw=0:rem magic wands
240 m=0:rem treasure maps
499 rem initialise bags
500 print chr$(white);"initialising bags..."
510 for i=1 to 10
520 for j=1 to 40
530 w(j,i)=0
540 next j
550 b(i)=0
560 bx(i)=0
570 by(i)=0
580 next i
590 print "bags initialised - ok.":gosub 9000
600 w(p,1)=1:rem place player in bag 1
610 rem add items to bags, 10 items each
620 print "generating item positions..."
625 print "generating bag..."
630 for i=1 to 10:rem 10 bags
635 print tab(10);i
640 for j=1 to 10:rem 10 items
650 q=int(rnd(1)*40)+1
660 if w(q,i)=0 then w(q,i)=int(rnd(1)*6)+4:goto 680
670 goto 650
680 next j
690 next i
700 print "world initialised - ok.":gosub 9000
rem 0 = . empty space
rem 1 = @ player
rem 2 = B placed bag
rem 3 = X bag exit
rem 4 = L loot
rem 5 = K key
rem 6 = G goblin
rem 7 = D door
rem 8 = W magic wand
rem 9 = M treasure map
999 rem draw current bag
1000 print chr$(147)
1010 print tab(10);chr$(yellow);"*** bagquest ***":print
1015 print chr$(white);"b:";hb;" bf:";bf;" l:";l;" k:";k;" wd:";mw;" m:";m
1017 print chr$(white);"current bag:";cb;" @:";p
1020 print chr$(yellow);"--------========================--------"
1030 for i=1 to 40
1040 if w(i,cb)=0 then print chr$(dark);".";:goto 1500
1050 if w(i,cb)=1 then print chr$(white);"@";:goto 1500
1060 if w(i,cb)=2 then print chr$(lightred);"b";:goto 1500
1070 if w(i,cb)=3 then print chr$(purple);"x";:goto 1500
1080 if w(i,cb)=4 then print chr$(yellow);"l";:goto 1500
1090 if w(i,cb)=5 then print chr$(red);"k";:goto 1500
1100 if w(i,cb)=6 then print chr$(green);"g";:goto 1500
1110 if w(i,cb)=7 then print chr$(brown);"d";:goto 1500
1120 if w(i,cb)=8 then print chr$(red);"w";:goto 1500
1130 if w(i,cb)=9 then print chr$(brown);"m";:goto 1500
1500 next i
1510 print
1999 rem status display
2000 print chr$(yellow);"--------========================--------"
2010 print chr$(white);"a/d=move. b=place bag. x=use exit."
2020 print chr$(white);"w=wand. m=map. i=info. q=quit."
2030 rem see line 1017
2040 print
2050 print chr$(yellow);"--------========================--------"
2060 if cb > 1 then print chr$(white);"find exit (x) to return."
2999 rem input
3000 get a$:if a$="" then 3000
3010 if a$="a" and p>1 then op=p:p=p-1:gosub 3500:gosub 4000:goto 1000
3020 if a$="d" and p<40 then op=p:p=p+1:gosub 3500:gosub 4000:goto 1000
3030 if a$="i" then gosub 8000
3040 if a$="b" and hb>0 then gosub 5000
3050 rem if a$="x" then gosub 7000
3060 if a$="q" then print "game over":end
3070 if a$="w" and mw>0 then gosub 10000
3080 if a$="m" and m>0 then gosub 11000
3090 goto 1000
3499 rem move player such that bag entry and exits not erased
3500 if w(op,cb)<>2 and w(op,cb)<>3 then w(op,cb)=0
3510 if w(p,cb)=0 then w(p,cb)=1
3520 return
3999 rem collisions
4000 if w(p,cb)=0 then w(p,cb)=1:return
4010 if w(p,cb)=2 then gosub 6000:return
4020 if w(p,cb)=3 then gosub 7000:return
4030 if w(p,cb)=4 then l=l+1:w(p,cb)=1:return
4040 if w(p,cb)=5 then k=k+1:w(p,cb)=1:return
4050 if w(p,cb)=6 then print chr$(green);"a goblin!":gosub 9100:return
4060 if w(p,cb)=7 then gosub 9200:return
4070 if w(p,cb)=8 then mw=mw+1:w(p,cb)=1:print "wand!":gosub 9000:return
4080 if w(p,cb)=9 then m=m+1:w(p,cb)=1:print "map!":gosub 9000:return
4090 return
4999 rem place a bag
5000 tp=0:if hb<=0 then print "you have no bags.":gosub 9000:return
5010 rem check left and right for empty space
5020 if p>1 and w(p-1,cb)=0 then tp=p-1:goto 5050
5030 if p<40 and w(p+1,cb)=0 then tp=p+1:goto 5050
5040 print "no empty space adjacent.":gosub 9000:return
5050 rem find empty bag slot
5060 for i=2 to 10
5070 if i=cb then goto 5090
5080 if b(i)=0 then goto 5120
5090 next i
5100 rem fall into here
5110 print "too many bags already.":return
5120 rem record where this bag leads
5130 b(i)=cb
5132 print "placed bag i=";i;" parent=";cb;" entry";tp
5133 gosub 9000
5140 bx(i)=tp
5150 by(i)=cb
5160 rem place exit in new bag
5170 be=int(rnd(1)*40)+1
5180 if w(be,i)<>0 then goto 5170:rem this could be an infinite loop uwu
5190 rem this line blank intentionally
5200 w(be,i)=3
5210 rem place entry in current bag
5220 w(tp,cb)=2
5230 hb=hb-1
5240 bf=bf+1
5250 print "bag placed at position";tp
5260 gosub 9000
5270 return
5999 rem enter placed bag
6000 for i=1 to 10
6010 if i=cb then goto 6030
6020 if bx(i)=p and by(i)=cb then goto 6050
6030 next i
6040 print "error: broken bag link.":return
6050 rem switch to the new bag
6060 rem w(p,cb)=0
6070 cb=i
6080 rem find empty spot in existing bag
6090 p=int(rnd(1)*40)+1
6100 if w(p,cb)<>0 then goto 6090
6110 w(p,cb)=1
6120 print "you enter a new bag..."
6130 gosub 9000
6140 return
6999 rem use bag exit
7000 if cb=1 then print "cannot leave main world...":gosub 9000:return
7010 pr=b(cb)
7020 if pr=0 then print "error: no parent world.":gosub 9000:return
7030 rem ep (entry point)
7040 ep=bx(cb)
7050 rem find empty space next to bag entry
7060 if ep>1 and w(ep-1,pr)=0 then tp=ep-1:goto 7100
7070 if ep<40 and w(ep+1,pr)=0 then tp=ep+1:goto 7100
7080 rem fallback: place player directly on entry (both sides blocked)
7090 tp=ep
7100 rem w(p,cb)=0 preserve exit tile
7110 p=tp
7120 cb=pr
7130 w(p,cb)=1
7140 print "you return through the exit..."
7150 gosub 9000
7160 return
7999 rem info screen
8000 print chr$(147)
8010 print tab(10);chr$(yellow);"=== bagquest ==="
8020 print
8030 print chr$(white);"you have";hb;" bags."
8040 print "bags visited:";bf
8050 print "current bag:";cb
8060 print "current position:";p
8070 print
8080 print chr$(yellow);"loot:";l
8090 print "keys:";k
8100 print "wands:";mw
8110 print "treasure maps:";m
8120 print
8130 print chr$(white);
8140 gosub 9000
8150 return
8999 rem delay
9000 for t=1 to 1000:next t
9010 return
9099 rem bribing the goblins
9100 if l>0 then l=l-1:print "goblin bribed.":gosub 9000:w(p,cb)=1:return
9110 print "goblin requires bribe!"
9120 p=op
9130 gosub 9000
9140 return
9199 rem doors need keys
9200 if k>0 then k=k-1:print "door unlocked.":gosub 9000:return
9210 print "door needs a key...":gosub 9000:p=op:w(p,cb)=1:return
9999 rem magic wand
10000 tb=int(rnd(1)*10)+1
10010 if tb=cb then goto 10000
10020 tp=int(rnd(1)*40)+1
10030 if w(tp,tb)<>0 then goto 10020
10040 rem w(p,cb)=0
10050 cb=tb
10060 p=tp
10070 w(p,cb)=1
10080 mw=mw-1
10090 print "wand teleports you to bag";cb;"at position";p
10100 gosub 9000
10110 return
10999 rem treasure map
11000 print "which bag? (1-10, 0=cancel)"
11010 input tb
11020 if tb=0 then print "map folded.":gosub 9000:return
11030 if tb<1 or tb>10 then print "invalid selection.":gosub 9000:return
11040 if tb=cb then print "already in bag...":gosub 9000:return
11050 w(p,cb)=0
11060 cb=tb
11070 tp=int(rnd(1)*40)+1
11080 if w(tp,cb)<>0 then goto 11070
11090 p=tp
11100 w(p,cb)=1
11110 print "map takes you to bag";cb;"at position";p
11120 gosub 9000
11130 return