home *** CD-ROM | disk | FTP | other *** search
- #include <fastgraf.h>
- #include "fighter.h"
- #include "game.h"
- #include "bar.h"
-
- const int GREEN = 207;
- const int BLUE = 230;
-
- const int BARX1 = 30;
- const int BARX2 = 190;
- const int BARY = 20;
- const int BARH = 2;
- const int BARLEN = 100;
-
- const int FRAME_XPOS = -6;
- const int FRAME_YPOS = BARY-6;
-
- CUELIST(LifeBar)
- MESSAGE(GOT_PUNCHED, on_hit)
- MESSAGE(GOT_KICKED, on_hit)
- ENDCUELIST
-
- LifeBar::LifeBar(Director* d,Fighter* f,int s) : Performer(d)
- {
- fighter=f;
- side=s;
-
- if (side==LEFTGUY)
- {
- imageno=3;
- x=BARX1;
- color=GREEN;
- }
- else
- {
- imageno=4;
- x=BARX2;
- color=BLUE;
- }
- }
-
- void LifeBar::initialize()
- {
- load_gfxlib("cards.gfx");
- set_gfxlib("cards.gfx");
- }
-
- void LifeBar::display()
- {
- // show frame
- show_image(x+FRAME_XPOS,FRAME_YPOS,imageno);
- update(0);
- }
-
- void LifeBar::update(int damage)
- {
- if (damage<0) damage=0;
- else if (damage>100) damage=100;
-
- fg_setcolor(color);
- fg_rect(x,x+BARLEN-damage,BARY,BARY+BARH);
- fg_setcolor(0);
- fg_rect(x+BARLEN-damage,x+BARLEN,BARY,BARY+BARH);
-
- int page=fg_getpage(); // future
- fg_transfer(x,x+BARLEN,BARY,BARY+BARH,x,BARY+BARH,page,1-page);
- }
-
- void LifeBar::on_hit(int,int data)
- {
- if (data!=side) return;
-
- update(fighter->get_damage());
- }
-
-