moved menu states into separate directory
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#include "Engine.h"
|
||||
#include "Game.h"
|
||||
|
||||
#include "Model.h"
|
||||
#include "View.h"
|
||||
#include "Controller.h"
|
||||
|
||||
namespace asteroids {
|
||||
|
||||
Model *GetModel () {
|
||||
return dynamic_cast<Model*> (Engine::EngineGetModel());
|
||||
}
|
||||
|
||||
View *GetView () {
|
||||
return dynamic_cast<View*> (Engine::EngineGetView());
|
||||
}
|
||||
|
||||
Controller *GetController () {
|
||||
return dynamic_cast<Controller*> (Engine::EngineGetController());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
namespace asteroids {
|
||||
|
||||
class Model;
|
||||
class View;
|
||||
class Controller;
|
||||
|
||||
Model *GetModel ();
|
||||
View *GetView ();
|
||||
Controller *GetController ();
|
||||
|
||||
}
|
||||
#endif /* GAME_H */
|
||||
@@ -1,203 +0,0 @@
|
||||
#include "OGLFT.h"
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
#include "DrawingsGL.h"
|
||||
|
||||
#include "OverlayBase.h"
|
||||
#include "MenuOverlay.h"
|
||||
#include "Model.h"
|
||||
#include "View.h"
|
||||
#include "Sprite.h"
|
||||
#include "ShipEntity.h"
|
||||
|
||||
#include "Engine.h"
|
||||
|
||||
namespace asteroids {
|
||||
|
||||
// static float left = 0;
|
||||
static float right = 0;
|
||||
// static float top = 0;
|
||||
static float bottom = 0;
|
||||
|
||||
void MenuOverlay::Init () {
|
||||
if (!mShipSprite.LoadFromPNG("./data/textures/ship.png"))
|
||||
Engine::LogError ("Could not load ship sprite!");
|
||||
|
||||
// setup of the HUD font
|
||||
mView->LoadFont ("AldotheApache.ttf", 20);
|
||||
mView->SelectFont ("AldotheApache.ttf");
|
||||
mView->SetFontJustification (Engine::FontJustificationRight);
|
||||
|
||||
assert (mShipSprite.GetWidth() > 1);
|
||||
mShipSprite.SetScale (0.1);
|
||||
}
|
||||
|
||||
bool MenuOverlay::OnKeyDown (const SDL_keysym &keysym) {
|
||||
if (mModel->GetGameState() == GameStateLevelComplete) {
|
||||
switch (keysym.sym) {
|
||||
case SDLK_RETURN:
|
||||
mModel->SetGameState(GameStateRunning);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
} else if (mModel->GetGameState() == GameStateRunning) {
|
||||
switch (keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
mModel->SetGameState(GameStatePaused);
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
} else if (mModel->GetGameState() == GameStateGameOver) {
|
||||
switch (keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
mModel->SetGameState(GameStateMainMenu);
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
mModel->SetGameState(GameStateMainMenu);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (mModel->GetGameState() == GameStateMainMenu
|
||||
|| mModel->GetGameState() == GameStatePaused) {
|
||||
switch (keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
Engine::RunCommand ("quit");
|
||||
return true;
|
||||
case SDLK_RETURN:
|
||||
mModel->SetGameState(GameStateRunning);
|
||||
return true;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
} else if (mModel->GetGameState() == GameStatePlayerDied) {
|
||||
switch (keysym.sym) {
|
||||
case SDLK_RETURN:
|
||||
mModel->SetGameState(GameStateRunning);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void MenuOverlay::Draw () {
|
||||
glClearColor (0.1, 0.1, 0.1, 1.);
|
||||
|
||||
right = static_cast<float> (Engine::GetWindowWidth());
|
||||
bottom = static_cast<float> (Engine::GetWindowHeight());
|
||||
|
||||
// we switch to orthographic projection and draw the contents of the 2d
|
||||
// overlay on top of the previous drawings
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
// first we have to get the size of the current viewport to set up the
|
||||
// orthographic projection correctly
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
gluOrtho2D (viewport[0], viewport[2], viewport[3], viewport[1]);
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
mView->SelectFont("console.ttf");
|
||||
|
||||
// then we do the drawings
|
||||
if (mModel->GetGameState() == GameStateRunning) {
|
||||
glClearColor (0., 0., 0., 1.);
|
||||
DrawGameRunning();
|
||||
} else if (mModel->GetGameState() == GameStateGameOver)
|
||||
DrawGameOverScreen ();
|
||||
else if (mModel->GetGameState() == GameStateMainMenu
|
||||
|| mModel->GetGameState() == GameStatePaused)
|
||||
DrawGameMenu ();
|
||||
else if (mModel->GetGameState() == GameStateLevelComplete)
|
||||
DrawGameLevelComplete ();
|
||||
else if (mModel->GetGameState() == GameStatePlayerDied)
|
||||
DrawPlayerDied();
|
||||
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
|
||||
};
|
||||
|
||||
void MenuOverlay::DrawGameRunning() {
|
||||
right = static_cast<float> (Engine::GetWindowWidth());
|
||||
bottom = static_cast<float> (Engine::GetWindowHeight());
|
||||
|
||||
mView->SelectFont ("AldotheApache.ttf");
|
||||
|
||||
std::ostringstream out_stream;
|
||||
out_stream << mModel->GetPlayerLives() << " x ";
|
||||
mView->DrawGLString (right - 64, bottom - 20, out_stream.str().c_str());
|
||||
|
||||
mShipSprite.DrawAt2D (right - 32 - 10, bottom - 16);
|
||||
|
||||
out_stream.str("");
|
||||
out_stream << mModel->GetPoints();
|
||||
mView->DrawGLString (right - 10, 40, out_stream.str().c_str());
|
||||
}
|
||||
|
||||
void MenuOverlay::DrawPlayerDied () {
|
||||
std::ostringstream topbar_stream;
|
||||
topbar_stream << "You died ...";
|
||||
Engine::DrawGLString ( right * 0.5 - 40, bottom * 0.5 - 8 - 32, topbar_stream.str().c_str ());
|
||||
|
||||
Engine::DrawGLString ( right * 0.5 - 90, bottom * 0.5 + 8, "Press [Return] to continue.");
|
||||
}
|
||||
|
||||
void MenuOverlay::DrawGameOverScreen() {
|
||||
std::ostringstream topbar_stream;
|
||||
|
||||
Engine::DrawGLString ( right * 0.5 - 60, bottom * 0.5 - 8 - 64, "G a m e O v e r");
|
||||
|
||||
if (mModel->GetPlayerLives() == 0) {
|
||||
topbar_stream << "That was pathetic! ";
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8, topbar_stream.str().c_str ());
|
||||
} else {
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 32, "You earned yourself the");
|
||||
Engine::DrawGLString ( right * 0.5 - 60, bottom * 0.5 + 0, "You Rock(TM) award.");
|
||||
Engine::DrawGLString ( right * 0.5 - 70, bottom * 0.5 + 32, "Go tell your friends.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MenuOverlay::DrawGameMenu() {
|
||||
Engine::DrawGLString ( right * 0.5 - 100, bottom * 0.5 - 8 - 64, "A s t e r o i d s");
|
||||
Engine::DrawGLString ( right * 0.5 - 100, bottom * 0.5 - 8 - 32, "Main Menu");
|
||||
|
||||
if (mModel->GetGameState() == GameStatePaused)
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8 - 16, "[Return] - Resume Game");
|
||||
else
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8 - 16, "[Return] - Start Game");
|
||||
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8, "[Escape] - Quit");
|
||||
}
|
||||
|
||||
void MenuOverlay::DrawGameLevelComplete() {
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8 - 16, "Congratulations - You rock!");
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8, "[Return] - Next level ...");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,411 @@
|
||||
#include "OGLFT.h"
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
#include "DrawingsGL.h"
|
||||
|
||||
#include "OverlayBase.h"
|
||||
#include "UserInterface.h"
|
||||
#include "Model.h"
|
||||
#include "View.h"
|
||||
#include "Sprite.h"
|
||||
#include "ShipEntity.h"
|
||||
|
||||
#include "Engine.h"
|
||||
#include "Game.h"
|
||||
|
||||
namespace asteroids {
|
||||
|
||||
// static float left = 0;
|
||||
static float right = 0;
|
||||
// static float top = 0;
|
||||
static float bottom = 0;
|
||||
|
||||
void MainMenuOverlay::Init () {
|
||||
// setup of the HUD font
|
||||
GetView()->LoadFont ("AldotheApache.ttf", 20);
|
||||
GetView()->SelectFont ("AldotheApache.ttf");
|
||||
GetView()->SetFontJustification (Engine::FontJustificationRight);
|
||||
}
|
||||
|
||||
bool MainMenuOverlay::OnKeyDown (const SDL_keysym &keysym) {
|
||||
switch (keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
Engine::RunCommand ("quit");
|
||||
return true;
|
||||
case SDLK_RETURN:
|
||||
GetModel()->SetGameState(GameStateRunning);
|
||||
return true;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void MainMenuOverlay::Draw () {
|
||||
glClearColor (0.1, 0.1, 0.1, 1.);
|
||||
|
||||
right = static_cast<float> (Engine::GetWindowWidth());
|
||||
bottom = static_cast<float> (Engine::GetWindowHeight());
|
||||
|
||||
// we switch to orthographic projection and draw the contents of the 2d
|
||||
// overlay on top of the previous drawings
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
// first we have to get the size of the current viewport to set up the
|
||||
// orthographic projection correctly
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
gluOrtho2D (viewport[0], viewport[2], viewport[3], viewport[1]);
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
GetView()->SelectFont("console.ttf");
|
||||
|
||||
// then we do the drawings
|
||||
Engine::DrawGLString ( right * 0.5 - 100, bottom * 0.5 - 8 - 64, "A s t e r o i d s");
|
||||
Engine::DrawGLString ( right * 0.5 - 100, bottom * 0.5 - 8 - 32, "Main Menu");
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8 - 16, "[Return] - Start Game");
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8, "[Escape] - Quit");
|
||||
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
|
||||
};
|
||||
|
||||
/**********************
|
||||
*
|
||||
* Game Running
|
||||
*
|
||||
**********************/
|
||||
|
||||
void GameRunningOverlay::Init () {
|
||||
if (!mShipSprite.LoadFromPNG("./data/textures/ship.png"))
|
||||
Engine::LogError ("Could not load ship sprite!");
|
||||
|
||||
// setup of the HUD font
|
||||
GetView()->LoadFont ("AldotheApache.ttf", 20);
|
||||
GetView()->SelectFont ("AldotheApache.ttf");
|
||||
GetView()->SetFontJustification (Engine::FontJustificationRight);
|
||||
|
||||
assert (mShipSprite.GetWidth() > 1);
|
||||
mShipSprite.SetScale (0.1);
|
||||
}
|
||||
|
||||
bool GameRunningOverlay::OnKeyDown (const SDL_keysym &keysym) {
|
||||
switch (keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
GetModel()->SetGameState(GameStatePaused);
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GameRunningOverlay::Draw () {
|
||||
glClearColor (0., 0., 0., 1.);
|
||||
|
||||
right = static_cast<float> (Engine::GetWindowWidth());
|
||||
bottom = static_cast<float> (Engine::GetWindowHeight());
|
||||
|
||||
// we switch to orthographic projection and draw the contents of the 2d
|
||||
// overlay on top of the previous drawings
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
// first we have to get the size of the current viewport to set up the
|
||||
// orthographic projection correctly
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
gluOrtho2D (viewport[0], viewport[2], viewport[3], viewport[1]);
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
// then we do the drawings
|
||||
right = static_cast<float> (Engine::GetWindowWidth());
|
||||
bottom = static_cast<float> (Engine::GetWindowHeight());
|
||||
|
||||
GetView()->SelectFont ("AldotheApache.ttf");
|
||||
|
||||
std::ostringstream out_stream;
|
||||
out_stream << GetModel()->GetPlayerLives() << " x ";
|
||||
GetView()->DrawGLString (right - 64, bottom - 20, out_stream.str().c_str());
|
||||
|
||||
mShipSprite.DrawAt2D (right - 32 - 10, bottom - 16);
|
||||
|
||||
out_stream.str("");
|
||||
out_stream << GetModel()->GetPoints();
|
||||
GetView()->DrawGLString (right - 10, 40, out_stream.str().c_str());
|
||||
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
|
||||
};
|
||||
|
||||
/**********************
|
||||
*
|
||||
* Game Over
|
||||
*
|
||||
**********************/
|
||||
|
||||
void GameOverOverlay::Init () {
|
||||
}
|
||||
|
||||
bool GameOverOverlay::OnKeyDown (const SDL_keysym &keysym) {
|
||||
switch (keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
GetModel()->SetGameState(GameStateMainMenu);
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
GetModel()->SetGameState(GameStateMainMenu);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GameOverOverlay::Draw () {
|
||||
glClearColor (0., 0., 0., 1.);
|
||||
|
||||
right = static_cast<float> (Engine::GetWindowWidth());
|
||||
bottom = static_cast<float> (Engine::GetWindowHeight());
|
||||
|
||||
// we switch to orthographic projection and draw the contents of the 2d
|
||||
// overlay on top of the previous drawings
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
// first we have to get the size of the current viewport to set up the
|
||||
// orthographic projection correctly
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
gluOrtho2D (viewport[0], viewport[2], viewport[3], viewport[1]);
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
GetView()->SelectFont("console.ttf");
|
||||
|
||||
// then we do the drawings
|
||||
std::ostringstream topbar_stream;
|
||||
|
||||
Engine::DrawGLString ( right * 0.5 - 60, bottom * 0.5 - 8 - 64, "G a m e O v e r");
|
||||
|
||||
if (GetModel()->GetPlayerLives() == 0) {
|
||||
topbar_stream << "That was pathetic! ";
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8, topbar_stream.str().c_str ());
|
||||
} else {
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 32, "You earned yourself the");
|
||||
Engine::DrawGLString ( right * 0.5 - 60, bottom * 0.5 + 0, "You Rock(TM) award.");
|
||||
Engine::DrawGLString ( right * 0.5 - 70, bottom * 0.5 + 32, "Go tell your friends.");
|
||||
}
|
||||
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
|
||||
};
|
||||
|
||||
/**********************
|
||||
*
|
||||
* Level Complete
|
||||
*
|
||||
**********************/
|
||||
|
||||
void LevelCompleteOverlay::Init () {
|
||||
}
|
||||
|
||||
bool LevelCompleteOverlay::OnKeyDown (const SDL_keysym &keysym) {
|
||||
switch (keysym.sym) {
|
||||
case SDLK_RETURN:
|
||||
GetModel()->SetGameState(GameStateRunning);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void LevelCompleteOverlay::Draw () {
|
||||
glClearColor (0., 0., 0., 1.);
|
||||
|
||||
right = static_cast<float> (Engine::GetWindowWidth());
|
||||
bottom = static_cast<float> (Engine::GetWindowHeight());
|
||||
|
||||
// we switch to orthographic projection and draw the contents of the 2d
|
||||
// overlay on top of the previous drawings
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
// first we have to get the size of the current viewport to set up the
|
||||
// orthographic projection correctly
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
gluOrtho2D (viewport[0], viewport[2], viewport[3], viewport[1]);
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
GetView()->SelectFont("console.ttf");
|
||||
|
||||
// then we do the drawings
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8 - 16, "Congratulations - You rock!");
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8, "[Return] - Next level ...");
|
||||
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
|
||||
};
|
||||
|
||||
/**********************
|
||||
*
|
||||
* Game Paused
|
||||
*
|
||||
**********************/
|
||||
|
||||
void GamePausedOverlay::Init () {
|
||||
}
|
||||
|
||||
bool GamePausedOverlay::OnKeyDown (const SDL_keysym &keysym) {
|
||||
switch (keysym.sym) {
|
||||
case SDLK_ESCAPE:
|
||||
Engine::RunCommand ("quit");
|
||||
return true;
|
||||
case SDLK_RETURN:
|
||||
GetModel()->SetGameState(GameStateRunning);
|
||||
return true;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void GamePausedOverlay::Draw () {
|
||||
glClearColor (0.1, 0.1, 0.1, 1.);
|
||||
|
||||
right = static_cast<float> (Engine::GetWindowWidth());
|
||||
bottom = static_cast<float> (Engine::GetWindowHeight());
|
||||
|
||||
// we switch to orthographic projection and draw the contents of the 2d
|
||||
// overlay on top of the previous drawings
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
// first we have to get the size of the current viewport to set up the
|
||||
// orthographic projection correctly
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
gluOrtho2D (viewport[0], viewport[2], viewport[3], viewport[1]);
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
GetView()->SelectFont("console.ttf");
|
||||
|
||||
// then we do the drawings
|
||||
Engine::DrawGLString ( right * 0.5 - 100, bottom * 0.5 - 8 - 64, "A s t e r o i d s");
|
||||
Engine::DrawGLString ( right * 0.5 - 100, bottom * 0.5 - 8 - 32, "Main Menu");
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8 - 16, "[Return] - Resume Game");
|
||||
Engine::DrawGLString ( right * 0.5 - 80, bottom * 0.5 - 8, "[Escape] - Quit");
|
||||
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
|
||||
};
|
||||
|
||||
/**********************
|
||||
*
|
||||
* Player Died
|
||||
*
|
||||
**********************/
|
||||
|
||||
void PlayerDiedOverlay::Init () {
|
||||
}
|
||||
|
||||
bool PlayerDiedOverlay::OnKeyDown (const SDL_keysym &keysym) {
|
||||
switch (keysym.sym) {
|
||||
case SDLK_RETURN:
|
||||
GetModel()->SetGameState(GameStateRunning);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlayerDiedOverlay::Draw () {
|
||||
glClearColor (0., 0., 0., 1.);
|
||||
|
||||
right = static_cast<float> (Engine::GetWindowWidth());
|
||||
bottom = static_cast<float> (Engine::GetWindowHeight());
|
||||
|
||||
// we switch to orthographic projection and draw the contents of the 2d
|
||||
// overlay on top of the previous drawings
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
// first we have to get the size of the current viewport to set up the
|
||||
// orthographic projection correctly
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
gluOrtho2D (viewport[0], viewport[2], viewport[3], viewport[1]);
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
GetView()->SelectFont("console.ttf");
|
||||
|
||||
// then we do the drawings
|
||||
std::ostringstream topbar_stream;
|
||||
topbar_stream << "You died ...";
|
||||
Engine::DrawGLString ( right * 0.5 - 40, bottom * 0.5 - 8 - 32, topbar_stream.str().c_str ());
|
||||
|
||||
Engine::DrawGLString ( right * 0.5 - 90, bottom * 0.5 + 8, "Press [Return] to continue.");
|
||||
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glPopMatrix ();
|
||||
|
||||
glMatrixMode (GL_MODELVIEW);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#ifndef USERINTERFACE
|
||||
#define USERINTERFACE
|
||||
|
||||
namespace Engine {
|
||||
class OverlayBase;
|
||||
}
|
||||
|
||||
#include "OverlayBase.h"
|
||||
#include "Sprite.h"
|
||||
|
||||
namespace asteroids {
|
||||
|
||||
class Model;
|
||||
class View;
|
||||
|
||||
class MainMenuOverlay : public Engine::OverlayBase {
|
||||
public:
|
||||
MainMenuOverlay () {
|
||||
};
|
||||
virtual ~MainMenuOverlay() {};
|
||||
|
||||
virtual void Init ();
|
||||
|
||||
virtual bool OnKeyDown (const SDL_keysym &keysym);
|
||||
virtual void Draw ();
|
||||
|
||||
private:
|
||||
Engine::Sprite mShipSprite;
|
||||
};
|
||||
|
||||
class GameRunningOverlay : public Engine::OverlayBase {
|
||||
public:
|
||||
GameRunningOverlay () {
|
||||
};
|
||||
virtual ~GameRunningOverlay() {};
|
||||
|
||||
virtual void Init ();
|
||||
|
||||
virtual bool OnKeyDown (const SDL_keysym &keysym);
|
||||
virtual void Draw ();
|
||||
|
||||
private:
|
||||
Engine::Sprite mShipSprite;
|
||||
};
|
||||
|
||||
class GameOverOverlay : public Engine::OverlayBase {
|
||||
public:
|
||||
GameOverOverlay () {
|
||||
};
|
||||
virtual ~GameOverOverlay() {};
|
||||
|
||||
virtual void Init ();
|
||||
|
||||
virtual bool OnKeyDown (const SDL_keysym &keysym);
|
||||
virtual void Draw ();
|
||||
};
|
||||
|
||||
class LevelCompleteOverlay : public Engine::OverlayBase {
|
||||
public:
|
||||
LevelCompleteOverlay () {
|
||||
};
|
||||
virtual ~LevelCompleteOverlay() {};
|
||||
|
||||
virtual void Init ();
|
||||
|
||||
virtual bool OnKeyDown (const SDL_keysym &keysym);
|
||||
virtual void Draw ();
|
||||
};
|
||||
|
||||
class GamePausedOverlay : public Engine::OverlayBase {
|
||||
public:
|
||||
GamePausedOverlay () {
|
||||
};
|
||||
virtual ~GamePausedOverlay() {};
|
||||
|
||||
virtual void Init ();
|
||||
|
||||
virtual bool OnKeyDown (const SDL_keysym &keysym);
|
||||
virtual void Draw ();
|
||||
};
|
||||
|
||||
class PlayerDiedOverlay : public Engine::OverlayBase {
|
||||
public:
|
||||
PlayerDiedOverlay () {
|
||||
};
|
||||
virtual ~PlayerDiedOverlay() {};
|
||||
|
||||
virtual void Init ();
|
||||
|
||||
virtual bool OnKeyDown (const SDL_keysym &keysym);
|
||||
virtual void Draw ();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* USERINTERFACE */
|
||||
|
||||
+18
-8
@@ -1,6 +1,6 @@
|
||||
#include "View.h"
|
||||
#include "CameraBase.h"
|
||||
#include "MenuOverlay.h"
|
||||
#include "UserInterface.h"
|
||||
#include "SimpleConsoleOverlay.h"
|
||||
|
||||
#include "Engine.h"
|
||||
@@ -30,17 +30,29 @@ int View::OnInit (int argc, char* argv[]) {
|
||||
ViewBase::OnInit (argc, argv);
|
||||
|
||||
// We want menu
|
||||
mMenuOverlay = boost::shared_ptr<MenuOverlay> (new MenuOverlay);
|
||||
mMenuOverlay->SetModel ((Model*) mModel);
|
||||
mMenuOverlay->SetView (this);
|
||||
mMenuOverlay->Init();
|
||||
mOverlayManager.Register (mMenuOverlay, GameStateMainMenu);
|
||||
Engine::OverlayBasePtr menu_overlay (new MainMenuOverlay);
|
||||
Engine::OverlayBasePtr game_running_overlay (new GameRunningOverlay);
|
||||
Engine::OverlayBasePtr game_over_overlay (new GameOverOverlay);
|
||||
Engine::OverlayBasePtr level_complete_overlay (new LevelCompleteOverlay);
|
||||
Engine::OverlayBasePtr game_paused_overlay (new GamePausedOverlay);
|
||||
Engine::OverlayBasePtr player_died_overlay (new PlayerDiedOverlay);
|
||||
|
||||
mOverlayManager.Register (menu_overlay, GameStateMainMenu);
|
||||
mOverlayManager.Register (game_running_overlay, GameStateRunning);
|
||||
mOverlayManager.Register (level_complete_overlay, GameStateLevelComplete);
|
||||
mOverlayManager.Register (game_over_overlay, GameStateGameOver);
|
||||
mOverlayManager.Register (player_died_overlay, GameStatePlayerDied);
|
||||
mOverlayManager.Register (game_paused_overlay, GameStatePaused);
|
||||
|
||||
mOverlayManager.InitOverlays();
|
||||
|
||||
/*
|
||||
// We want the console
|
||||
mConsoleOverlay = boost::shared_ptr<Engine::SimpleConsoleOverlay> (new Engine::SimpleConsoleOverlay);
|
||||
// We also want to display the log bar
|
||||
mConsoleOverlay->SetDrawLogBar (true);
|
||||
mOverlayManager.Register (mConsoleOverlay, GameStateMainMenu);
|
||||
*/
|
||||
|
||||
// This is a simple star field that makes the game so spacy
|
||||
int i;
|
||||
@@ -79,8 +91,6 @@ void View::OnDestroy() {
|
||||
mBackgroundStars.clear();
|
||||
mShipPartsEntityIds.clear();
|
||||
|
||||
mMenuOverlay.reset();
|
||||
|
||||
Engine::ViewBase::OnDestroy();
|
||||
}
|
||||
|
||||
|
||||
+2
-5
@@ -10,7 +10,6 @@
|
||||
|
||||
namespace asteroids {
|
||||
|
||||
class MenuOverlay;
|
||||
struct ShipEntity;
|
||||
struct AsteroidEntity;
|
||||
struct RocketEntity;
|
||||
@@ -43,10 +42,8 @@ class View : public Engine::ViewBase {
|
||||
void DrawRocket (RocketEntity *asteroid);
|
||||
void DrawShipPart (Engine::EntityBase *entity);
|
||||
|
||||
// Engine::OverlayBasePtr mMenuOverlay;
|
||||
// Engine::OverlayBasePtr mConsoleOverlay;
|
||||
boost::shared_ptr<MenuOverlay> mMenuOverlay;
|
||||
boost::shared_ptr<Engine::SimpleConsoleOverlay> mConsoleOverlay;
|
||||
// boost::shared_ptr<MenuOverlay> mMenuOverlay;
|
||||
// boost::shared_ptr<Engine::SimpleConsoleOverlay> mConsoleOverlay;
|
||||
|
||||
std::vector<BackgroundStar> mBackgroundStars;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user