Hi! I'm here again :D
Now with a simple Boulder Dash engine for didactic purpose, with large possibility to optimize it :)
Happy coding. ;)
Source Code on GitHub
https://github.com/FabrizioRadica/boulder-dash-engine-cpc
You're creating some really interesting things in locomotive basic!
That was me that posted some speed-ups to the youtube video (I'm poppichicken on youtube) - I really enjoy optimising code. 8)
ohh thank's you!!
I'm glad you like it :)
Quote from: ervin on 13:49, 12 October 18You're creating some really interesting things in locomotive basic!
That was me that posted some speed-ups to the youtube video (I'm poppichicken on youtube) - I really enjoy optimising code. 8)
Some more speed-ups, this time using an array of strings for the map, instead of a 2-dimensional array.
1 'Boulder Dash Engine - SLOW VERSION but most accurate.
2 '2018 - Fabrizio Radica
10 mode 1:pen 5:mx%=20:my%=11:DIM map$(my%):movx%=2:movy%=3:XOROn$=CHR$(23)+CHR$(1):XOROff$=CHR$(23)+CHR$(0)
100 'Read Map
110 FOR y%=1 TO my%
120 READ a$:map$(y%)=a$
121 FOR x%=1 TO mx%
125 LOCATE x%,y%
130 if mid$(map$(y%),x%,1)="1" then print CHR$(143):goto 145
135 if mid$(map$(y%),x%,1)="2" then print CHR$(207):goto 145
140 if mid$(map$(y%),x%,1)="3" then print CHR$(231)
145 NEXT x%
150 NEXT y%
160 locate 1,16:Print "Boulder Dash Engine"
165 Locate 1,17:print "Fabrizio Radica - www.retroacademy.it"
180 mid$(map$(movy%+1),movx%,1)="0":locate movx%,movy%:?chr$(249) 'Start player position
400 while 1 'Main Loop
450 gosub 2000 'Call player movements
660 FOR y%=1 TO my%-1
665 m$=map$(y%)
670 x%=1
675 'Check Rock collision and redraw the array map.
720 while x%<>0
730 x%=instr(x%,m$,"3")
735 if x%<>0 then gosub 5000:x%=x%+1
740 wend
750 next
800 wend
1000 'Map Data
1010 DATA "11111111111111111111"
1020 DATA "12223222222222222221"
1030 DATA "12333222233222222221"
1040 DATA "12222222223333222221"
1050 DATA "12222222222223222221"
1060 DATA "12333322222233332221"
1070 DATA "12222222223332222221"
1080 DATA "12222223222222233221"
1090 DATA "12222333222222222221"
1100 DATA "12222222222222222221"
1110 DATA "11111111111111111111"
1999 'Player Movements and collisions check.
2000 IF NOT(INKEY(1)) then gosub 6000
2100 IF NOT(INKEY(8)) then gosub 6100
2200 IF NOT(INKEY(0)) then gosub 6200
2300 IF NOT(INKEY(2)) then gosub 6300
2400 return
3000 sound 1,900,1,15,1:locate movx%,movy%:pen 6:print CHR$(249):return 'Player
5000 if mid$(map$(y%+1),x%,1)="0" then locate x%,y%:?chr$(32);:mid$(map$(y%),x%,1)="0":ry%=ry%+1:mry%=y%+ry%:locate x%,mry%:PEN 5:?chr$(231);:mid$(map$(mry%),x%,1)="3":ry%=0
5001 return
6000 if NOT(mid$(map$(movy%),movx%+1,1)="1") AND NOT(mid$(map$(movy%),movx%+1,1)="3") then locate movx%,movy%:print chr$(32);:mid$(map$(movy%),movx%,1)="0":movx%=movx%+1:gosub 3000
6001 return
6100 if NOT(mid$(map$(movy%),movx%-1,1)="1") AND NOT(mid$(map$(movy%),movx%-1,1)="3") then locate movx%,movy%:print chr$(32);:mid$(map$(movy%),movx%,1)="0":movx%=movx%-1:gosub 3000
6101 return
6200 if NOT(mid$(map$(movy%-1),movx%,1)="1") AND NOT(mid$(map$(movy%-1),movx%,1)="3") THEN locate movx%,movy%:print chr$(32);:mid$(map$(movy%),movx%,1)="0":movy%=movy%-1:gosub 3000
6201 return
6300 if NOT(mid$(map$(movy%+1),movx%,1)="1") AND NOT(mid$(map$(movy%+1),movx%,1)="3") THEN locate movx%,movy%:print chr$(32);:mid$(map$(movy%),movx%,1)="0":movy%=movy%+1:gosub 3000
6301 return
Some small adjustments for a bit more speed.
1 'Boulder Dash Engine - SLOW VERSION but most accurate.
2 '2018 - Fabrizio Radica
10 mode 1:pen 5:mx%=20:my%=11:DIM map$(my%):movx%=2:movy%=3:XOROn$=CHR$(23)+CHR$(1):XOROff$=CHR$(23)+CHR$(0)
100 'Read Map
110 FOR y%=1 TO my%
120 READ a$:map$(y%)=a$
121 FOR x%=1 TO mx%
125 LOCATE x%,y%
130 if mid$(map$(y%),x%,1)="1" then print CHR$(143):goto 145
135 if mid$(map$(y%),x%,1)="2" then print CHR$(207):goto 145
140 if mid$(map$(y%),x%,1)="3" then print CHR$(231)
145 NEXT x%
150 NEXT y%
160 locate 1,16:Print "Boulder Dash Engine"
165 Locate 1,17:print "Fabrizio Radica - www.retroacademy.it"
180 mid$(map$(movy%+1),movx%,1)="0":locate movx%,movy%:?chr$(249) 'Start player position
400 while 1 'Main Loop
450 gosub 2000 'Call player movements
660 FOR y%=2 TO my%-1
665 m$=map$(y%)
670 x%=2
675 'Check Rock collision and redraw the array map.
720 while x%<>0
730 x%=instr(x%,m$,"3")
735 if x%<>0 then gosub 5000:x%=x%+1
740 wend
750 next
800 wend
1000 'Map Data
1010 DATA "11111111111111111111"
1020 DATA "12223222222222222221"
1030 DATA "12333222233222222221"
1040 DATA "12222222223333222221"
1050 DATA "12222222222223222221"
1060 DATA "12333322222233332221"
1070 DATA "12222222223332222221"
1080 DATA "12222223222222233221"
1090 DATA "12222333222222222221"
1100 DATA "12222222222222222221"
1110 DATA "11111111111111111111"
1999 'Player Movements and collisions check.
2000 IF NOT(INKEY(1)) then gosub 6000
2100 IF NOT(INKEY(8)) then gosub 6100
2200 IF NOT(INKEY(0)) then gosub 6200
2300 IF NOT(INKEY(2)) then gosub 6300
2400 return
3000 sound 1,900,1,15,1:locate movx%,movy%:pen 6:print CHR$(249):return 'Player
5000 if mid$(map$(y%+1),x%,1)="0" then locate x%,y%:?chr$(32):mid$(map$(y%),x%,1)="0":ry%=ry%+1:mry%=y%+ry%:locate x%,mry%:PEN 5:?chr$(231):mid$(map$(mry%),x%,1)="3":ry%=0
5001 return
6000 if NOT(mid$(map$(movy%),movx%+1,1)="1") AND NOT(mid$(map$(movy%),movx%+1,1)="3") then locate movx%,movy%:print chr$(32):mid$(map$(movy%),movx%,1)="0":movx%=movx%+1:gosub 3000
6001 return
6100 if NOT(mid$(map$(movy%),movx%-1,1)="1") AND NOT(mid$(map$(movy%),movx%-1,1)="3") then locate movx%,movy%:print chr$(32):mid$(map$(movy%),movx%,1)="0":movx%=movx%-1:gosub 3000
6101 return
6200 if NOT(mid$(map$(movy%-1),movx%,1)="1") AND NOT(mid$(map$(movy%-1),movx%,1)="3") THEN locate movx%,movy%:print chr$(32):mid$(map$(movy%),movx%,1)="0":movy%=movy%-1:gosub 3000
6201 return
6300 if NOT(mid$(map$(movy%+1),movx%,1)="1") AND NOT(mid$(map$(movy%+1),movx%,1)="3") THEN locate movx%,movy%:print chr$(32):mid$(map$(movy%),movx%,1)="0":movy%=movy%+1:gosub 3000
6301 return
great!i like much more the DATA with this method, more compressed.it remind me dc.b in ASM :)
it's really faster than first method?
Tnx mate :)
Quote from: ervin on 15:27, 12 October 18Some small adjustments for a bit more speed.
1 'Boulder Dash Engine - SLOW VERSION but most accurate.
2 '2018 - Fabrizio Radica
10 mode 1:pen 5:mx%=20:my%=11:DIM map$(my%):movx%=2:movy%=3:XOROn$=CHR$(23)+CHR$(1):XOROff$=CHR$(23)+CHR$(0)
100 'Read Map
110 FOR y%=1 TO my%
120 READ a$:map$(y%)=a$
121 FOR x%=1 TO mx%
125 LOCATE x%,y%
130 if mid$(map$(y%),x%,1)="1" then print CHR$(143):goto 145
135 if mid$(map$(y%),x%,1)="2" then print CHR$(207):goto 145
140 if mid$(map$(y%),x%,1)="3" then print CHR$(231)
145 NEXT x%
150 NEXT y%
160 locate 1,16:Print "Boulder Dash Engine"
165 Locate 1,17:print "Fabrizio Radica - www.retroacademy.it"
180 mid$(map$(movy%+1),movx%,1)="0":locate movx%,movy%:?chr$(249) 'Start player position
400 while 1 'Main Loop
450 gosub 2000 'Call player movements
660 FOR y%=2 TO my%-1
665 m$=map$(y%)
670 x%=2
675 'Check Rock collision and redraw the array map.
720 while x%<>0
730 x%=instr(x%,m$,"3")
735 if x%<>0 then gosub 5000:x%=x%+1
740 wend
750 next
800 wend
1000 'Map Data
1010 DATA "11111111111111111111"
1020 DATA "12223222222222222221"
1030 DATA "12333222233222222221"
1040 DATA "12222222223333222221"
1050 DATA "12222222222223222221"
1060 DATA "12333322222233332221"
1070 DATA "12222222223332222221"
1080 DATA "12222223222222233221"
1090 DATA "12222333222222222221"
1100 DATA "12222222222222222221"
1110 DATA "11111111111111111111"
1999 'Player Movements and collisions check.
2000 IF NOT(INKEY(1)) then gosub 6000
2100 IF NOT(INKEY() then gosub 6100
2200 IF NOT(INKEY(0)) then gosub 6200
2300 IF NOT(INKEY(2)) then gosub 6300
2400 return
3000 sound 1,900,1,15,1:locate movx%,movy%:pen 6:print CHR$(249):return 'Player
5000 if mid$(map$(y%+1),x%,1)="0" then locate x%,y%:?chr$(32):mid$(map$(y%),x%,1)="0":ry%=ry%+1:mry%=y%+ry%:locate x%,mry%:PEN 5:?chr$(231):mid$(map$(mry%),x%,1)="3":ry%=0
5001 return
6000 if NOT(mid$(map$(movy%),movx%+1,1)="1") AND NOT(mid$(map$(movy%),movx%+1,1)="3") then locate movx%,movy%:print chr$(32):mid$(map$(movy%),movx%,1)="0":movx%=movx%+1:gosub 3000
6001 return
6100 if NOT(mid$(map$(movy%),movx%-1,1)="1") AND NOT(mid$(map$(movy%),movx%-1,1)="3") then locate movx%,movy%:print chr$(32):mid$(map$(movy%),movx%,1)="0":movx%=movx%-1:gosub 3000
6101 return
6200 if NOT(mid$(map$(movy%-1),movx%,1)="1") AND NOT(mid$(map$(movy%-1),movx%,1)="3") THEN locate movx%,movy%:print chr$(32):mid$(map$(movy%),movx%,1)="0":movy%=movy%-1:gosub 3000
6201 return
6300 if NOT(mid$(map$(movy%+1),movx%,1)="1") AND NOT(mid$(map$(movy%+1),movx%,1)="3") THEN locate movx%,movy%:print chr$(32):mid$(map$(movy%),movx%,1)="0":movy%=movy%+1:gosub 3000
6301 return
Much faster than first! :o
Quote from: ervin on 15:27, 12 October 18Some small adjustments for a bit more speed.
1 'Boulder Dash Engine - SLOW VERSION but most accurate.
2 '2018 - Fabrizio Radica
10 mode 1:pen 5:mx%=20:my%=11:DIM map$(my%):movx%=2:movy%=3:XOROn$=CHR$(23)+CHR$(1):XOROff$=CHR$(23)+CHR$(0)
100 'Read Map
110 FOR y%=1 TO my%
120 READ a$:map$(y%)=a$
121 FOR x%=1 TO mx%
125 LOCATE x%,y%
130 if mid$(map$(y%),x%,1)="1" then print CHR$(143):goto 145
135 if mid$(map$(y%),x%,1)="2" then print CHR$(207):goto 145
140 if mid$(map$(y%),x%,1)="3" then print CHR$(231)
145 NEXT x%
150 NEXT y%
160 locate 1,16:Print "Boulder Dash Engine"
165 Locate 1,17:print "Fabrizio Radica - www.retroacademy.it"
180 mid$(map$(movy%+1),movx%,1)="0":locate movx%,movy%:?chr$(249) 'Start player position
400 while 1 'Main Loop
450 gosub 2000 'Call player movements
660 FOR y%=2 TO my%-1
665 m$=map$(y%)
670 x%=2
675 'Check Rock collision and redraw the array map.
720 while x%<>0
730 x%=instr(x%,m$,"3")
735 if x%<>0 then gosub 5000:x%=x%+1
740 wend
750 next
800 wend
1000 'Map Data
1010 DATA "11111111111111111111"
1020 DATA "12223222222222222221"
1030 DATA "12333222233222222221"
1040 DATA "12222222223333222221"
1050 DATA "12222222222223222221"
1060 DATA "12333322222233332221"
1070 DATA "12222222223332222221"
1080 DATA "12222223222222233221"
1090 DATA "12222333222222222221"
1100 DATA "12222222222222222221"
1110 DATA "11111111111111111111"
1999 'Player Movements and collisions check.
2000 IF NOT(INKEY(1)) then gosub 6000
2100 IF NOT(INKEY() then gosub 6100
2200 IF NOT(INKEY(0)) then gosub 6200
2300 IF NOT(INKEY(2)) then gosub 6300
2400 return
3000 sound 1,900,1,15,1:locate movx%,movy%:pen 6:print CHR$(249):return 'Player
5000 if mid$(map$(y%+1),x%,1)="0" then locate x%,y%:?chr$(32):mid$(map$(y%),x%,1)="0":ry%=ry%+1:mry%=y%+ry%:locate x%,mry%:PEN 5:?chr$(231):mid$(map$(mry%),x%,1)="3":ry%=0
5001 return
6000 if NOT(mid$(map$(movy%),movx%+1,1)="1") AND NOT(mid$(map$(movy%),movx%+1,1)="3") then locate movx%,movy%:print chr$(32):mid$(map$(movy%),movx%,1)="0":movx%=movx%+1:gosub 3000
6001 return
6100 if NOT(mid$(map$(movy%),movx%-1,1)="1") AND NOT(mid$(map$(movy%),movx%-1,1)="3") then locate movx%,movy%:print chr$(32):mid$(map$(movy%),movx%,1)="0":movx%=movx%-1:gosub 3000
6101 return
6200 if NOT(mid$(map$(movy%-1),movx%,1)="1") AND NOT(mid$(map$(movy%-1),movx%,1)="3") THEN locate movx%,movy%:print chr$(32):mid$(map$(movy%),movx%,1)="0":movy%=movy%-1:gosub 3000
6201 return
6300 if NOT(mid$(map$(movy%+1),movx%,1)="1") AND NOT(mid$(map$(movy%+1),movx%,1)="3") THEN locate movx%,movy%:print chr$(32):mid$(map$(movy%),movx%,1)="0":movy%=movy%+1:gosub 3000
6301 return
I think Rock Hopper from Issue 6 of ACU, (http://www.cpcwiki.eu/index.php/ACU_Issue_6,_1985) shows a good programming structure for anyone interested in coding a Boulder Dash clone. True it's quite large, though I always remember tying it in relatively quickly back in the day and everything is clearly labelled. If you're interested Pages 80-82,85-87,89 & 90 compromise the main game with a Board Designer on Pages 90 & 91.
Quote from: AMSDOS on 00:54, 13 October 18
I think Rock Hopper from Issue 6 of ACU, (http://www.cpcwiki.eu/index.php/ACU_Issue_6,_1985) shows a good programming structure for anyone interested in coding a Boulder Dash clone. True it's quite large, though I always remember tying it in relatively quickly back in the day and everything is clearly labelled. If you're interested Pages 80-82,85-87,89 & 90 compromise the main game with a Board Designer on Pages 90 & 91.
Wow how time flies!
I remember typing that in as a kid (33 years ago!), and not having any idea of how it worked!
Really great game, especially for a type-in.
You can find Rock Hopper detailed here:
http://www.cpcwiki.eu/index.php/ACU_June_1985_-_Type-ins (http://www.cpcwiki.eu/index.php/ACU_June_1985_-_Type-ins)
Changed the map from an array to a single string, and made a few other small changes as well.
Got a nice speed-up.
8)
1 'Boulder Dash Engine
2 '2018 - Fabrizio Radica
10 mode 1:pen 5:mx%=20:my%=11:movx%=2:movy%=3
100 'Read Map
110 FOR y%=1 TO my%
120 READ a$:map$=map$+a$
130 next y%
140 l%=mx%*my%
150 for p%=1 to l%
160 y%=p%\20+1
170 x%=p% mod 20:if x%=0 then x%=20:y%=y%-1
180 locate x%,y%
185 m$=mid$(map$,p%,1)
190 if m$="1" then print chr$(143):goto 220
200 if m$="2" then print chr$(207):goto 220
210 if m$="3" then print chr$(231)
220 next p%
230 locate 1,16:Print "Boulder Dash Engine"
240 Locate 1,17:print "Fabrizio Radica - www.retroacademy.it"
250 mid$(map$,(movy%-1)*20+movx%,1)="0":locate movx%,movy%:print chr$(249) 'Start player position
300 while 1 'Main Loop
310 gosub 2000 'Call player movements
320 'Check Rock collision and redraw the array map.
330 p%=1
340 while p%<>0
350 p%=instr(p%,map$,"3")
360 if p%<>0 then gosub 5000:p%=p%+1
370 wend
380 wend
1000 'Map Data
1010 DATA "11111111111111111111"
1020 DATA "12223222222222222221"
1030 DATA "12333222233222222221"
1040 DATA "12222222223333222221"
1050 DATA "12222222222223222221"
1060 DATA "12333322222233332221"
1070 DATA "12222222223332222221"
1080 DATA "12222223222222233221"
1090 DATA "12222333222222222221"
1100 DATA "12222222222222222221"
1110 DATA "11111111111111111111"
1999 'Player Movements and collisions check.
2000 IF NOT(INKEY(1)) then gosub 6000
2100 IF NOT(INKEY() then gosub 6100
2200 IF NOT(INKEY(0)) then gosub 6200
2300 IF NOT(INKEY(2)) then gosub 6300
2400 return
3000 sound 1,900,1,15,1:locate movx%,movy%:pen 6:print CHR$(249):return 'Player
5000 if mid$(map$,p%+20,1)="0" then gosub 5500
5001 return
5500 y%=p%\20+1
5510 x%=p% mod 20:if x%=0 then x%=20:y%=y%-1
5520 locate x%,y%:print " "
5530 locate x%,y%+1:PEN 5:print chr$(231)
5540 y%=y%*20
5550 mid$(map$,y%-20+x%,1)="0"
5560 mid$(map$,y%+x%,1)="3"
5570 return
6000 y%=(movy%-1)*20:m$=mid$(map$,y%+movx%+1,1):if m$<>"1" AND m$<>"3" then gosub 7000:movx%=movx%+1:gosub 3000
6001 return
6100 y%=(movy%-1)*20:m$=mid$(map$,y%+movx%-1,1):if m$<>"1" AND m$<>"3" then gosub 7000:movx%=movx%-1:gosub 3000
6101 return
6200 y%=(movy%-1)*20:m$=mid$(map$,y%-20+movx%,1):if m$<>"1" AND m$<>"3" THEN gosub 7000:movy%=movy%-1:gosub 3000
6201 return
6300 y%=(movy%-1)*20:m$=mid$(map$,y%+20+movx%,1):if m$<>"1" AND m$<>"3" THEN gosub 7000:movy%=movy%+1:gosub 3000
6301 return
7000 locate movx%,movy%:print " ":mid$(map$,y%+movx%,1)="0"
7001 return
Removed the last line of the map definition entirely, and skipped processing of the first line of the map definition.
This has sped-up processing the rocks a bit more, as well as the initial drawing of the screen.
Also added a few little tidy-ups.
The program now runs approximately 7 times faster than the original.
I'd love to see this after it is compiled.
:)
1 'Boulder Dash Engine
2 '2018 - Fabrizio Radica
10 mode 1:pen 5:mx%=20:my%=10:movx%=2:movy%=3
100 'Read Map
110 FOR y%=1 TO my%
120 READ a$:map$=map$+a$
130 next y%
135 locate 1,1:print string$(20,chr$(143))
140 l%=mx%*my%
150 for p%=21 to l%
160 y%=p%\20+1
170 x%=p% mod 20:if x%=0 then x%=20:y%=y%-1
180 locate x%,y%
185 m$=mid$(map$,p%,1)
190 if m$="2" then print chr$(207):goto 220
200 if m$="3" then print chr$(231):goto 220
210 if m$="1" and p%>20 then print chr$(143)
220 next p%
225 locate 1,11:print string$(20,chr$(143))
230 locate 1,13:Print "Boulder Dash Engine"
240 Locate 1,14:print "Fabrizio Radica - www.retroacademy.it"
250 mid$(map$,(movy%-1)*20+movx%,1)="0":locate movx%,movy%:pen 6:print chr$(249) 'Start player position
300 while 1 'Main Loop
310 gosub 2000 'Call player movements
320 'Check Rock collision and redraw the array map.
330 p%=22
340 while p%<>0
350 p%=instr(p%,map$,"3")
360 if p%<>0 then gosub 5000:p%=p%+1
370 wend
380 wend
1000 'Map Data
1010 DATA "11111111111111111111"
1020 DATA "12223222222222222221"
1030 DATA "12333222233222222221"
1040 DATA "12222222223333222221"
1050 DATA "12222222222223222221"
1060 DATA "12333322222233332221"
1070 DATA "12222222223332222221"
1080 DATA "12222223222222233221"
1090 DATA "12222333222222222221"
1100 DATA "12222222222222222221"
1999 'Player Movements and collisions check.
2000 y%=(movy%-1)*20
2010 IF NOT(INKEY(1)) then gosub 6000
2100 IF NOT(INKEY() then gosub 6100
2200 IF NOT(INKEY(0)) then gosub 6200
2300 IF NOT(INKEY(2)) then gosub 6300
2400 return
3000 sound 1,900,1,15,1:locate movx%,movy%:pen 6:print CHR$(249):return 'Player
5000 if mid$(map$,p%+20,1)<>"0" then return
5500 y%=p%\20+1
5510 x%=p% mod 20:if x%=0 then x%=20:y%=y%-1
5520 locate x%,y%:print " "
5530 locate x%,y%+1:PEN 5:print chr$(231)
5550 mid$(map$,p%,1)="0"
5560 mid$(map$,p%+20,1)="3"
5570 return
6000 m$=mid$(map$,y%+movx%+1,1):if m$<>"1" AND m$<>"3" then gosub 7000:movx%=movx%+1:goto 3000
6010 return
6100 m$=mid$(map$,y%+movx%-1,1):if m$<>"1" AND m$<>"3" then gosub 7000:movx%=movx%-1:goto 3000
6110 return
6200 m$=mid$(map$,y%-20+movx%,1):if m$<>"1" AND m$<>"3" THEN gosub 7000:movy%=movy%-1:goto 3000
6210 return
6300 if movy%=10 then return
6310 m$=mid$(map$,y%+20+movx%,1):if m$<>"1" AND m$<>"3" THEN gosub 7000:movy%=movy%+1:goto 3000
6320 return
7000 locate movx%,movy%:print " ":mid$(map$,y%+movx%,1)="0"
7010 return
wow man!
Quote from: ervin on 12:45, 14 October 18Removed the last line of the map definition entirely, and skipped processing of the first line of the map definition.
This has sped-up processing the rocks a bit more, as well as the initial drawing of the screen.
Also added a few little tidy-ups.
The program now runs approximately 7 times faster than the original.
I'd love to see this after it is compiled.
:)
1 'Boulder Dash Engine
2 '2018 - Fabrizio Radica
10 mode 1:pen 5:mx%=20:my%=10:movx%=2:movy%=3
100 'Read Map
110 FOR y%=1 TO my%
120 READ a$:map$=map$+a$
130 next y%
135 locate 1,1:print string$(20,chr$(143))
140 l%=mx%*my%
150 for p%=21 to l%
160 y%=p%\20+1
170 x%=p% mod 20:if x%=0 then x%=20:y%=y%-1
180 locate x%,y%
185 m$=mid$(map$,p%,1)
190 if m$="2" then print chr$(207):goto 220
200 if m$="3" then print chr$(231):goto 220
210 if m$="1" and p%>20 then print chr$(143)
220 next p%
225 locate 1,11:print string$(20,chr$(143))
230 locate 1,13:Print "Boulder Dash Engine"
240 Locate 1,14:print "Fabrizio Radica - www.retroacademy.it"
250 mid$(map$,(movy%-1)*20+movx%,1)="0":locate movx%,movy%:pen 6:print chr$(249) 'Start player position
300 while 1 'Main Loop
310 gosub 2000 'Call player movements
320 'Check Rock collision and redraw the array map.
330 p%=22
340 while p%<>0
350 p%=instr(p%,map$,"3")
360 if p%<>0 then gosub 5000:p%=p%+1
370 wend
380 wend
1000 'Map Data
1010 DATA "11111111111111111111"
1020 DATA "12223222222222222221"
1030 DATA "12333222233222222221"
1040 DATA "12222222223333222221"
1050 DATA "12222222222223222221"
1060 DATA "12333322222233332221"
1070 DATA "12222222223332222221"
1080 DATA "12222223222222233221"
1090 DATA "12222333222222222221"
1100 DATA "12222222222222222221"
1999 'Player Movements and collisions check.
2000 y%=(movy%-1)*20
2010 IF NOT(INKEY(1)) then gosub 6000
2100 IF NOT(INKEY() then gosub 6100
2200 IF NOT(INKEY(0)) then gosub 6200
2300 IF NOT(INKEY(2)) then gosub 6300
2400 return
3000 sound 1,900,1,15,1:locate movx%,movy%:pen 6:print CHR$(249):return 'Player
5000 if mid$(map$,p%+20,1)<>"0" then return
5500 y%=p%\20+1
5510 x%=p% mod 20:if x%=0 then x%=20:y%=y%-1
5520 locate x%,y%:print " "
5530 locate x%,y%+1:PEN 5:print chr$(231)
5550 mid$(map$,p%,1)="0"
5560 mid$(map$,p%+20,1)="3"
5570 return
6000 m$=mid$(map$,y%+movx%+1,1):if m$<>"1" AND m$<>"3" then gosub 7000:movx%=movx%+1:goto 3000
6010 return
6100 m$=mid$(map$,y%+movx%-1,1):if m$<>"1" AND m$<>"3" then gosub 7000:movx%=movx%-1:goto 3000
6110 return
6200 m$=mid$(map$,y%-20+movx%,1):if m$<>"1" AND m$<>"3" THEN gosub 7000:movy%=movy%-1:goto 3000
6210 return
6300 if movy%=10 then return
6310 m$=mid$(map$,y%+20+movx%,1):if m$<>"1" AND m$<>"3" THEN gosub 7000:movy%=movy%+1:goto 3000
6320 return
7000 locate movx%,movy%:print " ":mid$(map$,y%+movx%,1)="0"
7010 return
isn't possible to play a song from BASIC? (not with data statement).
Quote from: ervin on 12:45, 14 October 18Removed the last line of the map definition entirely, and skipped processing of the first line of the map definition.
This has sped-up processing the rocks a bit more, as well as the initial drawing of the screen.
Also added a few little tidy-ups.
The program now runs approximately 7 times faster than the original.
I'd love to see this after it is compiled.
:)
1 'Boulder Dash Engine
2 '2018 - Fabrizio Radica
10 mode 1:pen 5:mx%=20:my%=10:movx%=2:movy%=3
100 'Read Map
110 FOR y%=1 TO my%
120 READ a$:map$=map$+a$
130 next y%
135 locate 1,1:print string$(20,chr$(143))
140 l%=mx%*my%
150 for p%=21 to l%
160 y%=p%\20+1
170 x%=p% mod 20:if x%=0 then x%=20:y%=y%-1
180 locate x%,y%
185 m$=mid$(map$,p%,1)
190 if m$="2" then print chr$(207):goto 220
200 if m$="3" then print chr$(231):goto 220
210 if m$="1" and p%>20 then print chr$(143)
220 next p%
225 locate 1,11:print string$(20,chr$(143))
230 locate 1,13:Print "Boulder Dash Engine"
240 Locate 1,14:print "Fabrizio Radica - www.retroacademy.it"
250 mid$(map$,(movy%-1)*20+movx%,1)="0":locate movx%,movy%:pen 6:print chr$(249) 'Start player position
300 while 1 'Main Loop
310 gosub 2000 'Call player movements
320 'Check Rock collision and redraw the array map.
330 p%=22
340 while p%<>0
350 p%=instr(p%,map$,"3")
360 if p%<>0 then gosub 5000:p%=p%+1
370 wend
380 wend
1000 'Map Data
1010 DATA "11111111111111111111"
1020 DATA "12223222222222222221"
1030 DATA "12333222233222222221"
1040 DATA "12222222223333222221"
1050 DATA "12222222222223222221"
1060 DATA "12333322222233332221"
1070 DATA "12222222223332222221"
1080 DATA "12222223222222233221"
1090 DATA "12222333222222222221"
1100 DATA "12222222222222222221"
1999 'Player Movements and collisions check.
2000 y%=(movy%-1)*20
2010 IF NOT(INKEY(1)) then gosub 6000
2100 IF NOT(INKEY() then gosub 6100
2200 IF NOT(INKEY(0)) then gosub 6200
2300 IF NOT(INKEY(2)) then gosub 6300
2400 return
3000 sound 1,900,1,15,1:locate movx%,movy%:pen 6:print CHR$(249):return 'Player
5000 if mid$(map$,p%+20,1)<>"0" then return
5500 y%=p%\20+1
5510 x%=p% mod 20:if x%=0 then x%=20:y%=y%-1
5520 locate x%,y%:print " "
5530 locate x%,y%+1:PEN 5:print chr$(231)
5550 mid$(map$,p%,1)="0"
5560 mid$(map$,p%+20,1)="3"
5570 return
6000 m$=mid$(map$,y%+movx%+1,1):if m$<>"1" AND m$<>"3" then gosub 7000:movx%=movx%+1:goto 3000
6010 return
6100 m$=mid$(map$,y%+movx%-1,1):if m$<>"1" AND m$<>"3" then gosub 7000:movx%=movx%-1:goto 3000
6110 return
6200 m$=mid$(map$,y%-20+movx%,1):if m$<>"1" AND m$<>"3" THEN gosub 7000:movy%=movy%-1:goto 3000
6210 return
6300 if movy%=10 then return
6310 m$=mid$(map$,y%+20+movx%,1):if m$<>"1" AND m$<>"3" THEN gosub 7000:movy%=movy%+1:goto 3000
6320 return
7000 locate movx%,movy%:print " ":mid$(map$,y%+movx%,1)="0"
7010 return
I don't know how to play music without data statements.
Others may be able to help you though.
Also, be aware that copying/pasting code to the forum seems to break line 2100.
The "8" followed by ")" fails, as it matches this emoticon: 8)
Quote from: Fabrizio Radica on 22:38, 14 October 18
isn't possible to play a song from BASIC? (not with data statement).
You will need data statements to play a bigger melody, or you can use random sound effects without data statements. I dont know how big the sound buffer is,but it could also work for reading a very very small tune during an interupt routine and play it as a Loop? So you wouldn't need a data statements.
Second option might be, to define the map as an array, Not as datas and than use datas for the melody?
I've made this logic for a "tracker" on Basic.
Obviously it's only a test and not optimized, only for prototyping.
https://github.com/FabrizioRadica/Locomotive-Tracker
Quote from: HAL 6128 on 00:01, 15 October 18You will need data statements to play a bigger melody, or you can use random sound effects without data statements. I dont know how big the sound buffer is,but it could also work for reading a very very small tune during an interupt routine and play it as a Loop? So you wouldn't need a data statements.
Second option might be, to define the map as an array, Not as datas and than use datas for the melody?
Quote from: Fabrizio Radica on 22:38, 14 October 18
isn't possible to play a song from BASIC? (not with data statement).
Why don't you want to use data statements?
Anyway, there is a way: You can use a string instead, containing the tones.
10 tone$ = "ZSXDCVGBHNJM" ' They keys on your musical keyboard.
20 melody$ = "ZCBZCBZCBZCB" ' The sequence of the keys
30 dim frequency%(255) ' We make room for 255 frequencies (i.e. notes). Way too much, but bare with me for now.
40 freq% = 478
50 for n%=1 to len(tone$)
60 frequency%(asc(mid$(tone$,n%,1))) = freq% ' We put the frequency into the position in the array corresponding to the ASCII code value of the character.
70 freq% = freq% * 2^(-1/12) ' Then we calculate the next tone
80 next
90 ' Now you have an array with frequencies. Next is to read your string, and play the tone according to the character
100 for n%=1 to len(melody$)
110 sound 1,frequency%(asc(mid$(melody$,n%,1))),50,15
120 next