A demo using sprites and background(BG).

  1. '+------------------+
  2. '|SAMPLE9
  3. '| SPRITE/BG related
  4. '+------------------+
  5. CLEAR

  6. '--- Initialize MENU
  7. MENUMAX=6
  8. DIM MENU$(MENUMAX)
  9. DIM INFO$(MENUMAX)

  10. FOR I=0 TO MENUMAX-1
  11. READ MENU$(I)
  12. READ INFO$(I)
  13. NEXT

  14. DATA "SPGETV/SPSETV"
  15. DATA "Information to SPRITE R/W"
  16. DATA "SPCOL/SPHIT"
  17. DATA "Detect a collision of SPRITE"
  18. DATA "SPHOME"
  19. DATA "SPRITE Set the base coordinate"
  20. DATA "SPREAD/SPCHK"
  21. DATA "Read the status of SPRITE"
  22. DATA "BGFILL/BGCOPY/BGCLR"
  23. DATA "Fill BG/Copy BG/Clear BG"
  24. DATA "BGCHK/BGREAD"
  25. DATA "Read BG state/Read BG CHR"

  26. '--- MAIN LOOP
  27. @MAIN
  28. ACLS
  29. COLOR 0
  30. PRINT "+-------------------------+"
  31. PRINT "|SAMPLE9 |"
  32. PRINT "| Command of SPRITE and BG|"
  33. PRINT "+-------------------------+"

  34. FOR I=0 TO MENUMAX-1
  35. Y=I*3+4
  36. COLOR 9
  37. LOCATE 0,Y
  38. PRINT I+1;" ";
  39. COLOR 0
  40. PRINT MENU$(I);" ";
  41. COLOR 3
  42. LOCATE 2,Y+1
  43. PRINT INFO$(I)
  44. NEXT

  45. COLOR 0
  46. LOCATE 0,22
  47. INPUT "Ж:Please select(0=END)";CMD
  48. CLS
  49. IF CMD<=0 THEN END
  50. IF CMD>MENUMAX THEN @MAIN
  51. COLOR 3
  52. PRINT "-------------------------------"
  53. PRINT
  54. PRINT MENU$(CMD-1):PRINT
  55. PRINT " ";INFO$(CMD-1)
  56. PRINT "-------------------------------"
  57. COLOR 7
  58. PRINT "Execute example:":PRINT
  59. COLOR 0

  60. IF CMD==1 THEN GOSUB @TEST1
  61. IF CMD==2 THEN GOSUB @TEST2
  62. IF CMD==3 THEN GOSUB @TEST3
  63. IF CMD==4 THEN GOSUB @TEST4
  64. IF CMD==5 THEN GOSUB @TEST5
  65. IF CMD==6 THEN GOSUB @TEST6

  66. GOSUB @HITANY
  67. GOTO @MAIN


  68. '--- SPGETV/SPSETV
  69. @TEST1
  70. PAL=2
  71. NUM = 0 'SPRITE No.
  72. PRINT "Random number to read and write to a user variable"
  73. COLOR 3
  74. SPSET NUM,68,PAL,0,0,1
  75. SPOFS NUM,128,160
  76. FOR I=0 TO 7
  77. VL=RND(10000)
  78. SPSETV NUM,I,VL
  79. LOCATE 0,10+I
  80. PRINT VL;" → HENSU(";I;")"
  81. NEXT
  82. COLOR 4
  83. FOR I=0 TO 7
  84. VL=SPGETV(NUM,I)
  85. LOCATE 16,10+I
  86. PRINT "HENSU(";I;") → ";VL
  87. NEXT
  88. RETURN

  89. '--- SPCOL/SPHIT
  90. @TEST2

  91. PAL=12
  92. AN=0 'SPRITE No.
  93. FN=10 'SPRITE No.
  94. AW=16 'WIDTH
  95. AH=32 'HEIGHT
  96. AX=128:AY=96
  97. AX1=2:AY1=1

  98. SPSET AN,288,PAL,0,0,2,AW,AH
  99. SPCOL AN,-AW/2,-AH/2,AW,AH,FALSE
  100. SPHOME AN,AW/2,AH/2

  101. FMAX=8 'TEKI MAX
  102. FW=16 'WIDTH
  103. FH=16 'HEIGHT

  104. FOR I=0 TO FMAX-1
  105. NUM = FN+I
  106. SCL = 200
  107. CH = 137

  108. SPSET NUM,CH,PAL,0,0,2
  109. SPSCALE NUM,SCL
  110. FX=48 + ((I%4)*48)
  111. FY=72 + FLOOR(I/4)*48
  112. SPHOME NUM,FW/2,FH/2
  113. SPCOL NUM,-FW/2,-FH/2,FW,FH,TRUE
  114. SPOFS NUM,FX,FY
  115. LOCATE FX/8-2,FY/8+2
  116. PRINT "NO.";NUM

  117. NEXT

  118. FOR I=0 TO 600
  119. IF AX<8 OR AX>246 THEN AX1=-AX1
  120. IF AY<16 OR AY>174 THEN AY1=-AY1

  121. AX=AX+AX1:AY=AY+AY1
  122. SPOFS AN,AX,AY

  123. HIT=SPHIT(AN,0)
  124. COLOR 0
  125. LOCATE 1,19
  126. PRINT "SPRITE function return value:";
  127. IF HIT THEN COLOR 13
  128. PRINT HIT;
  129. PRINT
  130. COLOR 0
  131. LOCATE 1,21
  132. PRINT "Value of the SPRITE No.:";
  133. COLOR 4
  134. PRINT SPHITNO;" "
  135. VSYNC 1
  136. NEXT

  137. RETURN

  138. '--- SPHOME
  139. @TEST3

  140. PAL=4
  141. NUM = 0 'SPRITE No.
  142. AW=16 'WIDTH
  143. AH=16 'HEIGHT
  144. CH=68
  145. SCL = 200
  146. AX = 128
  147. AY = 96
  148. ANG = 359
  149. DIR = 1

  150. SPSET NUM,CH,PAL,0,0,2
  151. SPOFS NUM,AX,AY
  152. SPSCALE NUM,SCL

  153. GLINE AX,AY-32,AX,AY+32,2
  154. GLINE AX-32,AY,AX+32,AY,2

  155. GOSUB @PUTCMD

  156. HX = 0:HY = 0
  157. GOSUB @TURNSUB

  158. HX = AW/2:HY = AH/2
  159. GOSUB @TURNSUB

  160. HX = AW-1:HY = AH-1
  161. GOSUB @TURNSUB
  162. RETURN

  163. '---
  164. @TURNSUB
  165. PRINT "Rotateing coordinate (";HX;",";HY;")"
  166. PRINT
  167. SPHOME NUM,HX,HY
  168. SPANGLE NUM,0
  169. VSYNC 1
  170. SPANGLE NUM,ANG,180,DIR

  171. @SPBUSY
  172. VSYNC 1
  173. IF SPCHK(AN) THEN @SPBUSY
  174. RETURN

  175. '--- SPREAD/SPCHK
  176. @TEST4

  177. PAL=4
  178. AN=0 'SPRITE No.
  179. AMAX=12 'MAX
  180. AW=16 'WIDTH
  181. AH=16 'HEIGHT

  182. FOR I=0 TO AMAX-1

  183. NUM = AN+I
  184. SCL = 100 'Scale
  185. CH = RND(256)
  186. ANG = 0
  187. SEC = RND(9)+1 'Keep time
  188. SPSET NUM,CH,PAL,0,0,2
  189. SPSCALE NUM,SCL
  190. SPHOME NUM,AW/2,AH/2
  191. SPOFS NUM,128,8
  192. VSYNC 1
  193. AX=240:AY=8+(I*16)
  194. SPOFS NUM,AX,AY,60*SEC

  195. NEXT

  196. TY=8
  197. LOCATE 1,TY-1
  198. PRINT "SPREAD/SPCHK return value"

  199. @SPRMAIN
  200. BUSY=0
  201. FOR I=0 TO AMAX-1
  202. NUM = AN+I
  203. SPREAD(NUM),AX,AY,ANG,SCL,CH
  204. SPC=SPCHK(NUM)

  205. COLOR 0
  206. LOCATE 0,TY+I
  207. PRINT NUM;":";
  208. LOCATE 3,TY+I
  209. PRINT "(";AX
  210. LOCATE 7,TY+I
  211. PRINT ",";AY;")"
  212. COLOR 0
  213. LOCATE 13,TY+I
  214. PRINT " SPCHK=";
  215. IF SPC THEN COLOR 4 ELSE COLOR 0
  216. PRINT SPC;
  217. VSYNC 1
  218. BUSY=BUSY+SPC
  219. NEXT
  220. IF BUSY THEN @SPRMAIN
  221. RETURN

  222. '--- BGFILL/BGCOPY/BGCLR
  223. @TEST5
  224. PAL=9 'Palette
  225. LOCATE 0,8
  226. PRINT "RUN BGFILL command"
  227. LAY=0
  228. X1=8:Y1=9
  229. X2=50:Y2=14
  230. CH=32
  231. H=0:V=0
  232. BGFILL LAY,X1,Y1,X2,Y2,CH,PAL,0,0
  233. WAIT 180

  234. X1=0 :Y1=15
  235. X2=X1+10:Y2=Y1+4
  236. FOR Y=0 TO (Y2-Y1)
  237. FOR X=0 TO (X2-X1)
  238. CH=X+(Y*32)
  239. BGPUT LAY,X1+X,Y1+Y,CH,PAL,0,0
  240. NEXT
  241. NEXT
  242. LOCATE 0,13
  243. PRINT "RUN BGCOPY command"
  244. PRINT "From COPY → to COPY"
  245. X3=X1+16:Y3=Y1
  246. BGCOPY LAY,X1,Y1,X2,Y2,X3,Y3
  247. WAIT 180

  248. GOSUB @HITANY
  249. COLOR 0
  250. LOCATE 0,21
  251. PRINT "RUN BGCLR command"
  252. BGCLR LAY

  253. RETURN

  254. @BGBUSY
  255. VSYNC 1
  256. BUSY=BGCHK(LAY)
  257. LOCATE 0,14
  258. COLOR 0
  259. PRINT "BGCHK return value:";
  260. IF BUSY THEN COLOR 3
  261. PRINT BUSY
  262. IF BUSY THEN @BGBUSY
  263. '0 = end
  264. RETURN

  265. '--- BGCHK/BGREAD
  266. @TEST6

  267. PAL=9 'Palette
  268. LAY=0
  269. X1=0 :Y1=10
  270. X2=X1+31:Y2=Y1+4
  271. FOR Y=0 TO (Y2-Y1)-1
  272. FOR X=0 TO (X2-X1)-1
  273. CH=X+(Y*32)
  274. BGPUT LAY,X1+X,Y1+Y,CH,PAL,0,0
  275. NEXT
  276. NEXT

  277. LOCATE 0,8
  278. PRINT "Getting information by"
  279. PRINT "BGCHK Function"

  280. BX=511:BY=511:SEC=3
  281. BGOFS LAY,BX,BY,60*SEC
  282. GOSUB @BGBUSY
  283. WAIT 60
  284. BX=0:BY=0:SEC=3
  285. BGOFS LAY,BX,BY,60*SEC
  286. GOSUB @BGBUSY

  287. WAIT 60

  288. SC$=""
  289. X=FLOOR((X1+X2)/2)
  290. Y=FLOOR((Y1+Y2)/2)
  291. LOCATE 0,16
  292. PRINT "RUN BGREAD"
  293. BGREAD(LAY,X,Y),SC$ '
  294. PRINT " X=";X;",Y=";Y
  295. PRINT "Return value :";SC$
  296. PRINT "(FOUR-DIGIT hexadecimal)"
  297. PRINT
  298. PRINT "Code ";SC$" is run BGPUT ="
  299. X=25:Y=21
  300. BGPUT LAY,X,Y,SC$
  301. 'Four-digit hexadecimal

  302. RETURN

  303. '--- Command Name
  304. @PUTCMD
  305. PRINT
  306. COLOR 4
  307. PRINT " ";
  308. PRINT "RUN ";MENU$(CMD-1)
  309. PRINT " ↓"
  310. COLOR 0
  311. PRINT
  312. RETURN

  313. '---
  314. @HITANY
  315. GOSUB @KEYOFF
  316. @HITANY2
  317. COLOR RND(13)+1
  318. LOCATE 7,23
  319. PRINT "HIT ANY BUTTON";
  320. VSYNC 5
  321. IF BUTTON() THEN RETURN
  322. GOTO @HITANY2

  323. '---
  324. @KEYOFF
  325. IF BUTTON() THEN @KEYOFF
  326. RETURN

  327. '+-------------------------+
  328. '| end |
  329. '+-------------------------+