home *** CD-ROM | disk | FTP | other *** search
/ Compute! Gazette 1984 May / 1984-05.d64 / supersprite (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  7KB  |  207 lines

  1. 10 rema:
  2. 20 :
  3. 21 rem         list of variables
  4. 22 rem sp sprite page
  5. 23 rem v  base of video chip
  6. 24 rem c  base of colour ram
  7. 25 rem sd base of sound chip
  8. 26 rem s  base of screen
  9. 27 rem hs byte to save high score
  10. 28 rem ch kernal print routine (chrout)
  11. 29 rem ar image of accumulator register
  12. 30 rem bs best score yet at runtime
  13. 31 rem zs old screen base and char set
  14. 32 rem zc old background colour
  15. 33 rem ze old border colour
  16. 34 rem zr old value of repeat flag
  17. 35 rem zl old print colour
  18. 36 rem gl turn number in game loop
  19. 37 rem i and j  for-next indices
  20. 38 rem u, u2 and u$ workhorses
  21. 39 rem t1-t9  constants in game loop
  22. 40 rem b$ game screen building block
  23. 41 rem t$ 16 space indent
  24. 42 rem w  either v or v+1 (sprite pos.)
  25. 43 rem ps part-score (one turn)
  26. 44 rem ts total score so far
  27. 45 rem fq quit flag, set by pressing *
  28. 46 :
  29. 47 rem         subroutines
  30. 48 rem  1000 one turn of the game
  31. 49 rem  2000 print game screen
  32. 50 rem  3000 exit (or play again)
  33. 51 rem  4000 build sprite
  34. 52 rem  5000 instructions data strings
  35. 53 rem  6000 print instructions
  36. 54 rem  7000 fly sprite ahead of instr.
  37. 55 rem  8000 wait to resume game
  38. 56 :
  39. 100 rem seed random number generator, disable character set shifts
  40. 110 u=rnd(-ti):poke657,128
  41. 120 rem save old environment, build new one, build sprite, print instructions
  42. 130 sp=13:v=53248
  43. 140 poke2041,peek(v+24):pokev+24,22
  44. 150 poke2042,peek(v+32):pokev+32,7
  45. 160 poke2043,peek(v+33):pokev+33,7
  46. 170 poke2044,peek(646):poke646,0
  47. 180 poke2045,peek(650):poke650,128
  48. 190 print"[147]":gosub4000
  49. 200 gosub6000:print"[147]":pokev+24,20
  50. 210 deffnsc(u)=int(u+u*gl/10)
  51. 220 fori=1to16:t$=t$+"":nexti
  52. 230 b$=""+chr$(13)+"":fori=0to39:b$=b$+" ":nexti
  53. 240 v=53248:c=55296:s=1024:sd=54272
  54. 250 hs=peek(43)+peek(44)*256+5
  55. 260 t1=135:t2=255:t3=230:t4=133
  56. 270 t5=5:t6=9:t7=.992:t8=42:t9=32
  57. 280 bs=peek(hs):ch=65508:ar=780
  58. 290 rem initialize cursors, print game screen
  59. 300 e(1)=1269:e(2)=1475:e(3)=1682:e(4)=1888
  60. 310 pokev+21,0:gosub2000
  61. 320 rem make space for score on screen, set sound chip, clear keyboard buffer
  62. 330 fori=1080to1100:pokei,32:next
  63. 340 pokesd+4,16:pokesd+11,16:pokesd+18,16
  64. 350 pokesd+6,240:pokesd+13,240:pokesd+20,240
  65. 360 pokesd+24,15
  66. 370 geta$:ifa$<>""then370
  67. 380 :
  68. 390 rem begin 20-turn game loop,set part score to zero
  69. 400 forgl=1to20:ps=0
  70. 410 rem position sprite, unexpand it, zero the collision detect register
  71. 420 pokev,23:pokev+1,49
  72. 430 pokev+23,0:pokev+31,0
  73. 440 rem print score info, turn on sound
  74. 450 print""t$"turn:"gl"  score:"ts
  75. 460 print""t$"best yet:"peek(hs)-1
  76. 470 pokesd+4,17:pokesd+11,17:pokesd+18,17
  77. 480 rem turn on sprite, take 1 turn, goto 570 if game aborted (fq set)
  78. 490 pokev+21,1:gosub1000:iffq=1then550
  79. 500 rem scroll sprite off screen if no collision, otherwise screech to a halt
  80. 510 ifpeek(v+1)>t3thenfori=peek(v+1)to250:pokev+1,i:nexti:goto550
  81. 520 pokesd+4,129:pokesd+11,33:pokesd+18,33
  82. 530 for i=72to20step-2:pokesd+1,i:pokesd+8,i-3:pokesd+15,i-2:nexti
  83. 540 rem turn off sound. jump to exit if fq set
  84. 550 pokesd+4,16:pokesd+11,16:pokesd+18,16
  85. 560 pokesd+1,0:pokesd+8,0:pokesd+15,0
  86. 570 iffq=1thenfq=0:gl=20:next:pokev+21,0:goto670
  87. 580 rem calculate part score from sprite y position, modify, add to total score
  88. 590 ps=fnsc(int((peek(v+1)-71)/40))
  89. 600 ts=ts+int((ps^1.4+ps)/2)
  90. 610 pokev+21,0:pokev+16,0
  91. 620 nextgl
  92. 630 rem update high score record, zero sound chip, go to exit (3000)
  93. 640 ifpeek(hs)<ts+1thenpokehs,ts+1
  94. 650 fori=0to24:poke sd+i,0:nexti
  95. 660 fori=1to500:nexti
  96. 670 gosub3000:clr:goto210
  97. 680 :
  98. 970 rem subroutine--one turn of the game
  99. 980 :
  100. 990 rem decide which sprite position register to alter (w) and by how much (u)
  101. 1000 u2=rnd(1):w=v+int(u2*2):u=gl/7+2
  102. 1010 rem y-expand sprite if expression true
  103. 1020 ifu2>t7andpeek(v+1)<t1thenpokev+23,1
  104. 1030 rem set msb of sprite x-position if necessary
  105. 1040 ifpeek(w)+u>t2thenpokev+16,1:pokev,peek(v)+u-t2:goto1070
  106. 1050 rem update sprite position.  exit if collision detected or 4th gap crossed
  107. 1060 pokew,peek(w)+u
  108. 1070 if(peek(v+31)and1)orpeek(v+1)>t3thenreturn
  109. 1080 rem change frequencies according to sprite y position and random number u2
  110. 1090 u=232-peek(v+1):pokesd+1,u*2/3:pokesd+8,u+3*u2:pokesd+15,u+3
  111. 1100 rem poll keyboard. exit on *; pause on ' '; goto1000 if not a function key
  112. 1110 sysch:u=peek(ar):ifu=t8thents=0:fq=1:return                 :rem exit
  113. 1120 ifu=t9thengosub8000:rem take 5
  114. 1130 ifu<t4then1000:rem input<f1
  115. 1140 rem move line right if key not shifted (1120), left if shifted (1140)
  116. 1150 u=u-132:ifu<t5then1180:rem input f1-f4
  117. 1160 ifu<t6then1200:rem input f5-f8
  118. 1170 goto1000:rem input>f8
  119. 1180 e(u)=e(u)+(e(u)=1100+200*u-(u>2)):pokee(u),223:pokee(u)-1,160
  120. 1190 poke e(u)+4+(u>2),32:pokee(u)+5+(u>2),95:e(u)=e(u)+1:goto1000
  121. 1200 u=u-4:e(u)=e(u)-(e(u)=1064+200*(u)):pokee(u)+3+(u>2),95
  122. 1210 pokee(u)+4+(u>2),160:pokee(u)-1,32:pokee(u)-2,223:e(u)=e(u)-1:goto1000
  123. 1970 rem subroutine--print game screen
  124. 1980 :
  125. 1990 rem line colours set in line 2000. last colour is for printed messages
  126. 2000 print"[147][156]"b$""b$"[154]"b$"[150]"b$"[144]"
  127. 2010 fori=1to4:pokee(i)-1,223:pokee(i)+3-(i<3),95:forj=e(i)toe(i)+2-(i<3)
  128. 2020 pokej,32:nextj,i:return       
  129. 2030 :
  130. 2980 rem subroutine--exit or re-entry
  131. 2990 :
  132. 3000 print"[147]"t$"your score:"ts
  133. 3010 print""t$"best yet:";peek(hs)-1
  134. 3020 print"play again (y/n)?
  135. 3030 [161]a$:[139]a$[178]""[167]3030
  136. 3040 [139]a$[178]"y"[167][142]
  137. 3050 [139]a$[178]"n"[167]3070
  138. 3060 [137]3030
  139. 3070 [139] [168](bs[179][194](hs))[167]3100
  140. 3080 [153]:[153]" congratulations, you broke the record.
  141. 3090 print:print" be sure to save the program.
  142. 3100 [153]:[153]" see you around.
  143. 3110 print""
  144. 3120 rem restore previous environment
  145. 3130 pokev+24,peek(2041):pokev+32,peek(2042):pokev+33,peek(2043)
  146. 3140 poke646,peek(2044):poke650,peek(2045):poke657,0
  147. 3150 end
  148. 3160 :
  149. 3980 rem subroutine--build sprite at page 13 (locations 832-895 in tape buffer)
  150. 3990 :
  151. 4000 for i=0to41:readu:poke(64*sp)+i,u:next
  152. 4010 fori=42to63:poke(64*sp)+i,0:next
  153. 4020 poke2040,sp:pokev+23,1:pokev+29,1:pokev+39,0:return
  154. 4030 return
  155. 4040 data 248,0,0,62,0,0,7,128,0,1,224
  156. 4050 data 0,0,120,0,0,62,0,0,15,112
  157. 4060 data 0,7,248,0,7,248,0,6,120,0
  158. 4070 data 6,12,0,6,6,0,3,6,0,1,128
  159. 4080 :
  160. 4980 rem data for instructions page
  161. 4990 :
  162. 5000 data"[217]our objective is to maneuver the
  163. 5010 [131]"horizontal lines so that (NULL)uper(NULL)prite
  164. 5020 data"may fly safely through the gaps.
  165. 5030 [131]"(NULL)he four lines are controlled by the
  166. 5040 data"four function keys on your right.
  167. 5050 [131]"
  168. 5060 data"[208]ressing one of these keys will cause
  169. 5070 [131]"the corresponding line to slide right.
  170. 5080 data"[212]he same key shifted will cause its
  171. 5090 [131]"line to slide left.  (NULL)ress the space
  172. 5100 data"bar to pause, '*' to abort.
  173. 5110 [131]"
  174. 5120 data"[193] game consists of 20 turns. [208]oints are
  175. 5130 [131]"awarded for every gap safely traversed.
  176. 5140 data"[212]he payoffs increase with the number of
  177. 5150 [131]"gaps traversed on a turn, and with the
  178. 5160 data"number of turns taken.  [211]uper[211]prite's
  179. 5170 [131]"flight speed and natural waywardness
  180. 5180 data"also increase as the game progresses."
  181. 5190 data"
  182. 5200 [131]"(NULL)he maximum score is 253. chr$ood luck.
  183. 5210 data"
  184. 5220 [131]"    (NULL)(NULL)val(NULL)(NULL)close(NULL)(NULL)atnlenvalclosepeekatn(NULL)close(NULL)(NULL) (NULL)(NULL)atn(NULL)(NULL)closechr$atn(NULL)val.
  185. 5230 :
  186. 5980 rem subroutine--print instructions
  187. 5990 :
  188. 6000 pokev,23:pokev+1,49:pokev+21,1
  189. 6010 gosub7000:gosub7000
  190. 6020 forw=1to23:readu$:printu$:gosub7000:nextw
  191. 6030 pokev+21,0:pokev,23:pokev+1,49:pokev+23,0:pokev+29,0
  192. 6040 geta$:ifa$<>chr$(32)then 6040
  193. 6050 return
  194. 6060 :
  195. 6980 rem subroutine--fly sprite down 1 print line (ahead of instructions)
  196. 6990 :
  197. 7000 fori=1to8:pokev,peek(v)+1
  198. 7010 pokev+1,peek(v+1)+1:next
  199. 7020 pokev,peek(v)+1:return
  200. 7030 :
  201. 7980 rem subroutine--answer the phone
  202. 7990 :
  203. 8000 poke sd+24,0
  204. 8010 sysch:ifpeek(ar)<>32then8010
  205. 8020 poke sd+24,15
  206. 8030 return
  207.