fysxasteroids/asteroids/Model.h

142 lines
4.1 KiB
C
Raw Permalink Normal View History

2010-04-05 23:38:59 +02:00
#ifndef _MODEL_H
#define _MODEL_H
#include "ModelBase.h"
#include "AsteroidsEnums.h"
namespace asteroids {
class Model : public Engine::ModelBase {
public:
virtual ~Model() {};
2010-04-05 23:38:59 +02:00
virtual void Process();
virtual void SetGameState (const unsigned int &state);
float GetWorldWidth ();
float GetWorldHeight ();
/* Event handler */
2010-06-10 23:30:29 +02:00
bool OnGameOver();
/** \brief Resets values from a previous game */
void OnNewGame ();
void OnShipExplode ();
void OnLevelComplete ();
2010-04-05 23:38:59 +02:00
/* Level loading etc. */
int DoLoadLevel (const char* filename);
int DoSaveLevel (const char* filename);
void LoadLevelFromIndex (unsigned int level_index);
2011-01-02 18:25:20 +01:00
void ResetLevel ();
void ReloadLevel();
void ProceedToNextLevel ();
2010-04-05 23:38:59 +02:00
int GetPlayerLives () { return mPlayerLives; };
2011-03-24 08:26:06 +01:00
void SetPlayerLives (int lives) { mPlayerLives = lives; };
2010-05-02 22:39:49 +02:00
unsigned int GetPoints () { return mPoints; };
2011-03-30 10:45:22 +02:00
unsigned int GetLevelPoints () { return mLevelPoints; };
unsigned int GetLevelTimeBonusPoints () { return mLevelTimeBonusPoints; };
2010-06-10 23:30:29 +02:00
std::string GetPlayerName() { return mPlayerName; };
void SetPlayerName(const std::string &name) {
Engine::LogDebug("new player name: %s", name.c_str());
mPlayerName = name;
};
2010-04-05 23:38:59 +02:00
2011-01-02 18:25:20 +01:00
std::string GetLevelName() { return mLevelName; };
void SetLevelName(const std::string &name) {
Engine::LogDebug("new level name: %s", name.c_str());
2011-01-02 18:25:20 +01:00
mLevelName = name;
}
std::string GetLevelAuthor() { return mLevelAuthor; };
void SetLevelAuthor(const std::string &author) {
Engine::LogDebug("new level author: %s", author.c_str());
mLevelAuthor = author;
}
std::string GetLevelTitle() { return mLevelTitle; };
void SetLevelTitle(const std::string &title) {
Engine::LogDebug("new level title: %s", title.c_str());
mLevelTitle = title;
}
2011-03-30 10:45:22 +02:00
float GetLevelTimeSeconds() { return mLevelTimeSeconds; };
float GetLevelParTimeSeconds() { return mLevelParTimeSeconds; };
/* Highscore */
2010-06-10 23:30:29 +02:00
struct HighscoreEntry {
HighscoreEntry(): name ("unknown"), points (0) { };
HighscoreEntry (const char *e_name, const unsigned int e_points):
name (e_name), points (e_points) { };
std::string name;
unsigned int points;
};
void ParseHighscoreStream (std::istream &highscore_stream);
2010-06-10 23:30:29 +02:00
void LoadHighscoreList ();
bool PullGlobalHighscore (std::stringstream &highscore_stream);
bool SubmitGlobalHigscoreEntry (std::string name, const unsigned int points);
void SubmitHighscoreEntry (const std::string &name, const unsigned int points);
unsigned int AddLocalHighscoreEntry(const std::string &name, const unsigned int points);
void LoadLocalHighscoreList ();
void SaveLocalHighscoreList ();
bool GetHighscoreIsOnline() { return mHighscoreIsOnline; };
2010-06-10 23:30:29 +02:00
std::list<HighscoreEntry> mHighscoreList;
unsigned int mNewestHighscoreEntryIndex;
2011-03-22 23:01:44 +01:00
unsigned int GetCurrentLevelIndex () {
return mCurrentLevelIndex;
}
bool GetGameModified() { return mGameModified; }
2011-06-20 22:06:35 +02:00
2010-04-05 23:38:59 +02:00
protected:
/** \brief Initializes the system */
virtual int OnInit (int argc, char* argv[]);
virtual void OnDestroy();
2010-04-05 23:38:59 +02:00
virtual void OnRegisterCommands ();
virtual void OnCreateEntity (const int type, const unsigned int id);
virtual void OnKillEntity (const Engine::EntityBase *entity);
private:
unsigned int InitLevelList ();
2010-04-05 23:38:59 +02:00
/** \brief Keeps a list of all asteroids */
std::vector<unsigned int> mAsteroids;
std::map<std::string, std::string> mLevelHashes;
bool mGameModified;
bool mCurrentLevelModified;
2010-04-05 23:38:59 +02:00
int mPlayerLives;
2010-05-02 22:39:49 +02:00
unsigned int mPoints;
unsigned int mCurrentLevelIndex;
2011-01-02 18:25:20 +01:00
2010-06-10 23:30:29 +02:00
std::string mPlayerName;
std::vector<std::string> mLevelList;
2011-01-02 18:25:20 +01:00
std::string mLevelName;
std::string mLevelAuthor;
std::string mLevelTitle;
2011-03-30 10:45:22 +02:00
unsigned int mLevelPoints;
float mLevelTimeSeconds;
// par time (= my run through, rounded down + 30 seconds
float mLevelParTimeSeconds;
unsigned int mLevelTimeBonusPoints;
static Engine::Variable HighscoreServerName;
static Engine::Variable HighscoreServerPath;
static Engine::Variable UseServerHighscore;
static Engine::Variable UseServerHighscoreAsked;
bool mHighscoreIsOnline;
virtual bool OnReceiveEvent (const Engine::EventBasePtr &event);
2010-04-05 23:38:59 +02:00
friend class View;
2011-01-02 18:25:20 +01:00
friend class Controller;
2010-04-05 23:38:59 +02:00
};
}
#endif // _MODEL_H