Disper.cpp 2.2 KB

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