Map Class Reference

#include <Map.h>

Inheritance diagram for Map:

IGameState List of all members.

Public Member Functions

 Map (StateSailing *curGame, Ship *playerShip, Terrain *terrain)
 ~Map ()
void Update (const unsigned int ticks)
void Display ()
void SwitchTo (IGameState *oldState)
void SwitchFrom ()
void DrawGui ()

Private Member Functions

void InitMenu ()
void CheckInput ()
void HandleKeyUp (SDL_keysym *keysym)
void HandleKeyDown (SDL_keysym *keysym)
void HandleMouseMove ()
float TerrainToScreenX (float x)
float TerrainToScreenZ (float z)
float ScreenToTerrainX (float x)
float ScreenToTerrainZ (float z)

Private Attributes

Texturem_background
gcn::Image * m_cityIconImage
gcn::Icon * m_shipIcon
gcn::Image * m_shipIconImage
vector< gcn::Widget * > m_guichanWidgets
StateSailingm_mainGame
Shipm_playerShip
int m_winWidth
int m_winHeight
int m_terrainWidth
int m_terrainHeight
int m_curMousePosX
int m_curMousePosY
bool m_transport

Static Private Attributes

static const std::string s_mainFontName = "smallFont.png"

Detailed Description

Definition at line 19 of file Map.h.


Constructor & Destructor Documentation

Map::Map ( StateSailing curGame,
Ship playerShip,
Terrain terrain 
)

Definition at line 25 of file Map.cpp.

References Texture::BindTexture(), Terrain::GetHeight(), Terrain::GetWidth(), Config::GetWinHeight(), Config::GetWinWidth(), InitMenu(), m_background, m_curMousePosX, m_curMousePosY, m_mainGame, m_playerShip, m_terrainHeight, m_terrainWidth, m_transport, m_winHeight, m_winWidth, and Config::s_config.

00025                                                                  :IGameState(curGame) {
00026   m_winWidth = Config::s_config->GetWinWidth();
00027   m_winHeight = Config::s_config->GetWinHeight();
00028 
00029   m_terrainWidth = terrain->GetWidth();
00030   m_terrainHeight = terrain->GetHeight();
00031 
00032   // Set the pointer to the main sailing state to null
00033   m_mainGame = curGame;
00034 
00035   m_playerShip = playerShip;
00036 
00037   // Load the background
00038   glEnable(GL_TEXTURE_2D);
00039   m_background = new Texture("mapscreen.png");
00040   m_background->BindTexture();
00041 
00042   m_curMousePosX = 0;
00043   m_curMousePosY = 0;
00044 
00045   m_transport = false;
00046 
00047   InitMenu();
00048 }

Map::~Map (  ) 

Definition at line 50 of file Map.cpp.

References m_background, m_cityIconImage, m_guichanWidgets, m_shipIcon, and m_shipIconImage.

00050           {
00051   gcn::Widget* tempWidget;
00052   unsigned int numWidgets;
00053 
00054   delete m_background;
00055 
00056   numWidgets = m_guichanWidgets.size();
00057 
00058   for (unsigned int i = 0; i < numWidgets; i++) {
00059     tempWidget = m_guichanWidgets[i];
00060     m_guichanWidgets[i] = NULL;
00061     delete tempWidget;
00062   }
00063   m_guichanWidgets.clear();
00064 
00065   delete m_shipIcon;
00066 
00067   delete m_cityIconImage;
00068   delete m_shipIconImage;
00069 }


Member Function Documentation

void Map::CheckInput (  )  [private, virtual]

Implements IGameState.

Definition at line 91 of file Map.cpp.

References IGameState::DoExit(), HandleKeyDown(), HandleKeyUp(), and HandleMouseMove().

Referenced by Update().

00091                      {
00092   /* Our SDL event placeholder. */
00093   SDL_Event event;
00094 
00095   HandleMouseMove();
00096   /* Grab all the events off the queue. */
00097   while( SDL_PollEvent( &event ) ) {
00098     switch( event.type ) {
00099     case SDL_KEYDOWN:
00100       /* Handle key presses. */
00101       HandleKeyDown( &event.key.keysym );
00102       break;
00103     case SDL_KEYUP:
00104       HandleKeyUp(&event.key.keysym);
00105       break;
00106     case SDL_QUIT:
00107       /* Handle quit requests (like Ctrl-c). */
00108       DoExit();
00109       break;
00110     }
00111   }
00112 }

void Map::Display (  )  [virtual]

Implements IGameState.

Definition at line 83 of file Map.cpp.

References IGameState::DisplayBackground(), Texture::GetTexture(), and m_background.

00083                   {
00084   glLoadIdentity();
00085 
00086   // Draw the background
00087   DisplayBackground(m_background->GetTexture(), .6);
00088 }

void Map::DrawGui (  ) 

Definition at line 170 of file Map.cpp.

References Texture::BindTexture(), m_background, and m_winHeight.

