home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / c / wgt35 / examples / castle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-28  |  2.6 KB  |  118 lines

  1. #include <dos.h>
  2. #include <alloc.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <wgt.h>
  6. #include <scroll.h>
  7.  
  8. /* Very basic scrolling demo
  9.    Try starting your own scrolling game, beginning with
  10.    this one and adding more as you need it.
  11.    This program loads in the tiles, map, and objects,
  12.    and scrolls around the map using one object overtop.
  13.    This may run too fast on new computers since there is no timing control
  14.    in this demo.
  15. */
  16. int speedx,speedy;
  17. int guyanim,guydir;
  18. int ox,oy;
  19.  
  20. wgtmap castlemap;            // our world map
  21.  
  22. int kbdon[100]={0,0,0,0,0};    // our keyboard on/off array;
  23. int kbdscanlist[100]={72,80,75,77,1};    // our keyboard scan codes;
  24. // You must have the above two if you want the keyboard interrupt 
  25.  
  26. color palette[256];        // our palette of colours
  27.  
  28. block blocks[1001];        // our blocks for the map
  29. block sprites[1001];        // our sprites 
  30.  
  31. int i,guyspeed;
  32.  
  33. void main(void)
  34. {
  35. vga256();                    // init
  36. wloadsprites(&palette,"castle.spr",blocks);        // load blocks
  37. wloadsprites(&palette,"guy.spr",sprites);        // load sprites
  38.  
  39. castlemap=wloadmap("castle.wmp");        // load our world map
  40.  
  41. winitscroll(17,10);                // make a 17x10 box
  42.                         // for the scrolling
  43.  
  44. wnormscreen();                    // go back to normal screen
  45. wcls(0);                    // clear it
  46.  
  47. wshowwindow(0,0,castlemap);            // start looking at world
  48.                         // at 0,0
  49. installkbd();                    // start new keyboard interrupt
  50.  
  51. numsprites=5;
  52. wobject[0].on=1; wobject[0].x=16; wobject[0].y=16; wobject[0].num=1;
  53.  
  54. guyanim=1;
  55. guyspeed=6;
  56.  
  57. do
  58. {
  59.  
  60. speedx=0;
  61. speedy=0;
  62. ox=wobject[0].x;
  63. oy=wobject[0].y;
  64.  
  65. if (kbdon[2]==1)        // Pressing left
  66.   {
  67.   wobject[0].x-=guyspeed;
  68.   guydir=1;
  69.   guyanim++;
  70.   }
  71. else if (kbdon[3]==1)    // Pressing right
  72.   {
  73.   wobject[0].x+=guyspeed;
  74.   guydir=3;
  75.   guyanim++;
  76. }
  77. if (kbdon[0]==1)        // Pressing up
  78.   {
  79.   wobject[0].y-=guyspeed;
  80.   guydir=0;
  81.   guyanim++;
  82. }
  83. else if (kbdon[1]==1)    // Pressing down
  84.   {
  85.   wobject[0].y+=guyspeed;
  86.   guydir=2;
  87.   guyanim++;
  88. }
  89.  
  90.  
  91. if (guyanim>4)
  92.   guyanim=1;
  93. wobject[0].num=guyanim+(guydir*4);
  94.  
  95. if (wobject[0].x-worldx<windowmaxx/2-20)
  96.    speedx=-guyspeed;
  97. else if (wobject[0].x-worldx>windowmaxx/2+20)
  98.    speedx=guyspeed;
  99. if (wobject[0].y-worldy<windowmaxy/2-1)
  100.    speedy=-guyspeed;
  101. else if (wobject[0].y-worldy>windowmaxy/2+20)
  102.    speedy=guyspeed;
  103.  
  104. wscrollwindow(speedx,speedy,castlemap);    // update the scrolling window
  105. wshowobjects();
  106. wcopyscroll(0,0);
  107. } while (kbdon[4] !=1);            // until right button is pressed
  108.  
  109. uninstallkbd();
  110.  
  111. wendscroll();
  112. wfreesprites(blocks);
  113. wfreesprites(sprites);
  114. free(castlemap);
  115. textmode(C80);
  116. }
  117.  
  118.