home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / basicaid.zip / ANIMATE.BAS < prev    next >
BASIC Source File  |  1980-01-01  |  4KB  |  97 lines

  1. 1 REM This is a sample program that illustrates how to use several of
  2. 2 REM the BASICA graphics commands.  Specifically, animation of objects
  3. 3 REM is presented ... along with how to display lines, boxes, and circles.
  4. 4 REM
  5. 5 REM
  6. 6 REM  The following statement defines the Graphics Array where objects will
  7. 7 REM  be saved.
  8. 8 REM
  9. 10 DIM OBJ$(1000)
  10. 11 REM
  11. 12 REM  The following statement sets up error handling.
  12. 13 REM
  13. 15 ON ERROR GOTO 20000
  14. 16 REM
  15. 17 REM  The following few statements check to see if the color monitor
  16. 18 REM  is being used.  If it is, control is transferred to stmt 140.
  17. 19 REM  If not, BASIC statements are executed that cause the color
  18. 20 REM  monitor to be activated.
  19. 21 REM
  20. 25 DEF SEG=0
  21. 30 IF (PEEK(&H410) AND &H30) <> &H30 THEN DEF SEG: GOTO 140
  22. 40 KEY OFF
  23. 50 CLS
  24. 60 WIDTH 80: DEF SEG=0: A=PEEK(&H410): POKE &H410,(A AND &HCF) OR &H20
  25. 70 WIDTH  40 :SCREEN 1: SCREEN 0: LOCATE ,,1,6,7
  26. 80 KEY OFF
  27. 90 SCREEN 0,1
  28. 100 COLOR 15,9,4
  29. 110 WIDTH 40
  30. 140 REM
  31. 141 REM The following statements set the appropriate color for the
  32. 142 REM program and screen width.  COLOR  0,0 means that background
  33. 143 REM is going to be black, with color palette 0 chosen.  This palette
  34. 144 REM allows us to use the colors black, green, red, and brown.
  35. 145 REM
  36. 150 WIDTH 40:COLOR 0,0:SCREEN 1,0:CLS:LOCATE 2,1
  37. 160 REM
  38. 161 REM Now we begin doing some real graphics processing.  We will begin
  39. 162 REM by drawing the object we wish to animate.  Then we will store it
  40. 163 REM into our array (obj$) for use later in the program.
  41. 164 REM
  42. 170 LINE (1,1)-(31,31),3,B ' draw a box
  43. 180 CIRCLE (16,16),14,2  ' draw a circle within the box
  44. 185 PAINT (16,16),2
  45. 190 GET (1,1)-(31,31),OBJ$ ' save object into array
  46. 200 CLS
  47. 260 REM
  48. 261 REM Now we get down to business.  We begin by drawing some lines on the
  49. 262 REM screen that will be used as a background.  These lines need not be
  50. 263 REM here, but are used for visual effect.
  51. 264 REM
  52. 270 FOR X%=1 TO 319 STEP 15
  53. 280 LINE (X%,1)-(X%,199),1
  54. 290 NEXT
  55. 300 FOR Y%=1 TO 199 STEP 15
  56. 310 LINE (1,Y%)-(319,Y%),1
  57. 320 NEXT
  58. 400 REM
  59. 401 REM Now we begin doing the animation process.  This particular program
  60. 402 REM allows the object to randomly move about the screen until it "hits"
  61. 403 REM the edge of the screen.  Once this occurs, the direction changes
  62. 404 REM and movement continues.  To stop the program requires the ESC key
  63. 405 REM to be pressed.
  64. 406 REM
  65. 410 X%=100:Y%=100:PUT (X%,Y%),OBJ$,XOR
  66. 420 DIREC%=1:YDIREC%=0:QUITIT=0:SPEED%=1
  67. 430 WHILE QUITIT=0
  68. 440 NEWX%=X%+DIREC%*SPEED%:IF NEWX%>287 THEN DIREC%=-1:GOTO 440 ELSE IF NEWX%<1 THEN DIREC%=1:GOTO 440  ' compute new x coordinate
  69. 450 NEWY%=Y%+YDIREC%*SPEED%:IF NEWY%>167 THEN YDIREC%=-1:GOTO 450 ELSE IF NEWY%<1 THEN YDIREC%=1:GOTO 450   ' compute new y coordinate
  70. 455 REM Check for arrow keys or carrots (<,>). Arrows control direction.
  71. 456 REM Carrots control speed (<=slow down, >=speed up)
  72. 460 K$=INKEY$:IF K$="" THEN 540
  73. 470 IF K$=CHR$(0)+CHR$(77) THEN DIREC%=1
  74. 480 IF K$=CHR$(0)+CHR$(75) THEN DIREC%=-1
  75. 490 IF K$=CHR$(0)+CHR$(72) THEN YDIREC%=-1
  76. 500 IF K$=CHR$(0)+CHR$(80) THEN YDIREC%=1
  77. 510 IF K$=CHR$(62) THEN SPEED%=SPEED%+1
  78. 520 IF K$=CHR$(60) THEN SPEED%=SPEED%-1:IF SPEED%<0 THEN SPEED%=0
  79. 530 IF K$=CHR$(27) THEN QUITIT=1
  80. 531 REM
  81. 532 REM Display graphics image at new location
  82. 533 REM
  83. 540 PUT (NEWX%,NEWY%),OBJ$,XOR
  84. 541 REM
  85. 542 REM Erase graphics image at old location
  86. 543 REM
  87. 550 PUT (X%,Y%),OBJ$,XOR
  88. 560 X%=NEWX%:Y%=NEWY%
  89. 570 WEND
  90. 580 LOCATE 23,1
  91. 590 CLS:RUN "MENU.PGM"
  92. 20000 PRINT "error encountered";ERL;"=error line";:RESUME
  93. =NEWX%:Y%=NEWY%
  94. 570 WEND
  95. 580 LOCATE 23,1
  96. 590 CLS:RUN "MENU.PGM"
  97. 20000 PRINT "error encountered";E