Brexit.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "Brexit.h"
  2. Brexit::Brexit()
  3. :Shot( BREXIT_DEGAT ), m_vx( -BREXIT_SPEED_X), m_vy( BREXIT_SPEED_Y )
  4. {
  5. //ctor
  6. }
  7. Brexit::Brexit( Sint16 x, Sint16 y, bool up, bool ally )
  8. :Shot( BREXIT_DEGAT, x, y, ally ), m_vx( BREXIT_SPEED_X ), m_vy( BREXIT_SPEED_Y )
  9. {
  10. if ( ally )
  11. m_vx = -m_vx;
  12. if ( up )
  13. m_vy = -m_vy;
  14. }
  15. Brexit::~Brexit()
  16. {
  17. //dtor
  18. }
  19. void Brexit::update()
  20. {
  21. m_x += m_vx;
  22. m_y += m_vy;
  23. }
  24. void Brexit::draw( SDL_Surface* screen )
  25. {
  26. if ( !m_exist )
  27. return;
  28. stringRGBA(screen, m_x - 4, m_y - 4, "X", 0, 255, 0, 255);
  29. }
  30. bool Brexit::damageSolid( Uint8** solid, const Uint16 dimH, const Uint16 dimW, const SDL_Rect& hitbox )
  31. {
  32. // Déterminer l'ordonnée d'impact discret
  33. Uint16 yImpct( ( m_y - hitbox.y ) / 8 );
  34. Uint16 xImpct( ( m_x - hitbox.x ) / 8 );
  35. Sint16 yAdd(1);
  36. if ( m_vy < 0 ) yAdd = -1;
  37. Sint16 xAdd(1);
  38. if ( m_ally ) xAdd = -1;
  39. // Détermination du bord de pénétration
  40. while ( yImpct != 0 && xImpct != 0 && yImpct != dimH - 1 && xImpct != dimW - 1 )
  41. {
  42. xImpct -= xAdd;
  43. yImpct -= yAdd;
  44. }
  45. // Détermination de l'abscisse d'impact
  46. while ( solid[yImpct][xImpct] == 0 )
  47. {
  48. xImpct += xAdd;
  49. yImpct += yAdd;
  50. if ( xImpct >= dimW || yImpct >= dimH )
  51. return false;
  52. }
  53. // Déstruction du centre
  54. damageBloc( solid, dimH, dimW, yImpct, xImpct, 150 );
  55. damageBloc( solid, dimH, dimW, yImpct, xImpct + xAdd, 150 );
  56. damageBloc( solid, dimH, dimW, yImpct + yAdd, xImpct, 150 );
  57. // Déstruction du projectile
  58. m_exist = false;
  59. return true;
  60. }