#include "Power.h" Power::Power(SDL_Surface *screen, Collisions *gestionnaireCollisons, Sounderer *mediaPlayer, SDL_Surface* apparence) : m_screen(screen), m_image(apparence), m_gestionnaireCollisions(gestionnaireCollisons), m_mediaPlayer(mediaPlayer), m_used(false), m_estPose(true) { }///Constructeur Power::~Power() { }///Destructeur //Fonctions pour le tableauPower void Power::attribuer() { m_estPose = false; //SDL_SetAlpha(m_image, SDL_SRCALPHA, 128); }///attribuer void Power::afficher(int x, int y) { m_position.x = x * 20; m_position.y = y * 20; SDL_BlitSurface(m_image, 0, m_screen, &m_position); }///afficher bool Power::estUtilise() { return m_used; } bool Power::estPose() { return m_estPose; }///estAttribue void Power::convertDir(int orientation, int &ajoutX, int &ajoutY) const { ajoutX = 0; ajoutY = 0; switch (orientation) { case HAUT: ajoutY=-1; break; case DROITE: ajoutX=1; break; case BAS: ajoutY=1; break; case GAUCHE: ajoutX=-1; break; } } /********************************************* class TableauPower *********************************************/ TableauPower::TableauPower(SDL_Surface *screen, Collisions *gestionnaireCollisons, int nbPow) : m_screen(screen), m_gestionnaireCollisions(gestionnaireCollisons), m_spriteGet(0), m_mediaPlayer(0), m_nbPow(nbPow) { //Sprites loader m_spriteGet = new SpriteLoader("Textures/"); SDL_SetColorKey(m_spriteGet->takeSprite("Missile"), SDL_SRCCOLORKEY ,SDL_MapRGB(screen->format,255,255,255)); SDL_SetColorKey(m_spriteGet->takeSprite("Expansion"), SDL_SRCCOLORKEY ,SDL_MapRGB(screen->format,255,255,255)); SDL_SetColorKey(m_spriteGet->takeSprite("Boost"), SDL_SRCCOLORKEY ,SDL_MapRGB(screen->format,255,255,255)); SDL_SetColorKey(m_spriteGet->takeSprite("Teleport"), SDL_SRCCOLORKEY ,SDL_MapRGB(screen->format,255,255,255)); SDL_SetColorKey(m_spriteGet->takeSprite("Bouclier"), SDL_SRCCOLORKEY ,SDL_MapRGB(screen->format,255,255,255)); SDL_SetColorKey(m_spriteGet->takeSprite("Trender"), SDL_SRCCOLORKEY ,SDL_MapRGB(screen->format,255,255,255)); SDL_SetColorKey(m_spriteGet->takeSprite("Tunnel"), SDL_SRCCOLORKEY ,SDL_MapRGB(screen->format,255,255,255)); SDL_SetColorKey(m_spriteGet->takeSprite("Bomb"), SDL_SRCCOLORKEY ,SDL_MapRGB(screen->format,255,255,255)); //Sounderer m_mediaPlayer = new Sounderer("Sons/"); if (m_mediaPlayer->init()) { m_mediaPlayer->preLoad("Mort", EXT_OGG); m_mediaPlayer->preLoad("Missile", EXT_OGG); m_mediaPlayer->preLoad("Expansion", EXT_OGG); m_mediaPlayer->preLoad("Boost", EXT_OGG); m_mediaPlayer->preLoad("Teleport", EXT_OGG); m_mediaPlayer->preLoad("Bouclier", EXT_OGG); m_mediaPlayer->preLoad("Trender", EXT_OGG); m_mediaPlayer->preLoad("Tunnel", EXT_OGG); m_mediaPlayer->preLoad("Bomb", EXT_OGG); //m_mediaPlayer->startMusic("musicMadagascar"); } //Tableaux statiques m_tableau = new Power*[m_nbPow]; for ( int i(0); i<2; i++ ) m_positions[i] = new int[m_nbPow]; // Powers for (int i(0); iestPose()) { pouvoirPotentiel = m_tableau[i]; m_tableau[i]->attribuer(); } return pouvoirPotentiel; }///chercherPouvoir Power* TableauPower::randomPower() { //[1] Démarrage Power *pouvoirAlea(0); //[2] Calculs alétoires switch (rand() % 8) { case 0: pouvoirAlea = new Missile(m_screen, m_gestionnaireCollisions, m_mediaPlayer, m_spriteGet->takeSprite("Missile")); break; case 1: pouvoirAlea = new Expansion(m_screen, m_gestionnaireCollisions, m_mediaPlayer, m_spriteGet->takeSprite("Expansion")); break; case 2: pouvoirAlea = new Boost(m_screen, m_gestionnaireCollisions, m_mediaPlayer, m_spriteGet->takeSprite("Boost")); break; case 3: pouvoirAlea = new Teleport(m_screen, m_gestionnaireCollisions, m_mediaPlayer, m_spriteGet->takeSprite("Teleport")); break; case 4: pouvoirAlea = new Bouclier(m_screen, m_gestionnaireCollisions, m_mediaPlayer, m_spriteGet->takeSprite("Bouclier")); break; case 5: pouvoirAlea = new Trender(m_screen, m_gestionnaireCollisions, m_mediaPlayer, m_spriteGet->takeSprite("Trender")); break; case 6: pouvoirAlea = new Tunnel(m_screen, m_gestionnaireCollisions, m_mediaPlayer, m_spriteGet->takeSprite("Tunnel")); break; case 7: pouvoirAlea = new Bomb(m_screen, m_gestionnaireCollisions, m_mediaPlayer, m_spriteGet->takeSprite("Bomb")); break; } //[3] Return return pouvoirAlea; }///randomPower void TableauPower::initialiser() { for (int i(0); igetSize(0);// x m_positions[1][i] = rand() % m_gestionnaireCollisions->getSize(1);// y }//for }///initialiser void TableauPower::actualiser() { for (int i(0); iestUtilise()) { delete m_tableau[i]; m_tableau[i]=0; } }///actualiser void TableauPower::afficher() { for (int i(0); iestPose()) m_tableau[i]->afficher(m_positions[0][i], m_positions[1][i]); }///afficher void TableauPower::bruiterMort() { m_mediaPlayer->play("Mort"); }///bruiterMort