#include "Fantome.h" int Fantome::m_multiKill = 0; Fantome::Fantome(Niveau *terrain, Ogre *ogre, Menestrel *menestrel, Controle controle): Personnage(), m_controle(controle), m_ogre(ogre), m_menestrel(menestrel), m_tempsRestant(0), m_vivant(true) { m_terrain = terrain; m_direction = Arret; m_nouvDir = Arret; m_skin = IMG_Load("Skins/Fantome.png"); if(m_skin == 0) std::cout << "Erreur de chargement du skin Skins/Fantome.png" << std::endl; } Fantome::~Fantome() { SDL_FreeSurface(m_skin); } void Fantome::deplacer() { if(!m_vivant) { if(SDL_GetTicks()w-LG_BLOC)/2; int posY = m_pos.y + (m_skin->h-LG_BLOC)/2; int FdirPossible = Arret; if(m_terrain->typeBloc(posX, posY-1, 1) != MUR && m_terrain->typeBloc(posX+LG_BLOC-1, posY-1, 1) != MUR) FdirPossible |= Haut; if(m_terrain->typeBloc(posX+LG_BLOC, posY, 1) != MUR && m_terrain->typeBloc(posX+LG_BLOC, posY+LG_BLOC-1, 1) != MUR) FdirPossible |= Droite; if(m_terrain->typeBloc(posX, posY+LG_BLOC, 1) != MUR && m_terrain->typeBloc(posX+LG_BLOC-1, posY+LG_BLOC, 1) != MUR) FdirPossible |= Bas; if(m_terrain->typeBloc(posX-1, posY, 1) != MUR && m_terrain->typeBloc(posX-1, posY+LG_BLOC-1, 1) != MUR) FdirPossible |= Gauche; int dirPerso = Arret; if(m_menestrel->getPosition().y < getPosition().y) dirPerso |= Haut; if(m_menestrel->getPosition().x > getPosition().x) dirPerso |= Droite; if(m_menestrel->getPosition().y > getPosition().y) dirPerso |= Bas; if(m_menestrel->getPosition().x < getPosition().x) dirPerso |= Gauche; std::vector nouvDir; for(int i = 0;i<4;i++) { if((m_nouvDir = (Direction)(FdirPossible & (int)pow(2, i)))) if(((m_direction<<2) != m_nouvDir) && ((m_direction>>2) != m_nouvDir)) nouvDir.push_back((Direction)pow(2, i)); } if(nouvDir.size()>0) { if(nouvDir.size()>1) { int nouvDirTaille = nouvDir.size(); for(int i = 0;iw-LG_BLOC)/2; m_pos.y = position.y*LG_BLOC - (m_skin->h-LG_BLOC)/2; } int posX = m_pos.x + (m_skin->w-LG_BLOC)/2; int posY = m_pos.y + (m_skin->h-LG_BLOC)/2; std::vector dirPossible; if(m_terrain->typeBloc(posX-1, posY, 1) != MUR && m_terrain->typeBloc(posX-1, posY+LG_BLOC-1, 1) != MUR) dirPossible.push_back(Gauche); if(m_terrain->typeBloc(posX+LG_BLOC, posY, 1) != MUR && m_terrain->typeBloc(posX+LG_BLOC, posY+LG_BLOC-1, 1) != MUR) dirPossible.push_back(Droite); if(m_terrain->typeBloc(posX, posY-1, 1) != MUR && m_terrain->typeBloc(posX+LG_BLOC-1, posY-1, 1) != MUR) dirPossible.push_back(Haut); if(m_terrain->typeBloc(posX, posY+LG_BLOC, 1) != MUR && m_terrain->typeBloc(posX+LG_BLOC-1, posY+LG_BLOC, 1) != MUR) dirPossible.push_back(Bas); if(dirPossible.size()>0) m_direction = dirPossible[rand()%dirPossible.size()]; m_nouvDir = m_direction; m_tempsRestant = 0; } void Fantome::afficher(SDL_Surface *ecran) { if(m_vivant) SDL_BlitSurface(m_skin, 0, ecran, &m_pos); } void Fantome::tuer() { m_multiKill++; m_vivant = false; m_tempsRestant = SDL_GetTicks()+TEMPS_MORT; } bool Fantome::vivant() { return m_vivant; } bool Fantome::getMultiKill(int nbFantomes) { if(nbFantomes == m_multiKill) { m_multiKill = 0; return true; } else return false; }