#include "states.hpp" MenuState MenuState::m_MenuState; void MenuState::Init() { menu = new Menu(); menu->addItem("Play", play); menu->addItem("High Score", score); # ifdef DEBUG menu->addItem("Debug Info", Debug_Info); # endif menu->addItem("Exit", quit); # ifdef DEBUG std::cout << "MenuState Init Successful" << std::endl; # endif } void MenuState::Clean() { delete menu; # ifdef DEBUG std::cout << "MenuState Clean Successful" << std::endl; # endif } void MenuState::Pause() { # ifdef DEBUG std::cout << "MenuState Paused" << std::endl; # endif } void MenuState::Resume() { # ifdef DEBUG std::cout << "MenuState Resumed" << std::endl; # endif } void MenuState::HandleEvents(game* Game) { SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: Game->Quit(); break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: { Game->Quit(); } break; case SDLK_DOWN: menu->Down(Game); break; case SDLK_UP: menu->Up(Game); break; case SDLK_SPACE: menu->Execute(Game); break; case SDLK_RETURN: menu->Execute(Game); break; } break; } } } void MenuState::Update(game* Game) { SDL_FillRect(Game->GetScreen(), NULL, 0x000000); } // We have to change the way we get the screen in this function void MenuState::Draw(game* Game) { menu->Draw(Game); SDL_Flip(Game->GetScreen()); } void MenuState::play(game* Game) { Game->ChangeState(PlayState::Instance()); } void MenuState::score(game* Game) { Game->PushState(ScoreState::Instance()); } void MenuState::quit(game* Game) { Game->Quit(); } # ifdef DEBUG void MenuState::Debug_Info(game* Game) { std::cout << "\n\n=== DEBUG INFO ===\n" << std::endl; std::cout << "Number of States: " << Game->CountStates() << std::endl; std::cout << "\n=== Debug Info ===\n\n" << endl; } # endif