src/StateBattle.cpp

Go to the documentation of this file.
00001 /* Crown and Cutlass
00002  * Naval Battle Entry Code
00003  */
00004 
00005 #include <string>
00006 #include <sstream>
00007 #include <guichan.hpp>
00008 #include <guichan/sdl.hpp>
00009 #include <guichan/opengl.hpp>
00010 #include "SDL.h"
00011 #include "GLee.h"
00012 #include "Menu/CCGui.h"
00013 #include "Menu/CCButton.h"
00014 #include "Menu/CCTable.h"
00015 #include "Menu/CCLabel.h"
00016 #include "Config.h"
00017 #include "Log.h"
00018 #include "Texture.h"
00019 #include "font.h"
00020 #include "IGameState.h"
00021 #include "StateBattle/Battle.h"
00022 #include "Player.h"
00023 #include "Ship.h"
00024 #include "StateBattle.h"
00025 
00026 using namespace std;
00027 
00028 const string StateBattle::s_mainFontName = "papyrus.png";
00029 const string StateBattle::s_highlightFontName = "highlightPapyrus.png";
00030 const string StateBattle::s_disabledFontName = "disabledPapyrus.png";
00031 
00032 StateBattle::StateBattle(): IGameState(NULL) {
00033   m_actualBattle = NULL;
00034 
00035   // Stop the player, so when they leave they aren't moving
00036   Player::player->ship->m_speed = 0;
00037   Player::player->ship->SetSails(NOSAILS);
00038 
00039   m_exitCallback.SetCallback(this, &StateBattle::Exit);
00040   m_attackCallback.SetCallback(this, &StateBattle::Attack);
00041 
00042   Log::s_log->Message("Callbacks Set");
00043 
00044   m_background = new Texture("enterbattle.png");
00045 
00046   Log::s_log->Message("Background Texture built");
00047 
00048   Log::s_log->Message("Top Created");
00049   m_menuList = new CCTable(1, 2);
00050 
00051   m_attackButton = new CCButton("Attack!", "attack_button", s_mainFontName, s_highlightFontName, s_disabledFontName, &m_attackCallback);
00052   m_sailAwayButton = new CCButton("Sail Away", "sailAway_button", s_mainFontName, s_highlightFontName, s_disabledFontName, &m_exitCallback);
00053 
00054   m_title = new CCLabel("Ship sighted!", s_mainFontName);
00055 
00056   m_menuList->add(0, 0, m_sailAwayButton);
00057   m_menuList->add(0, 1, m_attackButton);
00058 
00059   m_menuList->setVisible(true);
00060   m_menuList->setOpaque(false);
00061 
00062   Log::s_log->Message("Table Set...Label Set");
00063 
00064   m_top->add(m_menuList, 10, 200);
00065   m_top->add(m_title, (Config::s_config->GetWinWidth() / 2) - (m_title->getWidth() / 2), 50);
00066 
00067   Log::s_log->Message("StateBattle initialization done.");
00068 
00069 }
00070 
00071 StateBattle::~StateBattle() {
00072   delete m_menuList;
00073   delete m_title;
00074 
00075   delete m_actualBattle;
00076 
00077   delete m_background;
00078 
00079   Log::s_log->Message("State Battle deleted");
00080 }
00081 
00082 void StateBattle::Update(const unsigned int ticks) {
00083   CheckInput();
00084 }
00085 
00086 void StateBattle::Display() {
00087   glLoadIdentity();
00088   DisplayBackground(m_background->GetTexture(), 1);
00089 }
00090 
00091 void StateBattle::CheckInput() {
00092   SDL_Event event;
00093   /*
00094    * Poll SDL events
00095    */
00096   while(SDL_PollEvent(&event))
00097   {
00098     if (event.type == SDL_KEYDOWN)
00099     {
00100       /*
00101       if (event.key.keysym.sym == SDLK_ESCAPE)
00102       {
00103         done = false;
00104       }
00105       if (event.key.keysym.sym == SDLK_f)
00106       {
00107         if (event.key.keysym.mod & KMOD_CTRL)
00108         {
00109           // Works with X11 only
00110           //SDL_WM_ToggleFullScreen(screen);
00111         }
00112       }
00113       */
00114       if (event.key.keysym.sym == SDLK_z) {
00115         TakeScreenshot();
00116       }
00117     }
00118 
00119 
00120     /*
00121      * Now that we are done polling and using SDL events we pass
00122      * the leftovers to the SDLInput object to later be handled by
00123      * the Gui. (This example doesn't require us to do this 'cause a
00124      * label doesn't use input. But will do it anyway to show how to
00125      * set up an SDL application with Guichan.)
00126      */
00127     CCGui::s_CCGui->m_input->pushInput(event);
00128   }
00129 }
00130 
00131 void StateBattle::Exit(int ID) {
00132   PrepareStateSwitch(m_previous, this);
00133 }
00134 
00135 void StateBattle::Attack(int ID) {
00136   // Just to be on the safe side
00137   if (m_actualBattle != NULL) {
00138     delete m_actualBattle;
00139   }
00140   m_actualBattle = new Battle();
00141   PrepareStateSwitch(m_actualBattle, m_previous);
00142 }
00143 
00144 void StateBattle::SwitchTo(IGameState *oldState) {
00145   EnterTextMode(Config::s_config->GetWinWidth(), Config::s_config->GetWinHeight());
00146 }
00147 
00148 void StateBattle::SwitchFrom() {
00149 }

Generated on Mon Jan 8 22:34:12 2007 for CrownandCutlass by  doxygen 1.4.7