1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| class World
{
private:
std::vector<IEntity*> entities; // ensemble des entités de la zone de jeu
Core::XmlManager* pXmlManager; // gestion du fichier xml de config du jeu
IVect2D pos; // position de la zone dans la map courante
int idCurrent; // id de la zone courante dans la map courante
int idCurrentMap; // id de la map courante (une map contient plusieurs zones)
int idCurrentMask; // id du masque correspondant à la map courante
public:
World();
~World();
bool load();
bool draw(const Core::IRenderer& r);
bool update(int direction, int buttons);
};
// implémentation de la classe World :
World::World()
{
.....
}
World::~World()
{
....
}
bool World::load()
{
int idTemp = LOAD_FAILED;
// des chargements
....
idCurrentMap = IM->loadImage("data/map/overworld/1.bmp", false);
idCurrentMask = IM->loadImage("data/map/overworld/1m.bmp", false);
// chargement du sprite via le ImageManager
idTemp = IM->loadImage("data/link_mouvement.bmp");
// création d'un sprite
if (idTemp != LOAD_FAILED)
{
AnimatedSprite* aS = new AnimatedSprite(
IM->getImageSizeById(idTemp),
IVect2D(100,10), idTemp, USize2D(16*3,16*3), true, 10);
Player* p = new Player(aS);
idTemp = IM->loadImage("data/1.bmp", true);
AnimatedSprite* cS = new AnimatedSprite(
IM->getImageSizeById(idTemp),
IVect2D(100,10), idTemp, USize2D(16,16), false, 10);
Enemy* e = new Enemy(cS);
entities.push_back(e);
entities.push_back(p);
return true;
}
else return false;
}
bool World::draw(const Core::IRenderer& r)
{
bool bOk = true;
// dessine le terrain
//r.drawSurface(idCurrentMap, IVect2D(0,16), Rect(pos, USize2D(320, 256)));
std::vector<IEntity*>::const_iterator it;
for (it = entities.begin(); it != entities.end(); ++it)
{
bOk &= (*it)->draw(r);
}
return bOk;
}
bool World::update(int direction, int buttons)
{
bool bOk = true;
std::vector<IEntity*>::const_iterator it;
for (it = entities.begin(); it != entities.end(); ++it)
{
bOk &= (*it)->move(direction);
bOk &= (*it)->update(direction, buttons);
}
return bOk;
} |
Partager