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 / CASTLE.C < prev    next >
C/C++ Source or Header  |  1992-09-15  |  3KB  |  117 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.  
  14. int speedx,speedy;
  15. int guyanim,guydir;
  16. int ox,oy;
  17. int counter=0;
  18.  
  19. wgtmap castlemap;            // our world map
  20.  
  21. int kbdon[35]={0,0,0,0,0};    // our keyboard on/off array;
  22. int kbdscanlist[35]={72,80,75,77,1};    // our keyboard scan codes;
  23. // You must have the above two if you want the keyboard interrupt 
  24.  
  25. color palette[256];        // our palette of colours
  26.  
  27. block blocks[201];        // our blocks for the map
  28. block sprites[201];        // our sprites 
  29.  
  30. int i,guyspeed;
  31.  
  32. void main(void)
  33. {
  34. vga256();                    // init
  35. wloadsprites(&palette,"castle.spr",blocks);        // load blocks
  36. wloadsprites(&palette,"guy.spr",sprites);        // load sprites
  37.  
  38. castlemap=wloadmap("castle.wmp");        // load our world map
  39.  
  40. winitscroll(17,10);                // make a 17x10 box
  41.                         // for the scrolling
  42.  
  43. wnormscreen();                    // go back to normal screen
  44. wcls(0);                    // clear it
  45.  
  46. wshowwindow(0,0,castlemap);            // start looking at world
  47.                         // at 0,0
  48. installkbd();                    // start new keyboard interrupt
  49.  
  50. numsprites=5;
  51. wobject[0].on=1; wobject[0].x=16; wobject[0].y=16; wobject[0].num=1;
  52.  
  53. guyanim=1;
  54. guyspeed=6;
  55.  
  56. do
  57. {
  58.  
  59. speedx=0;
  60. speedy=0;
  61. ox=wobject[0].x;
  62. oy=wobject[0].y;
  63.  
  64. if (kbdon[2]==1)        // Pressing left
  65.   {
  66.   wobject[0].x-=guyspeed;
  67.   guydir=1;
  68.   guyanim++;
  69.   }
  70. else if (kbdon[3]==1)    // Pressing right
  71.   {
  72.   wobject[0].x+=guyspeed;
  73.   guydir=3;
  74.   guyanim++;
  75. }
  76. if (kbdon[0]==1)        // Pressing up
  77.   {
  78.   wobject[0].y-=guyspeed;
  79.   guydir=0;
  80.   guyanim++;
  81. }
  82. else if (kbdon[1]==1)    // Pressing down
  83.   {
  84.   wobject[0].y+=guyspeed;
  85.   guydir=2;
  86.   guyanim++;
  87. }
  88.  
  89.  
  90. if (guyanim>4)
  91.   guyanim=1;
  92. wobject[0].num=guyanim+(guydir*4);
  93.  
  94. if (wobject[0].x-worldx<windowmaxx/2-20)
  95.    speedx=-guyspeed;
  96. else if (wobject[0].x-worldx>windowmaxx/2+20)
  97.    speedx=guyspeed;
  98. if (wobject[0].y-worldy<windowmaxy/2-1)
  99.    speedy=-guyspeed;
  100. else if (wobject[0].y-worldy>windowmaxy/2+20)
  101.    speedy=guyspeed;
  102.  
  103. wscrollwindow(speedx,speedy,castlemap);    // update the scrolling window
  104. wshowobjects();
  105. wcopyscroll(0,0);
  106. } while (kbdon[4] !=1);            // until right button is pressed
  107.  
  108. uninstallkbd();
  109.  
  110. wendscroll();
  111. wfreesprites(blocks);
  112. wfreesprites(sprites);
  113. free(castlemap);
  114. textmode(C80);
  115. }
  116.  
  117.