Water Class Reference

#include <water.h>

Collaboration diagram for Water:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void Init ()
void Reset ()
void Free ()
void Refresh ()
void Draw ()
bool IsActive ()
int GetHeight (int x)

Private Attributes

uint temps_eau
int height_mvt
int vague
bool actif
double shift1
uint hauteur_eau
uint temps_montee
std::vector< int > height
Surface surface
Surface pattern

Detailed Description

Definition at line 31 of file water.h.


Member Function Documentation

void Water::Draw (  ) 

Definition at line 127 of file water.cpp.

00127                 {
00128   if (!actif)
00129     return;
00130 
00131   // Compute 1 pattern:
00132   pattern.SetAlpha( 0, 0);
00133   pattern.Fill(0x00000000);
00134 
00135   int y0 = world.GetHeight()-(hauteur_eau + height_mvt)-20;
00136 
00137   for(uint x=0; x<180; x++){
00138     Point2i dst(x, height.at(x) - y0);
00139     pattern.Blit(surface, dst);
00140   }
00141   pattern.SetAlpha(SDL_SRCALPHA, 0);
00142 
00143   int x0 = camera.GetPosition().x;
00144   while(x0<0)
00145     x0+=180;
00146   while(x0>180)
00147     x0-=180;
00148 
00149   for(int x=camera.GetPosition().x-x0; x<camera.GetPosition().x+camera.GetSize().x; x+=180)
00150     for(int y=y0; y<(int)camera.GetPosition().y+(int)camera.GetSize().y; y+=surface.GetSize().y)
00151       AbsoluteDraw(pattern, Point2i(x, y));
00152 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Water::Free (  ) 

Definition at line 66 of file water.cpp.

00066                 {
00067   if(!actif)
00068     return;
00069   surface.Free();
00070   pattern.Free();
00071   height.clear();
00072 }

Here is the call graph for this function:

Here is the caller graph for this function:

int Water::GetHeight ( int  x  ) 

Definition at line 154 of file water.cpp.

00154                          {
00155   if (IsActive()){
00156     while(x<0)
00157       x += 180;
00158     while(x>=180)
00159       x -= 180;
00160     return height.at(x);
00161   }
00162   else
00163     return world.GetHeight();
00164 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Water::Init (  ) 

Definition at line 44 of file water.cpp.

00044                 {
00045    Profile *res = resource_manager.LoadXMLProfile( "graphism.xml", false);
00046    surface = resource_manager.LoadImage(res, "gfx/water");
00047    surface.SetAlpha(0, 0);
00048    pattern.NewSurface( Point2i(180, surface.GetHeight() + 40), SDL_SWSURFACE|SDL_SRCALPHA, true);
00049    shift1 = 0;
00050    resource_manager.UnLoadXMLProfile(res);
00051 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Water::IsActive (  ) 

Definition at line 166 of file water.cpp.

00166                     {
00167   return actif;
00168 }

Here is the caller graph for this function:

void Water::Refresh (  ) 

Definition at line 74 of file water.cpp.

00074                    {
00075   if (!actif)
00076     return;
00077 
00078   height_mvt = 0;
00079 
00081   Time * global_time = Time::GetInstance();
00082   if (temps_montee < global_time->Read())
00083   {
00084     if(temps_montee + GO_UP_OSCILLATION_TIME * 1000 > global_time->Read()){
00085       uint dt=global_time->Read()- temps_montee;
00086       height_mvt = GO_UP_STEP + (uint)(((float)GO_UP_STEP * sin(((float)(dt*(GO_UP_OSCILLATION_NBR-0.25))/GO_UP_OSCILLATION_TIME/1000.0)*2*M_PI))/(a*dt+b));
00087     }
00088     else{
00089       temps_montee += GO_UP_TIME * 60 * 1000;
00090       hauteur_eau += GO_UP_STEP;
00091     }
00092   }
00093 
00095   // on rempli le sol avec de l'eau
00096   if (WAVE_TIME < (global_time->Read() - temps_eau))
00097   {
00098     temps_eau = global_time->Read();
00099     vague += WAVE_STEP;
00100     if (surface.GetWidth() <= vague)
00101                 vague=0;
00102   }
00103 
00104   int x = -surface.GetWidth() + vague;
00105   int y = world.GetHeight()-(hauteur_eau + height_mvt);
00106 
00107   double decree = (double) 2*M_PI/360;
00108 
00109   double angle1 = 0;
00110   double angle2 = shift1;
00111   do
00112   {
00113     int offset=0;
00114     double y_pos = y + sin(angle1)*10 + sin(angle2)*10;
00115 
00116     if (0<=x+offset)
00117          height.at(x+offset) = (int)y_pos;
00118 
00119     angle1 += 2*decree;
00120     angle2 += 4*decree;
00121     x++;
00122   } while ((uint)x < 180);
00123 
00124   shift1 += 4*decree;
00125 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Water::Reset (  ) 

Definition at line 53 of file water.cpp.

00053                  {
00054   actif = ActiveMap().UseWater();
00055   if(!actif) return;
00056   Init();
00057   hauteur_eau = WATER_INITIAL_HEIGHT;
00058   vague = 0;
00059   temps_eau = 0;
00060   temps_montee = GO_UP_TIME * 60 * 1000;
00061   height.clear();
00062   height.assign(180, 0);
00063   Refresh(); // Calculate first height position
00064 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

bool Water::actif [private]

Definition at line 37 of file water.h.

uint Water::hauteur_eau [private]

Definition at line 39 of file water.h.

std::vector<int> Water::height [private]

Definition at line 41 of file water.h.

int Water::height_mvt [private]

Definition at line 35 of file water.h.

Surface Water::pattern [private]

Definition at line 43 of file water.h.

double Water::shift1 [private]

Definition at line 38 of file water.h.

Surface Water::surface [private]

Definition at line 42 of file water.h.

uint Water::temps_eau [private]

Definition at line 34 of file water.h.

uint Water::temps_montee [private]

Definition at line 40 of file water.h.

int Water::vague [private]

Definition at line 36 of file water.h.


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