Hecto.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "Hecto.h"
  2. Hecto::Hecto()
  3. :Shot( HECTO_DEGAT ), m_velocity( -HECTO_SPEED ), m_life( HECTO_DURABILTY )
  4. {
  5. //ctor
  6. }
  7. Hecto::Hecto( Sint16 x, Sint16 y, bool ally )
  8. :Shot( HECTO_DEGAT, x, y, ally ), m_velocity( HECTO_SPEED ), m_life( HECTO_DURABILTY )
  9. {
  10. if ( ally )
  11. m_velocity = -m_velocity;
  12. }
  13. Hecto::~Hecto()
  14. {
  15. //dtor
  16. }
  17. void Hecto::update()
  18. {
  19. m_x += m_velocity;
  20. }
  21. void Hecto::draw( SDL_Surface* screen )
  22. {
  23. if ( m_exist )
  24. stringRGBA(screen, m_x - 4, m_y - 4, "H", 128, m_life * 255 / HECTO_DURABILTY, 0, 255);
  25. }
  26. bool Hecto::damageSolid( Uint8** solid, const Uint16 dimH, const Uint16 dimW, const SDL_Rect& hitbox )
  27. {
  28. // Déterminer les cordonnées de l'impact
  29. Uint16 yImpct( ( m_y - hitbox.y ) / 8 );
  30. Uint16 xImpct( ( m_x - hitbox.x ) / 8 );
  31. // Bloc présent ?
  32. if ( solid[yImpct][xImpct] == 0 )
  33. return false;
  34. // Déstruction du centre
  35. damageBloc( solid, dimH, dimW, yImpct, xImpct, 255 );
  36. // Forts dégats sur l'immédiat
  37. #define HECTO_NEAREST_BAM 200
  38. damageBloc( solid, dimH, dimW, yImpct - 1, xImpct, HECTO_NEAREST_BAM );
  39. damageBloc( solid, dimH, dimW, yImpct + 1, xImpct, HECTO_NEAREST_BAM );
  40. damageBloc( solid, dimH, dimW, yImpct, xImpct - 1, HECTO_NEAREST_BAM );
  41. damageBloc( solid, dimH, dimW, yImpct, xImpct + 1, HECTO_NEAREST_BAM );
  42. damageBloc( solid, dimH, dimW, yImpct - 1, xImpct - 1, HECTO_NEAREST_BAM );
  43. damageBloc( solid, dimH, dimW, yImpct + 1, xImpct - 1, HECTO_NEAREST_BAM );
  44. damageBloc( solid, dimH, dimW, yImpct - 1, xImpct + 1, HECTO_NEAREST_BAM );
  45. damageBloc( solid, dimH, dimW, yImpct + 1, xImpct + 1, HECTO_NEAREST_BAM );
  46. // Faibles dégats sur l'adjacent
  47. #define HECTO_FAR_BAM 60
  48. damageBloc( solid, dimH, dimW, yImpct - 2, xImpct, HECTO_FAR_BAM );
  49. damageBloc( solid, dimH, dimW, yImpct + 2, xImpct, HECTO_FAR_BAM );
  50. damageBloc( solid, dimH, dimW, yImpct, xImpct - 2, HECTO_FAR_BAM );
  51. damageBloc( solid, dimH, dimW, yImpct, xImpct + 2, HECTO_FAR_BAM );
  52. // Déstruction du projectile
  53. m_life-- ;
  54. if ( m_life == 0 )
  55. m_exist = false;
  56. return true;
  57. }