TeamEnergy Class Reference

#include <team_energy.h>

Collaboration diagram for TeamEnergy:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TeamEnergy (Team *_team)
 ~TeamEnergy ()
void Config (uint _current_energy, uint _max_energy)
void Refresh ()
void Draw (const Point2i &pos)
void SetValue (uint nv_energie)
void SetRanking (uint classem)
void NewRanking (uint nv_classem)
void Move ()
bool IsMoving () const
void FinalizeMove ()

Public Attributes

uint rank_tmp
energy_t status

Private Attributes

EnergyBar energy_bar
uint value
uint new_value
uint max_value
Teamteam
Spriteicon
Textt_team_energy
int dx
int dy
uint rank
uint new_rank
std::string team_name
uint move_start_time

Detailed Description

Definition at line 46 of file team_energy.h.


Constructor & Destructor Documentation

TeamEnergy::TeamEnergy ( Team _team  ) 

Definition at line 43 of file team_energy.cpp.

00044 {
00045   dx = 0;
00046   dy = 0;
00047   move_start_time = 0;
00048   max_value = 0;
00049   status = EnergyStatusOK;
00050   energy_bar.InitPos(0, 0, BAR_WIDTH, BAR_HEIGHT);
00051 
00052   energy_bar.SetBorderColor(Color(255, 255, 255, ALPHA));
00053   energy_bar.SetBackgroundColor(Color(255*6/10, 255*6/10, 255*6/10, BACK_ALPHA));
00054 
00055   team = _team;
00056   icon = NULL;
00057   t_team_energy = new Text("None", black_color, Font::GetInstance(Font::FONT_SMALL), false);
00058 }

Here is the call graph for this function:

TeamEnergy::~TeamEnergy (  ) 

Definition at line 60 of file team_energy.cpp.

00061 {
00062   if(icon) delete icon;
00063   if(t_team_energy) delete t_team_energy;
00064 }


Member Function Documentation

void TeamEnergy::Config ( uint  _current_energy,
uint  _max_energy 
)

Definition at line 66 of file team_energy.cpp.

00068 {
00069   max_value = _max_energy;
00070 
00071   value = _current_energy;
00072   new_value = _current_energy;
00073   assert(max_value != 0)
00074       energy_bar.InitVal(value, 0, max_value, ProgressBar::PROG_BAR_VERTICAL);
00075   icon = new Sprite(team->flag);
00076   icon->Scale(0.8,0.8);
00077 }

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamEnergy::Draw ( const Point2i pos  ) 

Definition at line 113 of file team_energy.cpp.

00114 {
00115   energy_bar.Actu(value);
00116   Point2i tmp = pos + Point2i(BAR_SPACING / 2 + rank * (BAR_WIDTH + BAR_SPACING) + dx, dy);
00117   energy_bar.DrawXY(tmp);
00118   icon->DrawXY(tmp + Point2i(energy_bar.GetWidth() / 2, 0));
00119 }

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamEnergy::FinalizeMove (  ) 

Definition at line 180 of file team_energy.cpp.

00181 {
00182   dy = 0;
00183   dx = 0;
00184   rank = new_rank;
00185   move_start_time = 0;
00186   status = EnergyStatusWait;
00187   return;
00188 }

Here is the caller graph for this function:

bool TeamEnergy::IsMoving (  )  const

Definition at line 190 of file team_energy.cpp.

00191 {
00192   if( dx != 0 || dy != 0 )
00193     return true;
00194   return false;
00195 }

Here is the caller graph for this function:

void TeamEnergy::Move (  ) 

Definition at line 138 of file team_energy.cpp.

