123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- #include "Armes_Gest.h"
- /// ~~~ ARMES_GEST IMPLEMENTATION ~~~ ----------------------------------------------------------------- VVVVV
- Armes_Gest::Armes_Gest( SpriteLoader* sprites )
- {
- /// Chargement des images
- // Chargement des images
- m_armeImg[ GUN ] = sprites->takeSprite("Gun");
- m_armeImg[ FUSIL ] = sprites->takeSprite("Fusil");
- m_armeImg[ SHOTGUN ] = sprites->takeSprite("Shotgun");
- m_armeImg[ USIANE ] = sprites->takeSprite("Usiane");
- m_armeImg[ SCATTER ] = sprites->takeSprite("Scatter");
- m_armeImg[ BAROUDEUR ] = sprites->takeSprite("Baroudeur");
- m_armeImg[ SULFATEUSE ] = sprites->takeSprite("Sulfateuse");
- m_armeImg[ TRIPHASEUR ] = sprites->takeSprite("Triphaseur");
- m_armeImg[ BOMBER ] = sprites->takeSprite("Bomber");
- // On enlève le transparent
- Uint32 noir( SDL_MapRGBA( m_armeImg[0]->format, 0, 0, 0, 255 ) );
- for (Uint8 i(0); i < NB_MODELS; i++) {
- SDL_SetColorKey(m_armeImg[i], SDL_SRCCOLORKEY, noir);
- }
- /// Création des Crafts
- m_crafts[ Craft( SHOTGUN, BAROUDEUR ) ] = BOMBER;
- m_crafts[ Craft( FUSIL, SCATTER ) ] = TRIPHASEUR;
- m_crafts[ Craft( FUSIL, SHOTGUN ) ] = BAROUDEUR;
- m_crafts[ Craft( GUN, USIANE ) ] = SULFATEUSE;
- m_crafts[ Craft( GUN, SHOTGUN ) ] = USIANE;
- m_crafts[ Craft( GUN, FUSIL ) ] = SCATTER;
- }
- Armes_Gest::~Armes_Gest()
- {
- for (m_itList = m_posees.begin(); m_itList != m_posees.end(); m_itList++){
- delete (*m_itList);
- }
- }
- SDL_Surface* Armes_Gest::getImg( WeaponType model ) const
- {
- return m_armeImg[ model ];
- }
- void Armes_Gest::allDisplay( const Vec &lookAt, SDL_Surface* screen )
- {
- for (m_itList = m_posees.begin(); m_itList != m_posees.end(); m_itList++){
- (*m_itList)->afficher( lookAt, screen );
- }
- }
- void Armes_Gest::drop( Vec pos, Arme* weapon )
- {
- m_posees.insert( m_posees.begin(), new CaisseArme( m_armeImg[ weapon->getModel() ], weapon, pos) );
- }
- Arme* Armes_Gest::saisir( Vec pos )
- {
- Arme* weapon( 0x0 );
- if (m_posees.empty()) std::cout << "Mais il n'y a pas d'arme sur le sol !" << std::endl;
- for (m_itList = m_posees.begin(); m_itList != m_posees.end() && weapon == 0x0; m_itList++){
- if ( (*m_itList)->proxi( pos ) ) {
- weapon = (*m_itList)->takeWeapon();
- m_posees.erase( m_itList );
- }
- }
- return weapon;
- }
- Arme* Armes_Gest::crafting( Arme* paire[2], Tirs_Gest* tirsGest )
- {
- std::cout << "Crafting : " << std::endl;
- Craft* prod(0x0);
- prod = new Craft( paire[0]->getModel(), paire[1]->getModel() );
- WeaponType resultat;
- Arme* renvoi(0x0);
- m_itMap = m_crafts.find( *prod );
- if ( m_itMap == m_crafts.end() ) std::cout << "Combinaison inexistante.";
- else {
- resultat = m_crafts[ *prod ];
- renvoi = takeWeapon( resultat, tirsGest );
- std::cout << "Arme obtenue : " << resultat;
- }
- std::cout << std::endl << std::endl << std::endl;
- delete prod;
- return renvoi;
- }
- Arme* Armes_Gest::takeWeapon( WeaponType model, Tirs_Gest* tirsGest ) const
- {
- switch ( model)
- {
- case GUN :
- return new Gun( tirsGest );
- break;
- case FUSIL :
- return new Fusil( tirsGest );
- break;
- case SHOTGUN :
- return new Shotgun( tirsGest );
- break;
- case USIANE :
- return new Usiane( tirsGest );
- break;
- case SCATTER :
- return new Scatter( tirsGest );
- break;
- case BAROUDEUR :
- return new Baroudeur( tirsGest );
- break;
- case SULFATEUSE :
- return new Sulfateuse( tirsGest );
- break;
- case TRIPHASEUR :
- return new Triphaseur( tirsGest );
- break;
- case BOMBER :
- return new Bomber( tirsGest );
- break;
- default:
- return 0x0;
- break;
- }
- }
- Arme* Armes_Gest::startWeapon( Tirs_Gest* tirsGest ) const
- {
- int choice( rand() % 3 );
- return takeWeapon( (WeaponType)choice, tirsGest );
- }
- /// ~~~ CRAFT IMPLEMENTATION ~~~ ----------------------------------------------------------------- VVVVV
- Craft::Craft()
- :m_a(GUN), m_b(SHOTGUN)
- {
- }
- Craft::Craft( WeaponType a, WeaponType b )
- {
- if ( a < b ) {
- m_a = a;
- m_b = b;
- }
- else {
- m_a = b;
- m_b = a;
- }
- }
- Craft::~Craft()
- {
- }
- void Craft::debugCout() const
- {
- std::cout <<"Arme A : "<< m_a << std::endl;
- std::cout <<"Arme B : "<< m_b << std::endl << std::endl;
- }
- bool Craft::operator<( const Craft& a ) const
- {
- if ( m_a < a.m_a )
- return true;
- else
- return m_b < a.m_b;
- }
|