Author Topic: Boulder Dash Engine Locomotive Basic  (Read 502 times)

0 Members and 1 Guest are viewing this topic.

Offline Fabrizio Radica

  • Supporter
  • CPC664
  • *
  • Posts: 107
  • Country: it
  • MSX Amiga and CPC6128 User
    • Retroacademy
  • Liked: 81
Boulder Dash Engine Locomotive Basic
« on: 14:38, 12 October 18 »
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
Amstrad CPC6128 <3
http://www.facebook.com/groups/retroacademy/
Retroacademy.it - retrocomputing, retrogame anni &#039;70, &#039;80, &#039;90
Retroacademy.it - retrocomputing, retrogame anni '70, '80, '90

Online ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.215
  • Country: au
    • index.php?action=treasury
  • Liked: 879
Re: Boulder Dash Engine Locomotive Basic
« Reply #1 on: 15:49, 12 October 18 »
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)
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline Fabrizio Radica

  • Supporter
  • CPC664
  • *
  • Posts: 107
  • Country: it
  • MSX Amiga and CPC6128 User
    • Retroacademy
  • Liked: 81
Re: Boulder Dash Engine Locomotive Basic
« Reply #2 on: 16:00, 12 October 18 »
ohh thank's you!!
I'm glad you like it :)

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)
Amstrad CPC6128 <3
http://www.facebook.com/groups/retroacademy/
Retroacademy.it - retrocomputing, retrogame anni &#039;70, &#039;80, &#039;90
Retroacademy.it - retrocomputing, retrogame anni '70, '80, '90

Online ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.215
  • Country: au
    • index.php?action=treasury
  • Liked: 879
Re: Boulder Dash Engine Locomotive Basic
« Reply #3 on: 16:40, 12 October 18 »
Some more speed-ups, this time using an array of strings for the map, instead of a 2-dimensional array.

Code: [Select]
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
« Last Edit: 17:12, 12 October 18 by ervin »
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Online ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.215
  • Country: au
    • index.php?action=treasury
  • Liked: 879
Re: Boulder Dash Engine Locomotive Basic
« Reply #4 on: 17:27, 12 October 18 »
Some small adjustments for a bit more speed.

Code: [Select]
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
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline Fabrizio Radica

  • Supporter
  • CPC664
  • *
  • Posts: 107
  • Country: it
  • MSX Amiga and CPC6128 User
    • Retroacademy
  • Liked: 81
Re: Boulder Dash Engine Locomotive Basic
« Reply #5 on: 18:27, 12 October 18 »
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 :)

Some small adjustments for a bit more speed.

Code: [Select]
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
Amstrad CPC6128 <3
http://www.facebook.com/groups/retroacademy/
Retroacademy.it - retrocomputing, retrogame anni &#039;70, &#039;80, &#039;90
Retroacademy.it - retrocomputing, retrogame anni '70, '80, '90

Offline Fabrizio Radica

  • Supporter
  • CPC664
  • *
  • Posts: 107
  • Country: it
  • MSX Amiga and CPC6128 User
    • Retroacademy
  • Liked: 81
Re: Boulder Dash Engine Locomotive Basic
« Reply #6 on: 19:30, 12 October 18 »
Much faster than first!  :o 
Some small adjustments for a bit more speed.

Code: [Select]
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
Amstrad CPC6128 <3
http://www.facebook.com/groups/retroacademy/
Retroacademy.it - retrocomputing, retrogame anni &#039;70, &#039;80, &#039;90
Retroacademy.it - retrocomputing, retrogame anni '70, '80, '90

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.454
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 710
Re: Boulder Dash Engine Locomotive Basic
« Reply #7 on: 02:54, 13 October 18 »
I think Rock Hopper from Issue 6 of ACU, 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.
* Using some of the hardly used Amstrad compilers :D
* I use Firmware in my Assembly code :P
* Have interpreted some BASIC 1.1 programs for BASIC 1.0. :)

Online ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.215
  • Country: au
    • index.php?action=treasury
  • Liked: 879
