improved font handling and HUD
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "OverlayBase.h"
|
||||
#include "MenuOverlay.h"
|
||||
#include "Model.h"
|
||||
#include "View.h"
|
||||
#include "Sprite.h"
|
||||
#include "ShipEntity.h"
|
||||
|
||||
@@ -24,6 +25,11 @@ 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);
|
||||
}
|
||||
@@ -110,6 +116,8 @@ void MenuOverlay::Draw () {
|
||||
glPushMatrix ();
|
||||
glLoadIdentity ();
|
||||
|
||||
mView->SelectFont("console.ttf");
|
||||
|
||||
// then we do the drawings
|
||||
if (mModel->GetGameState() == GameStateRunning) {
|
||||
glClearColor (0., 0., 0., 1.);
|
||||
@@ -137,10 +145,17 @@ void MenuOverlay::DrawGameRunning() {
|
||||
right = static_cast<float> (Engine::GetWindowWidth());
|
||||
bottom = static_cast<float> (Engine::GetWindowHeight());
|
||||
|
||||
int i;
|
||||
for (i = 0; i < mModel->GetPlayerLives(); i++) {
|
||||
mShipSprite.DrawAt2D (right - 32 - i*20, bottom - 16);
|
||||
}
|
||||
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 () {
|
||||
|
||||
@@ -11,6 +11,7 @@ class OverlayBase;
|
||||
namespace asteroids {
|
||||
|
||||
class Model;
|
||||
class View;
|
||||
|
||||
class MenuOverlay : public Engine::OverlayBase {
|
||||
public:
|
||||
@@ -30,9 +31,11 @@ class MenuOverlay : public Engine::OverlayBase {
|
||||
void DrawPlayerDied ();
|
||||
|
||||
void SetModel (Model *model) { mModel = model; };
|
||||
void SetView (View *view) { mView = view; };
|
||||
|
||||
private:
|
||||
Model *mModel;
|
||||
View *mView;
|
||||
Engine::Sprite mShipSprite;
|
||||
};
|
||||
|
||||
|
||||
+8
-4
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "EntityFactory.h"
|
||||
#include "AsteroidsEvents.h"
|
||||
#include "AsteroidEntity.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
@@ -56,6 +57,7 @@ void Model::Process () {
|
||||
if (mLastGameState == GameStateMainMenu && mGameState == GameStateRunning) {
|
||||
mPlayerLives = 3;
|
||||
mCurrentLevelIndex = 0;
|
||||
mPoints = 0;
|
||||
DoLoadLevel (mLevelList[mCurrentLevelIndex].c_str());
|
||||
}
|
||||
else if (mLastGameState == GameStateRunning && mGameState == GameStatePlayerDied) {
|
||||
@@ -75,8 +77,7 @@ void Model::Process () {
|
||||
}
|
||||
}
|
||||
else if (mLastGameState == GameStatePlayerDied && mGameState == GameStateRunning)
|
||||
// DoLoadLevel (mLevelPath);
|
||||
assert (0);
|
||||
DoLoadLevel(mLevelList[mCurrentLevelIndex].c_str());
|
||||
else if (mLastGameState == GameStateRunning && mGameState == GameStateGameOver)
|
||||
ClearEntities();
|
||||
|
||||
@@ -105,13 +106,14 @@ unsigned int Model::InitLevelList () {
|
||||
Engine::LogError ("Could not init level list: %s is not a directory!");
|
||||
}
|
||||
|
||||
|
||||
boost::filesystem::directory_iterator end_iter;
|
||||
for (boost::filesystem::directory_iterator dir_iter(level_dir);
|
||||
dir_iter != end_iter;
|
||||
++dir_iter) {
|
||||
if (boost::filesystem::is_regular_file (dir_iter->status())) {
|
||||
mLevelList.push_back (std::string(level_dir_name) + dir_iter->path().filename());
|
||||
std::string level_relative_path (level_dir_name);
|
||||
level_relative_path += dir_iter->path().filename();
|
||||
mLevelList.push_back (level_relative_path);
|
||||
Engine::LogDebug ("Found level %s", mLevelList[mLevelList.size()-1].c_str());
|
||||
}
|
||||
}
|
||||
@@ -248,6 +250,8 @@ void Model::OnKillEntity (const Engine::EntityBase *entity) {
|
||||
|
||||
if (entity_type == GameEntityTypeAsteroid) {
|
||||
unsigned int i;
|
||||
const AsteroidEntity *asteroid = static_cast<const AsteroidEntity*>(entity);
|
||||
mPoints += 150 + asteroid->mSubAsteroidsCount * 75;
|
||||
|
||||
for (i = 0; i < mAsteroids.size(); i++) {
|
||||
if (mAsteroids.at(i) == entity->mId) {
|
||||
|
||||
@@ -21,6 +21,7 @@ class Model : public Engine::ModelBase {
|
||||
GameState GetGameState () { return mGameState; };
|
||||
|
||||
int GetPlayerLives () { return mPlayerLives; };
|
||||
unsigned int GetPoints () { return mPoints; };
|
||||
|
||||
float GetWorldWidth ();
|
||||
float GetWorldHeight ();
|
||||
@@ -31,6 +32,7 @@ class Model : public Engine::ModelBase {
|
||||
virtual void OnDestroy() {
|
||||
Engine::ModelBase::OnDestroy();
|
||||
mAsteroids.clear();
|
||||
mLevelList.clear();
|
||||
delete mLevelCompleteEventHandler;
|
||||
};
|
||||
virtual void OnRegisterCommands ();
|
||||
@@ -48,6 +50,7 @@ class Model : public Engine::ModelBase {
|
||||
GameState mLastGameState;
|
||||
|
||||
int mPlayerLives;
|
||||
unsigned int mPoints;
|
||||
std::vector<std::string> mLevelList;
|
||||
unsigned int mCurrentLevelIndex;
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ int View::OnInit (int argc, char* argv[]) {
|
||||
// We want menu
|
||||
mMenuOverlay = boost::shared_ptr<MenuOverlay> (new MenuOverlay);
|
||||
mMenuOverlay->SetModel ((Model*) mModel);
|
||||
mMenuOverlay->SetView (this);
|
||||
mMenuOverlay->Init();
|
||||
AddOverlay (mMenuOverlay);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user