treewars/titlescreen.cpp

72 lines
1.3 KiB
C++
Raw Normal View History

#include "titlescreen.h"
2011-06-29 01:44:28 +00:00
#include "drawutils.h"
#include "game.h"
#include "debug.h"
TitleScreen::TitleScreen(stack<GameState*>* state_stack,
SDL_Surface* display)
: GameState(state_stack, display)
{
background = NULL;
title_banner = NULL;
}
TitleScreen::~TitleScreen()
{
if (background != NULL)
SDL_FreeSurface(background);
if (background != NULL)
SDL_FreeSurface(title_banner);
}
bool TitleScreen::init()
{
2011-06-29 01:44:28 +00:00
background = DrawUtils::load("background.bmp");
if (background == NULL)
{
2011-06-29 02:14:55 +00:00
debug("TitleScreen::init(): error: Couldn't load background image");
2011-06-29 01:44:28 +00:00
return false;
}
title_banner = DrawUtils::load("title_banner.bmp");
2011-06-29 01:44:28 +00:00
if (title_banner == NULL)
{
2011-06-29 02:14:55 +00:00
debug("TitleScreen::init(): error: Couldn't load title banner");
2011-06-29 01:44:28 +00:00
return false;
}
2011-06-30 22:16:36 +00:00
DrawUtils::transpare(title_banner);
return true;
}
void TitleScreen::render()
{
DrawUtils::draw(display, background, 0, 0);
int x = display->w / 2 - (title_banner->w / 2);
int y = display->h / 2 - (title_banner->h / 2);
DrawUtils::draw(display, title_banner, x, y);
SDL_Flip(display);
}
void TitleScreen::on_lbutton_down(int x, int y)
{
state_stack->push(new Game(state_stack, display));
}
void TitleScreen::on_key_down(SDLKey sym, SDLMod mod, Uint16 unicode)
{
if (sym == SDLK_q && mod & KMOD_CTRL) throw StateExit();
}