00139 {
00140   if( value != new_value && !IsMoving()) {
00141     // Other energy bar are moving so waiting for others to move
00142     status = EnergyStatusWait;
00143     return;
00144   }
00145 
00146   if( rank == new_rank && !IsMoving()) {
00147     // Others energy bar are moving
00148     status = EnergyStatusWait;
00149     return;
00150   }
00151 
00152   // teams ranking have changed
00153   Time * global_time = Time::GetInstance();
00154   if( rank != new_rank )
00155   {
00156     if(move_start_time == 0)
00157       move_start_time = global_time->Read();
00158 
00159     dx = (int)(((float)new_rank - rank) * (BAR_WIDTH + BAR_SPACING) * ((global_time->Read() - move_start_time) / MOVE_DURATION));
00160 
00161     // displacement in arc of circle only when losing place ranking
00162     if( new_rank > rank ) {
00163       dy = (int)((BAR_HEIGHT * ((float)rank - new_rank)) * 0.5 *
00164            sin( M_PI * ((global_time->Read() - move_start_time) / MOVE_DURATION)));
00165     } else {
00166       dy = (int)((BAR_HEIGHT * ((float)rank - new_rank)) * 0.5 *
00167           sin( M_PI * ((global_time->Read() - move_start_time) / MOVE_DURATION)));
00168     }
00169     // End of movement ?
00170     if( (global_time->Read() - move_start_time) > MOVE_DURATION)
00171       FinalizeMove();
00172   } else {
00173     // While moving, it came back to previous place in ranking
00174     dy = (int)((float)dy - ((global_time->Read() - move_start_time) / MOVE_DURATION) * dy);
00175     dx = (int)((float)dx - ((global_time->Read() - move_start_time) / MOVE_DURATION) * dx);
00176   }
00177 }

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamEnergy::NewRanking ( uint  nv_classem  ) 

Definition at line 132 of file team_energy.cpp.

00133 {
00134   new_rank = _new_rank;
00135 }

void TeamEnergy::Refresh (  ) 

Definition at line 79 of file team_energy.cpp.

00080 {
00081   switch(status)
00082   {
00083     // energy value from one team have changed
00084     case EnergyStatusValueChange:
00085       if(new_value > value)
00086         value = new_value;
00087       if(value > new_value)
00088         --value;
00089       if(value == new_value)
00090         status = EnergyStatusWait;
00091       break;
00092 
00093     // ranking is changing
00094     case EnergyStatusRankChange:
00095       Move();
00096       break;
00097 
00098     // Currently no move
00099     case EnergyStatusOK:
00100       if( value != new_value && !IsMoving())
00101         status = EnergyStatusValueChange;
00102       else
00103         if( rank != new_rank )
00104           status = EnergyStatusRankChange;
00105       break;
00106 
00107     // This energy bar wait others bar before moving
00108     case EnergyStatusWait:
00109       break;
00110   }
00111 }

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamEnergy::SetRanking ( uint  classem  ) 

Definition at line 126 of file team_energy.cpp.

00127 {
00128   rank = _rank;
00129   new_rank = _rank;
00130 }

void TeamEnergy::SetValue ( uint  nv_energie  ) 

Definition at line 121 of file team_energy.cpp.

00122 {
00123   new_value = new_energy;
00124 }

Here is the caller graph for this function:


Member Data Documentation

int TeamEnergy::dx [private]

Definition at line 61 of file team_energy.h.

int TeamEnergy::dy [private]

Definition at line 62 of file team_energy.h.

EnergyBar TeamEnergy::energy_bar [private]

Definition at line 49 of file team_energy.h.

Sprite* TeamEnergy::icon [private]

Definition at line 58 of file team_energy.h.

uint TeamEnergy::max_value [private]

Definition at line 55 of file team_energy.h.

uint TeamEnergy::move_start_time [private]

Definition at line 69 of file team_energy.h.

uint TeamEnergy::new_rank [private]

Definition at line 65 of file team_energy.h.

uint TeamEnergy::new_value [private]

Definition at line 53 of file team_energy.h.

uint TeamEnergy::rank [private]

Definition at line 64 of file team_energy.h.

uint TeamEnergy::rank_tmp

Definition at line 72 of file team_energy.h.

energy_t TeamEnergy::status

Definition at line 73 of file team_energy.h.

Text* TeamEnergy::t_team_energy [private]

Definition at line 59 of file team_energy.h.

Team* TeamEnergy::team [private]

Definition at line 57 of file team_energy.h.

std::string TeamEnergy::team_name [private]

Definition at line 67 of file team_energy.h.

uint TeamEnergy::value [private]

Definition at line 51 of file team_energy.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 14:23:20 2007 for Wormux by  doxygen 1.4.7