111 lines
1.6 KiB
C++
111 lines
1.6 KiB
C++
#include "states.hpp"
|
|
|
|
|
|
PauseState PauseState::m_PauseState;
|
|
|
|
void PauseState::Init()
|
|
{
|
|
menu = new Menu();
|
|
|
|
menu->addItem("Resume", resume);
|
|
menu->addItem("To menu", go_to_menu);
|
|
menu->addItem("Exit", quit);
|
|
|
|
# ifdef DEBUG
|
|
std::cout << "PauseState Init Successful" << std::endl;
|
|
# endif
|
|
}
|
|
|
|
void PauseState::Clean()
|
|
{
|
|
delete menu;
|
|
|
|
# ifdef DEBUG
|
|
std::cout << "PauseState Clean Successful" << std::endl;
|
|
# endif
|
|
}
|
|
|
|
void PauseState::Pause()
|
|
{
|
|
# ifdef DEBUG
|
|
std::cout << "PauseState Paused" << std::endl;
|
|
# endif
|
|
}
|
|
|
|
void PauseState::Resume()
|
|
{
|
|
# ifdef DEBUG
|
|
std::cout << "PauseState Resumed" << std::endl;
|
|
# endif
|
|
}
|
|
|
|
void PauseState::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->PopState();
|
|
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 PauseState::Update(game* Game)
|
|
{
|
|
SDL_FillRect(Game->GetScreen(), NULL, 0x000000);
|
|
}
|
|
|
|
// We have to change the way we get the screen in this function
|
|
void PauseState::Draw(game* Game)
|
|
{
|
|
menu->Draw(Game);
|
|
|
|
SDL_Flip(Game->GetScreen());
|
|
}
|
|
|
|
|
|
void PauseState::resume(game* Game)
|
|
{
|
|
Game->PopState();
|
|
}
|
|
|
|
void PauseState::go_to_menu(game* Game)
|
|
{
|
|
Game->DelStateF();
|
|
Game->ChangeState(MenuState::Instance());
|
|
}
|
|
|
|
void PauseState::quit(game* Game)
|
|
{
|
|
Game->Quit();
|
|
}
|