home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1986 June / Ahoy_Magazine_86-06_1986_Double_L.d64 / sprite animation < prev    next >
Encoding:
Text File  |  1986-01-01  |  2.0 KB  |  68 lines

  1. THE WALKER
  2.  
  3. by Captain COMAL
  4.  
  5. There is no need to be frightened of
  6. sprites. COMAL adds simple commands
  7. to easily control all 8 sprites at
  8. once. WALKER is a simple program that
  9. animates a sprite using 4 shapes. Try
  10. the program. Watch the WALKER hobble
  11. across the screen. COMAL is so fast
  12. that a pause routine is added to slow
  13. the WALKER down.
  14.  
  15. The whole program is merely 5 lines
  16. long. Well, actually more if you
  17. count all the procedures too. It
  18. takes advantage of COMAL's modular
  19. nature, and sets up procedures to
  20. perform the several routines needed.
  21. The first one is called SETUP. As you
  22. might guess it sets up things for the
  23. program. Before setting up the sprite
  24. colors and size the SETUP procedure,
  25. calls DEFINE'IMAGES. Now, that is
  26. where the sprite shapes are
  27. determined - all four of them.
  28.  
  29. Sprite images are defined by a 63
  30. byte string, just as in BASIC. But
  31. COMAL does all the work. DEFINE puts
  32. the images in a special reserved area
  33. of memory for you! No PEEK or POKE
  34. needed. Then IDENTIFY lets any sprite
  35. use any of the defined shapes at any
  36. time, even simultaneously. But why
  37. use a 64 byte string to DEFINE our
  38. shapes? Only 63 are for the shape
  39. itself! If the 64th byte is a CHR$(0)
  40. it tells COMAL that the sprite is
  41. Hi-Res. Otherwise the sprite will be
  42. Multi-Color (like in this program).
  43. Lines 240-260 show how easy it is to
  44. set up the colors for our sprites, as
  45. well as to choose to expand their
  46. size.
  47.  
  48. The rest of the program is a simple
  49. REPEAT loop. It continues WALKING
  50. until you press the Q key. WALKING
  51. keeps moving our sprite across the
  52. screen while animating the images.
  53. SPRITEPOS in line 520 changes its
  54. position while IDENTIFY in line 530
  55. gives it an image. Then line 540
  56. pauses a bit. Change the (30) to
  57. something smaller for a shorter
  58. pause. Remove the line altogether for
  59. some really fast walking.
  60.  
  61. Finally, notice the use of MOD in
  62. lines 510 and 530. It does a division
  63. and throws away the answer. The only
  64. thing it remembers is the remainder.
  65. Thus 9 MOD 4 is 1, the remainder of 9
  66. divided by 4. This is a convenient
  67. way to have images cycle by fours.
  68.