fysxasteroids/asteroids/Model.h

69 lines
1.6 KiB
C++

#ifndef _MODEL_H
#define _MODEL_H
#include "ModelBase.h"
#include "AsteroidsEnums.h"
namespace asteroids {
class Model : public Engine::ModelBase {
public:
virtual ~Model() {};
virtual void Process();
int DoLoadLevel (const char* filename);
int DoSaveLevel (const char* filename);
bool OnLevelComplete();
int GetPlayerLives () { return mPlayerLives; };
unsigned int GetPoints () { return mPoints; };
float GetWorldWidth ();
float GetWorldHeight ();
protected:
/** \brief Initializes the system */
virtual int OnInit (int argc, char* argv[]);
virtual void OnDestroy() {
Engine::ModelBase::OnDestroy();
mAsteroids.clear();
mLevelList.clear();
delete mLevelCompleteEventHandler;
};
virtual void OnRegisterCommands ();
virtual void OnCreateEntity (const int type, const unsigned int id);
virtual void OnKillEntity (const Engine::EntityBase *entity);
private:
unsigned int InitLevelList ();
/** \brief Keeps a list of all asteroids */
std::vector<unsigned int> mAsteroids;
int mPlayerLives;
unsigned int mPoints;
std::vector<std::string> mLevelList;
unsigned int mCurrentLevelIndex;
/* event handler class definitions */
class LevelCompleteEventHandler : public Engine::EventListenerBase {
public:
explicit LevelCompleteEventHandler (Model *view) : mModel (view) {};
virtual bool HandleEvent (const Engine::EventBasePtr &event) const {
return mModel->OnLevelComplete();
}
private:
LevelCompleteEventHandler() {};
Model *mModel;
};
/* event handler member variables */
LevelCompleteEventHandler *mLevelCompleteEventHandler;
friend class View;
};
}
#endif // _MODEL_H