Re: Boulder Dash Engine Locomotive Basic
« Reply #8 on: 03:27, 13 October 18 »
I think Rock Hopper from Issue 6 of ACU, 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
« Last Edit: 14:05, 13 October 18 by ervin »
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Online ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.215
  • Country: au
    • index.php?action=treasury
  • Liked: 879
Re: Boulder Dash Engine Locomotive Basic
« Reply #9 on: 15:33, 13 October 18 »
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)

Code: [Select]
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
« Last Edit: 01:23, 14 October 18 by ervin »
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Online ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.215
  • Country: au
    • index.php?action=treasury
  • Liked: 879
Re: Boulder Dash Engine Locomotive Basic
« Reply #10 on: 14:45, 14 October 18 »
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.
 :)

Code: [Select]
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
« Last Edit: 14:49, 14 October 18 by ervin »
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline Fabrizio Radica

  • Supporter
  • CPC664
  • *
  • Posts: 107
  • Country: it
  • MSX Amiga and CPC6128 User
    • Retroacademy
  • Liked: 81
Re: Boulder Dash Engine Locomotive Basic
« Reply #11 on: 15:28, 14 October 18 »
wow man!
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.
 :)

Code: [Select]
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
Amstrad CPC6128 <3
http://www.facebook.com/groups/retroacademy/
Retroacademy.it - retrocomputing, retrogame anni &#039;70, &#039;80, &#039;90
Retroacademy.it - retrocomputing, retrogame anni '70, '80, '90

Offline Fabrizio Radica

  • Supporter
  • CPC664
  • *
  • Posts: 107
  • Country: it
  • MSX Amiga and CPC6128 User
    • Retroacademy
  • Liked: 81
Re: Boulder Dash Engine Locomotive Basic
« Reply #12 on: 00:38, 15 October 18 »
isn't possible to play a song from BASIC? (not with data statement).
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.
 :)

Code: [Select]
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
Amstrad CPC6128 <3
http://www.facebook.com/groups/retroacademy/
Retroacademy.it - retrocomputing, retrogame anni &#039;70, &#039;80, &#039;90
Retroacademy.it - retrocomputing, retrogame anni '70, '80, '90

Online ervin

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.215
  • Country: au
    • index.php?action=treasury
  • Liked: 879
Re: Boulder Dash Engine Locomotive Basic
« Reply #13 on: 00:45, 15 October 18 »
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)

« Last Edit: 02:19, 15 October 18 by ervin »
My (cancelled) entry for the CPCRetroDev 2017 Competition http://www.cpcwiki.eu/forum/programming/my-cpcretrodev-2017-entry/
FAST line drawing in CPCtelera http://www.cpcwiki.eu/forum/programming/drawing-lines-with-cpctelera-sdcc/
RUNCPC My entry for the CPCRetroDev 2015 Competition http://www.cpc-power.com/index.php?page=detail&num=12494

Offline HAL 6128

  • 464 Plus
  • *****
  • Posts: 446
  • Country: de
    • index.php?action=treasury
  • Liked: 215
Re: Boulder Dash Engine Locomotive Basic
« Reply #14 on: 02:01, 15 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?
...proudly supported Pentomino and NQ-Music-Disc with GFX

Offline Fabrizio Radica

  • Supporter
  • CPC664
  • *
  • Posts: 107
  • Country: it
  • MSX Amiga and CPC6128 User
    • Retroacademy
  • Liked: 81
Re: Boulder Dash Engine Locomotive Basic
« Reply #15 on: 09:37, 15 October 18 »
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

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?
Amstrad CPC6128 <3
http://www.facebook.com/groups/retroacademy/
Retroacademy.it - retrocomputing, retrogame anni &#039;70, &#039;80, &#039;90
Retroacademy.it - retrocomputing, retrogame anni '70, '80, '90

Offline mr_lou

  • 6128 Plus
  • ******
  • Posts: 2.699
  • Country: dk
    • index.php?action=treasury
    • 8-bit Memoirs - a Blu-ray diskmag-like eBook about the 8-bit era
  • Liked: 917
Re: Boulder Dash Engine Locomotive Basic
« Reply #16 on: 20:27, 15 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.
Code: [Select]
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
« Last Edit: 20:29, 15 October 18 by mr_lou »