1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #include "Menestrel.h"
- Menestrel::Menestrel(Input *input, Niveau *terrain, Controle controle): Joueur(input, terrain, controle)
- {
- m_skin = IMG_Load("Skins/Menestrel.png");
- if(m_skin == 0)
- std::cout << "Erreur de chargement du skin Skins/Menestrel.png" << std::endl;
- }
- Menestrel::~Menestrel()
- {
- SDL_FreeSurface(m_skin);
- }
- void Menestrel::deplacer()
- {
- if(m_controle == local)
- {
- if(m_input->getTouches(SDLK_UP))
- m_nouvDir = Haut;
- else if(m_input->getTouches(SDLK_RIGHT))
- m_nouvDir = Droite;
- else if(m_input->getTouches(SDLK_DOWN))
- m_nouvDir = Bas;
- else if(m_input->getTouches(SDLK_LEFT))
- m_nouvDir = Gauche;
- }
- int posX = m_pos.x + (m_skin->w-LG_BLOC)/2;
- int posY = m_pos.y + (m_skin->h-LG_BLOC)/2;
- int dirPossible = Arret;
- if(m_terrain->typeBloc(posX-1, posY, 1) != MUR && m_terrain->typeBloc(posX-1, posY+LG_BLOC-1, 1) != MUR)
- dirPossible |= Gauche;
- if(m_terrain->typeBloc(posX+LG_BLOC, posY, 1) != MUR && m_terrain->typeBloc(posX+LG_BLOC, posY+LG_BLOC-1, 1) != MUR)
- dirPossible |= Droite;
- if(m_terrain->typeBloc(posX, posY-1, 1) != MUR && m_terrain->typeBloc(posX+LG_BLOC-1, posY-1, 1) != MUR)
- dirPossible |= Haut;
- if(m_terrain->typeBloc(posX, posY+LG_BLOC, 1) != MUR && m_terrain->typeBloc(posX+LG_BLOC-1, posY+LG_BLOC, 1) != MUR)
- dirPossible |= Bas;
- if(dirPossible & m_nouvDir)
- m_direction = m_nouvDir;
- if(dirPossible & m_direction)
- {
- m_pos+=m_direction;
- posX = m_pos.x + (m_skin->w-LG_BLOC)/2;
- posY = m_pos.y + (m_skin->h-LG_BLOC)/2;
- }
- else if((!(dirPossible&Haut) && !(dirPossible&Bas) && (m_direction == Gauche || m_direction == Droite)) ||
- (!(dirPossible&Gauche) && !(dirPossible&Droite) && (m_direction == Haut || m_direction == Bas)))
- {
- m_direction = m_direction==Gauche?Droite:m_direction==Droite?Gauche:m_direction==Haut?Bas:Haut;
- m_nouvDir = m_direction;
- }
- }
|