home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / w / wgt3_ex.zip / WGT18.C < prev    next >
C/C++ Source or Header  |  1992-09-08  |  3KB  |  78 lines

  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <wgt.h>
  4. /*   WORDUP Graphics Toolkit   Version 3.0
  5.      Demonstration program 18
  6.  
  7. This program shows how to make animation with two screens.
  8.  
  9. One way to produce animation is to use two screens.  One screen is
  10. constantly displayed while you draw things on the other.  Once the
  11. drawing is complete, you then copy the whole screen in the background
  12. to the one that is being displayed.
  13.  
  14.  
  15.         Visual Screen               Background Screen
  16.     ..............................          ..............................
  17.     ......o.......................          ......o..............o........
  18.     ...../Y\......................          ...../Y\............/Y\.......
  19.     ......|.......................          ......|..............|........
  20.     ...../.\......................          ...../.\............/.\.......
  21.     ..............................          ..............................
  22.     ..............................          .Pos 1-> Clear Screen ->Pos 2.
  23.     ..............................          ..............................
  24.  
  25. Here we have a person shown on the visual page. It has just been copied
  26. over from the background screen. Now you must clear the background screen
  27. somehow (put a picture over top, or wcls(0) it).  Once it is cleared, you
  28. can use putblock to show the person in a different place on the screen.
  29. Then you copy the background screen to the visual screen and repeat the
  30. process.  This method is slow, but can be sped up by decreasing the number
  31. of putblocks you use as sprites, and make the area copied from one screen
  32. to another smaller.
  33.  
  34.  
  35. */
  36.  
  37. block screen1,circ;        // one virtual screen and our sprite circ
  38. int y;
  39.  
  40. void main(void)
  41. {
  42. vga256();        // initializes system
  43.  
  44. screen1=wnewblock(0,0,319,199);
  45.  
  46. wsetcolor(40);
  47. wfill_circle(30,30,20);        // draw a circle with a box cut out in middle
  48. wsetcolor(0);
  49. wbar(20,20,40,40);
  50.  
  51. circ=wnewblock(10,10,50,50);        // get the sprite
  52.  
  53.  
  54. wsetscreen(screen1);        // sets to screen1
  55.  
  56. do {
  57. mread();
  58. for (y=0; y<200; y++)
  59.   {
  60.   wsetcolor(y);
  61.   wline(0,y,319,y);        // clear the screen by drawing horz lines (fast)
  62.   }
  63.  
  64. wputblock(mx,my,circ,1);    // put the block using xray mode at mouse position
  65. wputblock(319-mx,my,circ,1);
  66. wputblock(mx,199-my,circ,1);
  67. wputblock(319-mx,199-my,circ,1);
  68. wcopyscreen(0,0,319,199,screen1,0,0,NULL);  // copy the whole screen
  69. // notice how we never use wnormscreen at all!
  70.  
  71. } while (but==0);
  72.  
  73.  
  74.  
  75. wfreeblock(screen1);    // remember to free that memory
  76. wfreeblock(circ);
  77. textmode(C80);                // used to return to text mode
  78. }