- Main Page
- Classes
- Files

- File List
- File Members

# C:/Users/Public/AGS Final Folder/BFLETCHER D4010283/Source/Game/Source/BreakoutMainMenuScene.cpp

Go to the documentation of this file.

    00001 #include "BreakoutMainMenuScene.h"
    00002
    00003 #include "GameConfig.h"
    00004
    00005 #include "Vector2.h"
    00006
    00007 #include "ApplicationEvents.h"
    00008 #include "InputEvents.h"
    00009 #include "BreakoutEvents.h"
    00010 #include "EventManager.h"
    00011
    00012 BreakoutMainMenuScene::BreakoutMainMenuScene()
    00013 : m_bIsActive(false), m_selectedEntry(0), m_gameTitleID(0), m_gameTitleShadowID(0)
    00014 {
    00015
    00016 }
    00017
    00018 BreakoutMainMenuScene::~BreakoutMainMenuScene()
    00019 {
    00020
    00021 }
    00022
    00023 void BreakoutMainMenuScene::Initialise()
    00024 {
    00025         Visualisation* pVis = Visualisation::getSingleton();
    00026         MenuEntry startEntry;
    00027         startEntry.Name = MENU_START_GAME_TEXT;
    00028         startEntry.NormalSprite = pVis->CreateSpriteText(startEntry.Name, MENU_NORMAL_COLOUR);
    00029         startEntry.SelectedSprite = pVis->CreateSpriteText(startEntry.Name, MENU_SELECTED_COLOUR);
    00030         m_vMenuEntries.push_back(startEntry);
    00031
    00032         MenuEntry quitEntry;
    00033         quitEntry.Name = MENU_QUIT_GAME_TEXT;
    00034         quitEntry.NormalSprite = pVis->CreateSpriteText(quitEntry.Name, MENU_NORMAL_COLOUR);
    00035         quitEntry.SelectedSprite = pVis->CreateSpriteText(quitEntry.Name, MENU_SELECTED_COLOUR);
    00036         m_vMenuEntries.push_back(quitEntry);
    00037
    00038         m_gameTitleID = Visualisation::getSingleton()->CreateSpriteText(GAME_TITLE, GAME_TITLE_COLOUR);
    00039         m_gameTitleShadowID = Visualisation::getSingleton()->CreateSpriteText(GAME_TITLE, GAME_TITLE_SHADOW_COLOUR);
    00040
    00041         EventManager::getSingleton()->AddEventListener(ButtonInputEvent::cEventName, this);
    00042 }
    00043
    00044 void BreakoutMainMenuScene::Draw()
    00045 {
    00046         if(!m_bIsActive)
    00047                 return;
    00048
    00049         Visualisation* pVis = Visualisation::getSingleton();
    00050         pVis->ClearScreen();
    00051
    00052         SDL_Surface* pScreen = pVis->GetScreen();
    00053         Vector2i centre(pScreen->w / 2, pScreen->h / 2);
    00054
    00055         Vector2i titlePos;
    00056         std::string title = GAME_TITLE;
    00057         titlePos.x = centre.x - (pVis->GetSpriteWidth(m_gameTitleID) / 2);
    00058         titlePos.y = pScreen->h / 5;
    00059         pVis->DrawSprite(m_gameTitleShadowID, titlePos.x, titlePos.y);
    00060         int offset = CHARACTER_WIDTH / 4;
    00061         pVis->DrawSprite(m_gameTitleID, titlePos.x + offset, titlePos.y + offset);
    00062
    00063         int numEntries = m_vMenuEntries.size();
    00064         int totalHeight = numEntries * CHARACTER_HEIGHT * 2; //Multiplied by 2 to add some spacing between entries.
    00065         int yPos = centre.y - (totalHeight / 2);
    00066
    00067         for(int i = 0 ; i < numEntries; i++)
    00068         {
    00069                 int strSize = m_vMenuEntries[i].Name.size();
    00070                 int xPos = centre.x - (pVis->GetSpriteWidth(m_vMenuEntries[i].NormalSprite) / 2);
    00071                 if(i == m_selectedEntry)
    00072                         pVis->DrawSprite(m_vMenuEntries[i].SelectedSprite, xPos, yPos);
    00073                 else
    00074                         pVis->DrawSprite(m_vMenuEntries[i].NormalSprite, xPos, yPos);
    00075
    00076
    00077                 yPos += CHARACTER_HEIGHT * 2;
    00078         }
    00079 }
    00080
    00081 void BreakoutMainMenuScene::Update()
    00082 {
    00083
    00084 }
    00085
    00086 void BreakoutMainMenuScene::Shutdown()
    00087 {
    00088         m_vMenuEntries.clear();
    00089 }
    00090
    00091 void BreakoutMainMenuScene::Activate()
    00092 {
    00093         m_bIsActive = true;
    00094 }
    00095
    00096 void BreakoutMainMenuScene::Deactivate()
    00097 {
    00098         m_bIsActive = false;
    00099 }
    00100
    00101 bool BreakoutMainMenuScene::HandleEvent(IEvent *pEvent)
    00102 {
    00103         if(!m_bIsActive)
    00104                 return false;
    00105
    00106         if(pEvent->GetEventType() == ButtonInputEvent::cEventName)
    00107         {
    00108                 ButtonInputEvent* pButtonEvent = (ButtonInputEvent*)pEvent;
    00109                 int key = pButtonEvent->GetKey();
    00110
    00111                 if((key == eKeyUp || key == eKeyUpLeft || key == eKeyUpRight) && pButtonEvent->IsKeyDown())
    00112                 {
    00113                         m_selectedEntry--;
    00114                         if(m_selectedEntry < 0)
    00115                                 m_selectedEntry = 0;
    00116
    00117                         return true;
    00118                 }
    00119
    00120                 if((key == eKeyDown || key == eKeyDownLeft || key == eKeyDownRight) && pButtonEvent->IsKeyDown())
    00121                 {
    00122                         m_selectedEntry++;
    00123                         if(m_selectedEntry >= m_vMenuEntries.size())
    00124                                 m_selectedEntry = m_vMenuEntries.size() - 1;
    00125
    00126                         return true;
    00127                 }
    00128
    00129                 if(key == eKeyButtonB)
    00130                 {
    00131                         std::string name = m_vMenuEntries[m_selectedEntry].Name;
    00132
    00133                         if(name == MENU_START_GAME_TEXT)
    00134                         {
    00135                                 BreakoutStartGameEvent* pStartEvent = new BreakoutStartGameEvent();
    00136                                 EventManager::getSingleton()->QueueEvent(pStartEvent);
    00137                         }
    00138                         else if(name == MENU_QUIT_GAME_TEXT)
    00139                         {
    00140                                 ApplicationQuitEvent* pQuitEvent = new ApplicationQuitEvent();
    00141                                 EventManager::getSingleton()->QueueEvent(pQuitEvent);
    00142                         }
    00143
    00144                         return true;
    00145                 }
    00146         }
    00147         return false;
    00148 }