Armes_Gest.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #include "Armes_Gest.h"
  2. /// ~~~ ARMES_GEST IMPLEMENTATION ~~~ ----------------------------------------------------------------- VVVVV
  3. Armes_Gest::Armes_Gest( SpriteLoader* sprites )
  4. {
  5. /// Chargement des images
  6. // Chargement des images
  7. m_armeImg[ GUN ] = sprites->takeSprite("Gun");
  8. m_armeImg[ FUSIL ] = sprites->takeSprite("Fusil");
  9. m_armeImg[ SHOTGUN ] = sprites->takeSprite("Shotgun");
  10. m_armeImg[ USIANE ] = sprites->takeSprite("Usiane");
  11. m_armeImg[ SCATTER ] = sprites->takeSprite("Scatter");
  12. m_armeImg[ BAROUDEUR ] = sprites->takeSprite("Baroudeur");
  13. m_armeImg[ SULFATEUSE ] = sprites->takeSprite("Sulfateuse");
  14. m_armeImg[ TRIPHASEUR ] = sprites->takeSprite("Triphaseur");
  15. m_armeImg[ BOMBER ] = sprites->takeSprite("Bomber");
  16. // On enlève le transparent
  17. Uint32 noir( SDL_MapRGBA( m_armeImg[0]->format, 0, 0, 0, 255 ) );
  18. for (Uint8 i(0); i < NB_MODELS; i++) {
  19. SDL_SetColorKey(m_armeImg[i], SDL_SRCCOLORKEY, noir);
  20. }
  21. /// Création des Crafts
  22. m_crafts[ Craft( SHOTGUN, BAROUDEUR ) ] = BOMBER;
  23. m_crafts[ Craft( FUSIL, SCATTER ) ] = TRIPHASEUR;
  24. m_crafts[ Craft( FUSIL, SHOTGUN ) ] = BAROUDEUR;
  25. m_crafts[ Craft( GUN, USIANE ) ] = SULFATEUSE;
  26. m_crafts[ Craft( GUN, SHOTGUN ) ] = USIANE;
  27. m_crafts[ Craft( GUN, FUSIL ) ] = SCATTER;
  28. }
  29. Armes_Gest::~Armes_Gest()
  30. {
  31. for (m_itList = m_posees.begin(); m_itList != m_posees.end(); m_itList++){
  32. delete (*m_itList);
  33. }
  34. }
  35. SDL_Surface* Armes_Gest::getImg( WeaponType model ) const
  36. {
  37. return m_armeImg[ model ];
  38. }
  39. void Armes_Gest::allDisplay( const Vec &lookAt, SDL_Surface* screen )
  40. {
  41. for (m_itList = m_posees.begin(); m_itList != m_posees.end(); m_itList++){
  42. (*m_itList)->afficher( lookAt, screen );
  43. }
  44. }
  45. void Armes_Gest::drop( Vec pos, Arme* weapon )
  46. {
  47. m_posees.insert( m_posees.begin(), new CaisseArme( m_armeImg[ weapon->getModel() ], weapon, pos) );
  48. }
  49. Arme* Armes_Gest::saisir( Vec pos )
  50. {
  51. Arme* weapon( 0x0 );
  52. if (m_posees.empty()) std::cout << "Mais il n'y a pas d'arme sur le sol !" << std::endl;
  53. for (m_itList = m_posees.begin(); m_itList != m_posees.end() && weapon == 0x0; m_itList++){
  54. if ( (*m_itList)->proxi( pos ) ) {
  55. weapon = (*m_itList)->takeWeapon();
  56. m_posees.erase( m_itList );
  57. }
  58. }
  59. return weapon;
  60. }
  61. Arme* Armes_Gest::crafting( Arme* paire[2], Tirs_Gest* tirsGest )
  62. {
  63. std::cout << "Crafting : " << std::endl;
  64. Craft* prod(0x0);
  65. prod = new Craft( paire[0]->getModel(), paire[1]->getModel() );
  66. WeaponType resultat;
  67. Arme* renvoi(0x0);
  68. m_itMap = m_crafts.find( *prod );
  69. if ( m_itMap == m_crafts.end() ) std::cout << "Combinaison inexistante.";
  70. else {
  71. resultat = m_crafts[ *prod ];
  72. renvoi = takeWeapon( resultat, tirsGest );
  73. std::cout << "Arme obtenue : " << resultat;
  74. }
  75. std::cout << std::endl << std::endl << std::endl;
  76. delete prod;
  77. return renvoi;
  78. }
  79. Arme* Armes_Gest::takeWeapon( WeaponType model, Tirs_Gest* tirsGest ) const
  80. {
  81. switch ( model)
  82. {
  83. case GUN :
  84. return new Gun( tirsGest );
  85. break;
  86. case FUSIL :
  87. return new Fusil( tirsGest );
  88. break;
  89. case SHOTGUN :
  90. return new Shotgun( tirsGest );
  91. break;
  92. case USIANE :
  93. return new Usiane( tirsGest );
  94. break;
  95. case SCATTER :
  96. return new Scatter( tirsGest );
  97. break;
  98. case BAROUDEUR :
  99. return new Baroudeur( tirsGest );
  100. break;
  101. case SULFATEUSE :
  102. return new Sulfateuse( tirsGest );
  103. break;
  104. case TRIPHASEUR :
  105. return new Triphaseur( tirsGest );
  106. break;
  107. case BOMBER :
  108. return new Bomber( tirsGest );
  109. break;
  110. default:
  111. return 0x0;
  112. break;
  113. }
  114. }
  115. Arme* Armes_Gest::startWeapon( Tirs_Gest* tirsGest ) const
  116. {
  117. int choice( rand() % 3 );
  118. return takeWeapon( (WeaponType)choice, tirsGest );
  119. }
  120. /// ~~~ CRAFT IMPLEMENTATION ~~~ ----------------------------------------------------------------- VVVVV
  121. Craft::Craft()
  122. :m_a(GUN), m_b(SHOTGUN)
  123. {
  124. }
  125. Craft::Craft( WeaponType a, WeaponType b )
  126. {
  127. if ( a < b ) {
  128. m_a = a;
  129. m_b = b;
  130. }
  131. else {
  132. m_a = b;
  133. m_b = a;
  134. }
  135. }
  136. Craft::~Craft()
  137. {
  138. }
  139. void Craft::debugCout() const
  140. {
  141. std::cout <<"Arme A : "<< m_a << std::endl;
  142. std::cout <<"Arme B : "<< m_b << std::endl << std::endl;
  143. }
  144. bool Craft::operator<( const Craft& a ) const
  145. {
  146. if ( m_a < a.m_a )
  147. return true;
  148. else
  149. return m_b < a.m_b;
  150. }