Personnage.cpp 978 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "Personnage.h"
  2. SDL_Rect operator+=(SDL_Rect &pos, Direction dir)
  3. {
  4. switch(dir)
  5. {
  6. case Arret:
  7. break;
  8. case Haut:
  9. pos.y -= 1;
  10. break;
  11. case Droite:
  12. pos.x += 1;
  13. break;
  14. case Bas:
  15. pos.y += 1;
  16. break;
  17. case Gauche:
  18. pos.x -= 1;
  19. break;
  20. }
  21. return pos;
  22. }
  23. void Personnage::afficher(SDL_Surface *ecran)
  24. {
  25. SDL_BlitSurface(m_skin, 0, ecran, &m_pos);
  26. }
  27. SDL_Rect Personnage::getPosition(bool coordonnee)
  28. {
  29. if(coordonnee)
  30. return m_pos;
  31. else
  32. {
  33. SDL_Rect pos;
  34. pos.x = m_pos.x+(m_skin->w-LG_BLOC)/2+LG_BLOC/2;
  35. pos.x /= LG_BLOC;
  36. pos.y = m_pos.y+(m_skin->h-LG_BLOC)/2+LG_BLOC/2;
  37. pos.y /= LG_BLOC;
  38. return pos;
  39. }
  40. }
  41. bool operator==(SDL_Rect pos1, SDL_Rect pos2)
  42. {
  43. if(pos1.x==pos2.x && pos1.y==pos2.y)
  44. return true;
  45. else
  46. return false;
  47. }