00170                   {
00171   glPushMatrix();
00172   glLoadIdentity();
00173   m_background->BindTexture();
00174 
00175   glColor3f(0, 0, 0);
00176 
00177   //Draw quad for map
00178   glBegin(GL_QUADS);
00179   glTexCoord2f(0,0);
00180   glVertex3f(10, m_winHeight - 250, 0);
00181   glTexCoord2f(0, 1);
00182   glVertex3f(10, m_winHeight - 10, 0);
00183   glTexCoord2f(1, 1);
00184   glVertex3f(370, m_winHeight - 10, 0);
00185   glTexCoord2f(1, 0);
00186   glVertex3f(370, m_winHeight - 250, 0);
00187   glEnd();
00188 
00189   glColor3f(1, 1, 1);
00190   glPopMatrix();
00191 }

void Map::HandleKeyDown ( SDL_keysym *  keysym  )  [private]

Definition at line 149 of file Map.cpp.

References m_transport, and IGameState::TakeScreenshot().

Referenced by CheckInput().

00149                                           {
00150   switch( keysym->sym ) {
00151   case SDLK_z:
00152     TakeScreenshot();
00153     break;
00154   case SDLK_t:
00155     m_transport = true;
00156     break;
00157   default:
00158     break;
00159   }
00160 }

void Map::HandleKeyUp ( SDL_keysym *  keysym  )  [private]

Definition at line 125 of file Map.cpp.

References IGameState::m_previous, m_transport, and IGameState::PrepareStateSwitch().

Referenced by CheckInput().

00125                                         {
00126   switch(keysym->sym) {
00127   case SDLK_ESCAPE:
00128     // Go back to the game, if it is loaded
00129     if (m_previous != NULL) {
00130       PrepareStateSwitch(m_previous, this);
00131     }
00132     break;
00133   case SDLK_m:
00134     // Go back to the game, if it is loaded
00135     if (m_previous != NULL) {
00136       PrepareStateSwitch(m_previous, this);
00137     }
00138     break;
00139   case SDLK_t:
00140     // Stop the transport function
00141     m_transport = false;
00142     break;
00143 
00144   default:
00145     break;
00146   }
00147 }

void Map::HandleMouseMove (  )  [private]

Definition at line 114 of file Map.cpp.

References m_curMousePosX, m_curMousePosY, m_playerShip, m_transport, Ship::m_x, Ship::m_z, ScreenToTerrainX(), and ScreenToTerrainZ().

Referenced by CheckInput().

00114                           {
00115   Uint8 buttons;
00116 
00117   buttons = SDL_GetMouseState(&m_curMousePosX, &m_curMousePosY);
00118 
00119   if ((buttons == SDL_BUTTON(1)) && m_transport) {
00120     m_playerShip->m_x = ScreenToTerrainX((float)m_curMousePosX);
00121     m_playerShip->m_z = ScreenToTerrainZ((float)m_curMousePosY);
00122   }
00123 }

void Map::InitMenu (  )  [private]

Definition at line 193 of file Map.cpp.

References CityManager::GetCity(), IEnvironmentObject::GetLocX(), IEnvironmentObject::GetLocZ(), IEnvironmentObject::getName(), StateSailing::m_cities, m_cityIconImage, m_guichanWidgets, m_mainGame, m_playerShip, m_shipIcon, m_shipIconImage, IGameState::m_top, Ship::m_x, Ship::m_z, CityManager::NumberCities(), s_mainFontName, TerrainToScreenX(), and TerrainToScreenZ().

Referenced by Map().

00193                    {
00194   gcn::Widget* tempWidget;
00195   unsigned int i, numCities;
00196   float screenX, screenY;
00197 
00198   m_cityIconImage = new gcn::Image("data/Textures/cityicon.png");
00199   m_shipIconImage = new gcn::Image("data/Textures/shipicon.png");
00200 
00201   numCities = m_mainGame->m_cities->NumberCities();
00202 
00203   m_guichanWidgets.reserve(numCities * 2);
00204 
00205   for (i = 0; i < numCities; i++) {
00206     screenX = TerrainToScreenX((float)m_mainGame->m_cities->GetCity(i)->GetLocX());
00207     screenY = TerrainToScreenZ((float)m_mainGame->m_cities->GetCity(i)->GetLocZ());
00208 
00209     tempWidget = new gcn::Icon(m_cityIconImage);
00210     m_guichanWidgets.push_back(tempWidget);
00211     m_top->add(tempWidget, (int) screenX - (m_cityIconImage->getWidth() / 2), (int) screenY - (m_cityIconImage->getHeight() / 2));
00212 
00213     tempWidget = new CCLabel(m_mainGame->m_cities->GetCity(i)->getName(), s_mainFontName);
00214     m_guichanWidgets.push_back(tempWidget);
00215     m_top->add(tempWidget, (int) screenX, (int) screenY);
00216   }
00217 
00218   screenX = TerrainToScreenX((float)m_playerShip->m_x);
00219   screenY = TerrainToScreenZ((float)m_playerShip->m_z);
00220 
00221   m_shipIcon = new gcn::Icon(m_shipIconImage);
00222   m_top->add(m_shipIcon, (int) screenX - (m_shipIconImage->getWidth() / 2), (int) screenY - (m_shipIconImage->getHeight() / 2));
00223 }

