123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- #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); i<m_nbPow; i++)
- m_tableau[i] = 0;
- }///Constructeur
- TableauPower::~TableauPower()
- {
- //Sprites loader
- delete m_spriteGet;
- //Sounderer
- delete m_mediaPlayer;
- //Powers
- for (int i(0); i<m_nbPow; i++)
- {
- if (m_tableau[i] == 0)
- {}//Ne fait rien si le pointeur est déjà vide.
- else
- delete m_tableau[i];
- }
- // Tableaux
- for ( int i(0); i<2; i++ )
- delete[] m_positions[i];
- delete[] m_tableau;
- }///Destructeur
- Power* TableauPower::chercherPouvoir(int x, int y) const
- {
- Power *pouvoirPotentiel(0);
- for (int i(0); i<m_nbPow; i++)
- if (m_tableau[i]!=0)
- if (x == m_positions[0][i] && y == m_positions[1][i] && m_tableau[i]->estPose())
- {
- 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); i<m_nbPow; i++)
- {
- if (m_tableau[i] != 0)
- {
- delete m_tableau[i];
- m_tableau[i] = 0;
- }
- m_tableau[i] = randomPower();
- m_positions[0][i] = rand() % m_gestionnaireCollisions->getSize(0);// x
- m_positions[1][i] = rand() % m_gestionnaireCollisions->getSize(1);// y
- }//for
- }///initialiser
- void TableauPower::actualiser()
- {
- for (int i(0); i<m_nbPow; i++)
- if (m_tableau[i]!=0)
- if (m_tableau[i]->estUtilise())
- {
- delete m_tableau[i];
- m_tableau[i]=0;
- }
- }///actualiser
- void TableauPower::afficher()
- {
- for (int i(0); i<m_nbPow; i++)
- if (m_tableau[i]!=0)
- if (m_tableau[i]->estPose())
- m_tableau[i]->afficher(m_positions[0][i], m_positions[1][i]);
- }///afficher
- void TableauPower::bruiterMort()
- {
- m_mediaPlayer->play("Mort");
- }///bruiterMort
|