Code: Select all
0 dim x, y, a, b, s, d, i, j, up, down, left, right, fire, vic, po, bit, msb, cmsb, z, ff
10 def fn b(s) = abs(s)
20 fire = 16
30 right = 8
40 left = 4
50 up = 2
60 down = 1
70 po = 56320
80 bit = 127
90 z = 0
100 cmsb = 251
110 ff = 255
120 min = right
130 max = 334
140 x = 62
150 poke 53280,z:poke 53281,z
160 print "{clear}"
170 vic = 53248
180 i = 2042
190 d = 832
200 s = 21
210 a = 13
220 j = 4
230 poke vic+s, j
240 poke i, a
250 for i = z to x
260 read j
270 poke d+i, j
280 next
290 x = 64
300 y = x
310 a = 4
320 d = a+1
330 for i = z to down
340 if x <= ff then msb = z:poke vic+fire, peek(vic+fire) and cmsb
350 if x > ff then msb = ff:poke vic+fire, peek(vic+fire) or left
360 poke vic+a, x-msb
370 poke vic+d, y
380 j = bit - peek(po)
390 x = x + fn b(j=right) - fn b(j=left)
400 y = y + fn b(j=up) - fn b(j=down)
410 x = x + fn b(x<min) - fn b(x > max)
420 y = y + fn b(y<z) - fn b(y > ff)
430 if j = fire then next: end
440 i = z
450 next
63999 data ,127,,1,255,192,3,255,224,3,231,224,7,217,240,7,223,240,7,217,240,3,231,224,3,255,224,3,255,224,2,255,160,1,127,64,1,62,64,,156,128,,156,128,,73,,,73,,,62,,,62,,,62,,,28,
The listing does not handle diagonal movements yet, and fire will end the demonstration. The data has been minimised - where you see ,, should be a zero. As CBM BASIC will read an empty data entry as zero then I've missed them out. Not sure what happens if you were to read a string.
I've recycled some variables as required and defined some as constants (like z for zero and ff for 255).
The check in line 340 and 350 is to set the MSB for sprite 4 so that you may move the sprite across the whole of the visible screen area. There might be a more efficient way of doing this, I'll have to think about that.
As I'm happy that this is working, I'll add a minimised (hopefully more efficient and/or memory friendly) version as soon as. But obviously you don't need a function to get the ABS value as you can just use ABS is place of the fn b() where ever you see it. Also, all of the variables can be minimised to a single letter. There's a lot of lines as well, this can easily be reduced without much effort. And a 'goto' may be added instead of 'illegal' use of the for/next loop. There's probably a more graceful way to exit the program as well.
Regards,
Shaun.