float Map::ScreenToTerrainX ( float  x  )  [private]

Definition at line 233 of file Map.cpp.

References m_terrainWidth, and m_winWidth.

Referenced by HandleMouseMove().

00233                                    {
00234   return m_terrainWidth * ((float)x/m_winWidth - 0.5);
00235 }

float Map::ScreenToTerrainZ ( float  z  )  [private]

Definition at line 237 of file Map.cpp.

References m_terrainHeight, and m_winHeight.

Referenced by HandleMouseMove().

00237                                    {
00238   return m_terrainHeight * ((float)z/m_winHeight - 0.5);
00239 }

void Map::SwitchFrom (  )  [virtual]

Implements IGameState.

Definition at line 167 of file Map.cpp.

00167                      {
00168 }

void Map::SwitchTo ( IGameState oldState  )  [virtual]

Implements IGameState.

Definition at line 162 of file Map.cpp.

References EnterTextMode(), m_transport, and Config::s_config.

00162                                        {
00163   m_transport = false;
00164   EnterTextMode(Config::s_config->GetWinWidth(), Config::s_config->GetWinHeight());
00165 }

float Map::TerrainToScreenX ( float  x  )  [private]

Definition at line 225 of file Map.cpp.

References m_terrainWidth, and m_winWidth.

Referenced by InitMenu(), and Update().

00225                                    {
00226   return m_winWidth * (x / m_terrainWidth + 0.5);
00227 }

float Map::TerrainToScreenZ ( float  z  )  [private]

Definition at line 229 of file Map.cpp.

References m_terrainHeight, and m_winHeight.

Referenced by InitMenu(), and Update().

00229                                    {
00230   return m_winHeight * (z / m_terrainHeight + 0.5);
00231 }

void Map::Update ( const unsigned int  ticks  )  [virtual]

Implements IGameState.

Definition at line 71 of file Map.cpp.

References CheckInput(), m_playerShip, m_shipIcon, m_shipIconImage, Ship::m_x, Ship::m_z, TerrainToScreenX(), and TerrainToScreenZ().

00071                                          {
00072   float screenX, screenY;
00073 
00074   // Process incoming events
00075   CheckInput();
00076 
00077   screenX = TerrainToScreenX((float)m_playerShip->m_x);
00078   screenY = TerrainToScreenZ((float)m_playerShip->m_z);
00079   m_shipIcon->setX((int) screenX - (m_shipIconImage->getWidth() / 2));
00080   m_shipIcon->setY((int) screenY - (m_shipIconImage->getHeight() / 2));
00081 }


Member Data Documentation

Texture* Map::m_background [private]

Definition at line 42 of file Map.h.

Referenced by Display(), DrawGui(), Map(), and ~Map().

gcn::Image* Map::m_cityIconImage [private]

Definition at line 45 of file Map.h.

Referenced by InitMenu(), and ~Map().

int Map::m_curMousePosX [private]

Definition at line 72 of file Map.h.

Referenced by HandleMouseMove(), and Map().

int Map::m_curMousePosY [private]

Definition at line 73 of file Map.h.

Referenced by HandleMouseMove(), and Map().

vector<gcn::Widget*> Map::m_guichanWidgets [private]

Definition at line 48 of file Map.h.

Referenced by InitMenu(), and ~Map().

StateSailing* Map::m_mainGame [private]

Definition at line 56 of file Map.h.

Referenced by InitMenu(), and Map().

Ship* Map::m_playerShip [private]

Definition at line 59 of file Map.h.

Referenced by HandleMouseMove(), InitMenu(), Map(), and Update().

gcn::Icon* Map::m_shipIcon [private]

Definition at line 46 of file Map.h.

Referenced by InitMenu(), Update(), and ~Map().

gcn::Image* Map::m_shipIconImage [private]

Definition at line 47 of file Map.h.

Referenced by InitMenu(), Update(), and ~Map().

int Map::m_terrainHeight [private]

Definition at line 70 of file Map.h.

Referenced by Map(), ScreenToTerrainZ(), and TerrainToScreenZ().

int Map::m_terrainWidth [private]

Definition at line 69 of file Map.h.

Referenced by Map(), ScreenToTerrainX(), and TerrainToScreenX().

bool Map::m_transport [private]

Definition at line 75 of file Map.h.

Referenced by HandleKeyDown(), HandleKeyUp(), HandleMouseMove(), Map(), and SwitchTo().

int Map::m_winHeight [private]

Definition at line 67 of file Map.h.

Referenced by DrawGui(), Map(), ScreenToTerrainZ(), and TerrainToScreenZ().

int Map::m_winWidth [private]

Definition at line 66 of file Map.h.

Referenced by Map(), ScreenToTerrainX(), and TerrainToScreenX().

const string Map::s_mainFontName = "smallFont.png" [static, private]

Definition at line 86 of file Map.h.

Referenced by InitMenu().


The documentation for this class was generated from the following files:
Generated on Mon Jan 8 22:34:14 2007 for CrownandCutlass by  doxygen 1.4.7