home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / demos / mfighter / build / bar.cpp next >
Encoding:
C/C++ Source or Header  |  1995-04-26  |  1.3 KB  |  76 lines

  1. #include <fastgraf.h>
  2. #include "fighter.h"
  3. #include "game.h"
  4. #include "bar.h"
  5.  
  6. const int GREEN = 207;
  7. const int BLUE = 230;
  8.  
  9. const int BARX1 = 30;
  10. const int BARX2 = 190;
  11. const int BARY = 20;
  12. const int BARH = 2;
  13. const int BARLEN = 100;
  14.  
  15. const int FRAME_XPOS = -6;
  16. const int FRAME_YPOS = BARY-6;
  17.  
  18. CUELIST(LifeBar)
  19.   MESSAGE(GOT_PUNCHED, on_hit)
  20.   MESSAGE(GOT_KICKED, on_hit)
  21. ENDCUELIST
  22.  
  23. LifeBar::LifeBar(Director* d,Fighter* f,int s) : Performer(d)
  24.   {
  25.   fighter=f;
  26.   side=s;
  27.  
  28.   if (side==LEFTGUY)
  29.     {
  30.     imageno=3;
  31.     x=BARX1;
  32.     color=GREEN;
  33.     }
  34.   else
  35.     {
  36.     imageno=4;
  37.     x=BARX2;
  38.     color=BLUE;
  39.     }
  40.   }
  41.  
  42. void LifeBar::initialize()
  43.   {
  44.   load_gfxlib("cards.gfx");
  45.   set_gfxlib("cards.gfx");
  46.   }
  47.  
  48. void LifeBar::display()
  49.   {
  50. // show frame
  51.   show_image(x+FRAME_XPOS,FRAME_YPOS,imageno);
  52.   update(0);
  53.   }
  54.  
  55. void LifeBar::update(int damage)
  56.   {
  57.   if (damage<0)  damage=0;
  58.   else if (damage>100)  damage=100;
  59.  
  60.   fg_setcolor(color);
  61.   fg_rect(x,x+BARLEN-damage,BARY,BARY+BARH);
  62.   fg_setcolor(0);
  63.   fg_rect(x+BARLEN-damage,x+BARLEN,BARY,BARY+BARH);
  64.  
  65.   int page=fg_getpage();      // future
  66.   fg_transfer(x,x+BARLEN,BARY,BARY+BARH,x,BARY+BARH,page,1-page);
  67.   }
  68.  
  69. void LifeBar::on_hit(int,int data)
  70.   {
  71.   if (data!=side)  return;
  72.  
  73.   update(fighter->get_damage());
  74.   }
  75.  
  76.