home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / WGT_TC21.ZIP / WGT22.C < prev    next >
C/C++ Source or Header  |  1992-07-17  |  2KB  |  86 lines

  1. // This is a small program 'template' to help you get started
  2. // with the sprites library.
  3.  
  4. /*   WORDUP Graphics Toolkit   Version 2.1
  5.      Demonstration program 22
  6.  
  7.      Sprite program template.
  8.  
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <dos.h>
  13. #include <conio.h>
  14. #include <stdlib.h>
  15. #include <alloc.h>
  16. #include "c:\tc\wgt\wgt.h"
  17. #include "c:\tc\wgt\spr.h"
  18.  
  19. color palette[256];            // the palette
  20. block sprites[201];            // all the sprites
  21. int quit;                // if quit !=0, program quits
  22.  
  23. void looper(void);            // a routine which controls the sprites
  24.  
  25. void main(void)
  26. {
  27. vga256();
  28. wloadsprites(&palette,"c:\\tc\\wgt\\invader.spr",sprites);    // load them
  29. initspr();                    // initialize them
  30. spon=10;                    // number of sprites on
  31.  
  32. spriteon(1,160,100,1);                // turn on any sprites
  33. spriteon(2,10,100,3);                // you need
  34.  
  35. // Spriteon has the following format:
  36. // Sprite number, x coord, y coord, sprite number in array of sprites
  37. // Therefore sprite #1 would be displayed at 160,100 with sprite 1 in the array
  38.  
  39.  
  40. movex(2,"(1,300,0)(-1,300,0)R");        // set up any movement
  41. movexon(2);                    // or animation needed
  42.  
  43. // This move will go left 1, for 300 times, and right 1 for 300 times,
  44. // and repeat
  45.  
  46. animate(2,"(3,50)(4,50)(5,50)(4,50)R");
  47. animon(2);
  48.  
  49. // This animation will animate sprite 2 through a sequence of sprites
  50. // in the sprite array and keep repeating.
  51.  
  52. wsetscreen(spritescreen);
  53.  
  54. do {
  55. looper();
  56. } while (!quit);
  57.  
  58.  
  59. spriteoff(1);            // turn off sprites
  60. spriteoff(2);
  61. // To be safe, turn off all sprites before ending program.
  62. // This will free any memory used from them.
  63.  
  64.  
  65. wfreesprites(sprites);        // free memory
  66. wfreeblock(spritescreen);
  67. wcls(0);
  68. textmode(C80);
  69. }
  70.  
  71.  
  72. void looper(void)
  73. {
  74. erasespr();            // clear the sprites
  75.  
  76. mread();
  77. s[1].x=mx;            // any direct sprite movements must be placed
  78. s[1].y=my;            // between erasespr and drawspr
  79. // notice how sprite #2 moves and animates on its own now!
  80. // You don't need to change anything to make it move!
  81.  
  82.  
  83. drawspr();            // draw them back on
  84. if (kbhit()) quit=1;
  85. }
  86.