home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / demos / planet / build / demo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-07  |  1.6 KB  |  103 lines

  1. #include <fastgraf.h>
  2. #include <string.h>
  3. #include "demo.h"
  4.  
  5. const int IMAGENO = 1;
  6.  
  7. Sprite::Sprite(char* gfxlibname,char* sfxlibname)
  8.   {
  9.   strcpy(gfxlib,gfxlibname);
  10.   strcpy(sfxlib,sfxlibname);
  11.   image=IMAGENO;
  12.   }
  13.  
  14. void Sprite::initialize()
  15.   {
  16.   load_gfxlib(gfxlib);
  17.   load_sfxlib(sfxlib);
  18.   w=get_image_width(image);
  19.   h=get_image_height(image);
  20.   xq[0]=xq[1]=0;
  21.   yq[0]=yq[1]=0;
  22.   }
  23.  
  24. void Sprite::bounce()
  25.   {
  26.   play_sound_clip(1);
  27.   }
  28.  
  29. void Sprite::move_to(int newx,int newy)
  30.   {
  31.   static int qi;
  32.   VideoDirector::restore_patch(xq[qi],yq[qi],xq[qi]+w-1,yq[qi]+h-1);
  33.   show_image(newx,newy,image);
  34.   xq[qi]=newx;
  35.   yq[qi]=newy;
  36.  
  37.   qi=(qi+1)%2;
  38.   }
  39.  
  40. CUELIST(DemoDirector)
  41.   TIMER(18,on_timer)
  42.   KEYSTROKE(ESC,on_esc)
  43. ENDCUELIST
  44.  
  45. DemoDirector::DemoDirector()
  46.   {
  47.   moon=new Sprite("demo.gfx","demo.sfx");
  48.   x=y=20;
  49.   xinc=yinc=INC;
  50.   }
  51.  
  52. void DemoDirector::display()
  53.   {
  54.   init_video();
  55.   show_pcx("planet.pcx");
  56.   swap_video_pages();
  57.   synch_video_pages();
  58.   fill_background_buffer(active_page());
  59.   }
  60.  
  61. void DemoDirector::on_timer()
  62.   {
  63.   moon->move_to(x+=xinc,y+=yinc);
  64.   swap_video_pages();
  65.  
  66.   if (x<5 || x>280)
  67.     {
  68.     xinc=-xinc;
  69.     moon->bounce();
  70.     }
  71.   if (y<5 || y>190)
  72.     {
  73.     yinc=-yinc;
  74.     moon->bounce();
  75.     }
  76.   }
  77.  
  78. void DemoDirector::on_esc(int)
  79.   { 
  80.   stop_director();
  81.   }
  82.  
  83. class PlanetDemo : public Theatrix
  84.   {
  85. public:
  86.   PlanetDemo() : Theatrix("Planet")
  87.     {
  88.     demo=new DemoDirector; 
  89.     }
  90.   ~PlanetDemo()
  91.     {
  92.     delete demo;
  93.     }
  94. private:
  95.   DemoDirector* demo; 
  96.   }; 
  97.  
  98. void main()
  99.   {
  100.   PlanetDemo demo;
  101.   demo.go();
  102.   }
  103.