home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1985 September / Ahoy_Magazine_85-09_1985_Double_L.d64 / sprites (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  6KB  |  171 lines

  1. 1 rem    *** basic sprites ***
  2. 2 rem a ship and a rocket demonstrate sprite creation and movement
  3. 9 rem      *** set-up subroutines ***
  4. 10 gosub 600:rem (video memory)
  5. 11 gosub 700:rem (background)
  6. 12 gosub 800:rem (sprite shapes)
  7. 13 gosub 900:rem (sprite positions)
  8. 15 goto 100
  9. 98 rem      *** action loop ***
  10. 100 vp=vp+1:if vp>vz then vp=0
  11. 110 hp=hp-1:if hp<0 then hp=hz
  12. 120 poke vt(1),vv(vp)
  13. 130 poke ht(0),hh(hp):poke hr,hb(hp):poke ht(1),hh(hp)
  14. 140 wv=wv-1:if wv<1 then wv=8
  15. 150 print dd$mid$(st$,wv,40)"";
  16. 196 goto 100
  17. 198 rem     *** wait for response ***
  18. 296 return
  19. 298 rem     *** ending routines ***
  20. 300 print "[147]final score:  "rt*100+vp*10:print:print:vp=15:poke vt(0),vv(vp)
  21. 310 print "to play again, press p":print "to quit, press q":hp=79
  22. 315 hp=79:poke hr,hb(hp):poke ht(0),hh(hp):xp=1:poke lt(0),st(xp)
  23. 320 z=peek(203):if z=62 then 370
  24. 325 poke ht(0),hh(hp):poke hr,hb(hp)
  25. 330 hp=hp+1:if hp>hz then hp=0
  26. 345 if z<>41 then 320
  27. 350 eg=0:dl=0:dt=1:ds=5:rt=0:rc=0:gosub 930:goto 100
  28. 369 rem ** put video memory back to first block, and screen memory to 1024
  29. 370 poke 56578,peek(56578)or3:poke 56576,(peek(56576)and 252)or 3
  30. 371 poke 53272,20:poke 648,4
  31. 379 rem ** reenable shift/commodore and run-stop/restore
  32. 380 poke 657,0:poke 792,71:poke 808,237
  33. 390 end
  34. 598 rem    *** arrange memory ***
  35. 599 rem use first video block (0 to 16383) so nothing fancy has to be done.
  36. 600 vb=0
  37. 601 rem ** screen memory stays where it is
  38. 608 rem    *** register addresses ***
  39. 609 rem ** sprite shape location table
  40. 610 lt(0)=2040:for i=1 to 7:lt(i)=lt(i-1)+1:next
  41. 611 rem ** sprite color table
  42. 612 ct(0)=53287:for i=1 to 7:ct(i)=ct(i-1)+1:next
  43. 613 rem ** sprite horizontal position table (low bytes)
  44. 614 ht(0)=53248:for i=1 to 7:ht(i)=ht(i-1)+2:next
  45. 615 rem ** sprite vertical position table
  46. 616 vt(0)=53249:for i=1 to 7:vt(i)=vt(i-1)+2:next
  47. 617 rem ** sprite horizontal high-bit register
  48. 618 hr=53264
  49. 619 rem ** sprite enable register
  50. 620 es=53269
  51. 621 rem ** vertical expansion register (1=double height)
  52. 622 ve=53271
  53. 623 rem ** horizontal expansion register (1=double width)
  54. 624 he=53277
  55. 625 rem ** sprite priority register (1=sprite is in front of foreground)
  56. 626 pr=53275
  57. 627 rem ** multicolor enable register (1=multi-color enabled)
  58. 628 em=53276
  59. 629 rem ** sprite multicolor color registers
  60. 630 mr=53285:rem ('01' register: add 1 to mr for '11' register)
  61. 631 rem ** sprite-sprite collision register
  62. 632 cs=53278
  63. 633 rem ** sprite-foreground collision register
  64. 634 cf=53279
  65. 635 rem ** set-bit and clear-bit values
  66. 636 bs(0)=1:for i=1 to 7:bs(i)=2*bs(i-1):next
  67. 637 for i=0 to 7:bc(i)=255-bs(i):next
  68. 638 rem     *** initialize values ***
  69. 639 rem ** foreground color
  70. 640 poke 53281,6:print "[147]";:rem (blue)
  71. 641 rem ** background color
  72. 642 poke 53281,14:rem (light blue)
  73. 643 rem ** border color
  74. 644 poke 53280,0:rem (black)
  75. 645 rem ** sprite colors (defaults: whi,red,l-grn,pur,grn,blu,yel,m-gray)
  76. 646 poke ct(0),0:poke ct(1),2:rem (the ship is black, the rocket red)
  77. 647 rem ** set priority
  78. 648 poke pr,255:rem (all behind)
  79. 649 rem ** set horizontal sizes
  80. 650 poke he,1:rem (ship is double width, rocket is normal width)
  81. 651 rem ** set vertical sizes
  82. 652 poke ve,2:rem (rocket is double height)
  83. 653 rem ** enable sprites
  84. 654 poke es,bs(0) or bs(1):rem (sprites 0 and 1)
  85. 696 return
  86. 698 rem     *** set up ocean ***
  87. 700 r$=chr$(18):rx$=chr$(146):b$=" "
  88. 701 fd$=chr$(162)+chr$(185)+chr$(175)+chr$(228)
  89. 703 fu$=b$+chr$(228)+chr$(175)+chr$(185)
  90. 705 s$=r$:for i=1 to 40:s$=s$+b$:next:s$=s$+rx$
  91. 706 st$=fu$+fd$+fu$+fd$+fu$+fd$:st$=st$+st$
  92. 707 dd$=""
  93. 708 wv=8
  94. 710 print "[147]"dd$mid$(st$,wv,40)s$s$s$left$(s$,40)""rx$;
  95. 711 poke 2023,160
  96. 796 return
  97. 798 rem     *** sprite shapes ***
  98. 799 rem ** number of sprite shapes (-1);number of lines per sprite shape (-1)
  99. 800 ns=1
  100. 801 rem ** locate sprite shape memory
  101. 802 st(0)=13:st(1)=14
  102. 803 rem ** loops
  103. 804 for i=0 to ns:for j=0 to 20:read ss$:for k=0 to 2:x=0:y=vb+st(i)*64+j*3+k
  104. 805 rem ** convert strings to shape bytes (use bs(0-7) to set bits)
  105. 806 for l=1 to 8:m=l+8*k:m=asc(mid$(ss$,m,1)):if m=42 then x=x or bs(8-l)
  106. 807 next:poke y,x:next:next:next
  107. 809 rem sprite shape data, 21 lines  per shape: *='on'  .='off'
  108. 810 data ".........*.............."
  109. 811 data ".........*.............."
  110. 812 data ".........*..**.........."
  111. 813 data ".........*..**.........."
  112. 814 data "........**..**.........."
  113. 815 data "........**.***.........."
  114. 816 data ".........*****.........."
  115. 817 data ".......*********........"
  116. 818 data "************************"
  117. 819 data "************************"
  118. 820 data "..********************.."
  119. 821 data "...******************..."
  120. 822 data "...******************..."
  121. 823 data "...*******************.."
  122. 824 data "....******************.."
  123. 825 data ".....*****************.."
  124. 826 data "........................"
  125. 827 data "........................"
  126. 828 data "........................"
  127. 829 data "........................"
  128. 830 data "........................"
  129. 831 rem ** 2nd sprite shape
  130. 832 data ".....................*.."
  131. 833 data ".....................*.."
  132. 834 data "....................***."
  133. 835 data "....................***."
  134. 836 data "....................***."
  135. 837 data "....................***."
  136. 838 data "....................***."
  137. 839 data "....................***."
  138. 840 data "....................*.*."
  139. 841 data "....................*.*."
  140. 842 data "........................"
  141. 843 data "........................"
  142. 844 data "........................"
  143. 845 data "........................"
  144. 846 data "........................"
  145. 847 data "........................"
  146. 848 data "........................"
  147. 849 data "........................"
  148. 850 data "........................"
  149. 851 data "........................"
  150. 852 data "........................"
  151. 853 data "........................"
  152. 896 return
  153. 898 rem     *** sprite positions ***
  154. 899 rem ** possible positions dim'ed
  155. 900 vz=32:hz=362:dim hh(hz),vv(vz),hb(hz)
  156. 901 rem ** assign  horizontal values
  157. 902 x=0:b=0:for i=0 to hz:hh(i)=x:hb(i)=b
  158. 903 x=x+1:if x>255 then x=x-256:b=3
  159. 904 next
  160. 905 rem ** assign vertical values
  161. 906 x=202:for i=0 to 9:vv(i)=x:x=x-1:next:for i=10 to 14:vv(i)=x:x=x-2:next
  162. 907 :for i=15 to 18:vv(i)=x:x=x-3:next:for i=19 to 21:vv(i)=x:x=x-6:next
  163. 908 for i=22 to vz:vv(i)=x:x=x-12:next
  164. 929 rem ** initial sprite positioning
  165. 930 hp=160:vp=0
  166. 931 poke vt(0),vv(vp):poke ht(0),hh(hp):poke hr,hb(hp)
  167. 932 poke vt(1),vv(vp):poke ht(1),hh(hp)
  168. 939 rem ** tell vic-2 where to find sprite shapes
  169. 940 poke lt(0),st(0):poke lt(1),st(1)
  170. 996 return
  171.