Gun.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "Gun.h"
  2. Gun::Gun()
  3. :Shot( GUN_DEGAT ), m_velocity( -GUN_SPEED )
  4. {
  5. //ctor
  6. }
  7. Gun::Gun( Sint16 x, Sint16 y, bool ally )
  8. :Shot( GUN_DEGAT, x, y, ally ), m_velocity( GUN_SPEED )
  9. {
  10. if ( ally )
  11. m_velocity = -m_velocity;
  12. }
  13. Gun::~Gun()
  14. {
  15. //dtor
  16. }
  17. void Gun::update()
  18. {
  19. m_x += m_velocity;
  20. }
  21. void Gun::draw( SDL_Surface* screen )
  22. {
  23. if ( m_exist )
  24. stringRGBA(screen, m_x - 4, m_y - 4, "+", 255, 255, 255, 255);
  25. }
  26. bool Gun::damageSolid( Uint8** solid, const Uint16 dimH, const Uint16 dimW, const SDL_Rect& hitbox )
  27. {
  28. // Déterminer l'ordonnée d'impact
  29. Uint16 yImpct( ( m_y - hitbox.y ) / 8 );
  30. // Détermination de l'abscisse d'impact
  31. Sint16 xImpct(0);
  32. if ( m_ally )
  33. xImpct = dimW - 1;
  34. while ( solid[yImpct][xImpct] == 0 )
  35. {
  36. if ( m_ally )
  37. xImpct --;
  38. else
  39. xImpct ++;
  40. if ( xImpct == -1 || xImpct == dimW )
  41. return false;
  42. }
  43. // Déstruction du centre
  44. #define GUN_CENTER_BAM 200
  45. damageBloc( solid, dimH, dimW, yImpct, xImpct, GUN_CENTER_BAM );
  46. // Forts dégats sur l'immédiat
  47. #define GUN_NEAREST_BAM 130
  48. damageBloc( solid, dimH, dimW, yImpct - 1, xImpct, GUN_NEAREST_BAM );
  49. damageBloc( solid, dimH, dimW, yImpct + 1, xImpct, GUN_NEAREST_BAM );
  50. damageBloc( solid, dimH, dimW, yImpct, xImpct - 1, GUN_NEAREST_BAM );
  51. damageBloc( solid, dimH, dimW, yImpct, xImpct + 1, GUN_NEAREST_BAM );
  52. // Faibles dégats sur l'adjacent
  53. #define GUN_FAR_BAM 60
  54. damageBloc( solid, dimH, dimW, yImpct - 1, xImpct - 1, GUN_FAR_BAM );
  55. damageBloc( solid, dimH, dimW, yImpct + 1, xImpct - 1, GUN_FAR_BAM );
  56. damageBloc( solid, dimH, dimW, yImpct - 1, xImpct + 1, GUN_FAR_BAM );
  57. damageBloc( solid, dimH, dimW, yImpct + 1, xImpct + 1, GUN_FAR_BAM );
  58. damageBloc( solid, dimH, dimW, yImpct - 2, xImpct, GUN_FAR_BAM );
  59. damageBloc( solid, dimH, dimW, yImpct + 2, xImpct, GUN_FAR_BAM );
  60. damageBloc( solid, dimH, dimW, yImpct, xImpct - 2, GUN_FAR_BAM );
  61. damageBloc( solid, dimH, dimW, yImpct, xImpct + 2, GUN_FAR_BAM );
  62. // Déstruction du projectile
  63. m_exist = false;
  64. return true;
  65. }