#include "Collisions.h" Collisions::Collisions(SDL_Surface *screen, int const xBlocSize, int const yBlocSize) : m_screen(screen), m_xSize(xBlocSize), m_ySize(yBlocSize) { // Tableau dynamique m_tableau = new int*[yBlocSize]; for (int i(0); iw, m_screen->h, 32, 0, 0, 0, 0); m_position.x = m_position.y = 0; // Initialisation standard reinitialiser(); }///Constructeur Collisions::~Collisions() { // Destruction du tableau dynamique for (int i(0); i < m_ySize; i++) delete[] m_tableau[i]; delete[] m_tableau; m_tableau = 0; // Libération des surfaces for (int i(0); i<4; i++) SDL_FreeSurface(m_carre[i]); SDL_FreeSurface(m_sol); SDL_FreeSurface(m_terrain); SDL_FreeSurface(m_carreStd); }///Destructeur void Collisions::ajouter(int x, int y, int ID) { // Correction position coorectPos(x, y); // Blitage de surface m_position.y=y*20; m_position.x=x*20; if (0<=ID && ID<=4 && (m_tableau[y][x]==VIDE || m_tableau[y][x] == ID)) { m_tableau[y][x] = ID; SDL_BlitSurface(m_carre[ID], 0, m_terrain, &m_position); } else { m_tableau[y][x] = NEUTRE; SDL_BlitSurface(m_carreStd, 0, m_terrain, &m_position); } // Signalement }///ajouter void Collisions::enlever(int x, int y) { // Correction position coorectPos(x, y); // Blitage de surface m_position.y=y*20; m_position.x=x*20; SDL_BlitSurface(m_sol, 0, m_terrain, &m_position); // Signalement m_tableau[y][x] = VIDE; }///enlever int Collisions::tester(int x,int y) const { coorectPos(x,y); return m_tableau[y][x]; }///tester void Collisions::afficher() { SDL_BlitSurface(m_terrain, 0, m_screen, 0); }///dessiner void Collisions::reinitialiser() { for (int i(0); i < m_ySize; i++) { for (int j(0); j < m_xSize; j++) { m_tableau[i][j] = VIDE; m_position.y = i*20; m_position.x = j*20; SDL_BlitSurface(m_sol, 0, m_terrain, &m_position); } } }///reinitialiser void Collisions::coorectPos(int &x, int &y) const { while ( x >= m_xSize ) x -= m_xSize; while ( x < 0 ) x += m_xSize; while ( y >= m_ySize ) y -= m_ySize; while ( y < 0 ) y += m_ySize; }///coorectPos int Collisions::getSize(int idCoord) { if (idCoord) // y -> 1 return m_ySize; else // x -> 0 return m_xSize; }