Cutter.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "Cutter.h"
  2. Cutter::Cutter()
  3. :Shot( CUTTER_DEGAT ), m_velocity( -CUTTER_SPEED )
  4. {
  5. //ctor
  6. }
  7. Cutter::Cutter( Sint16 x, Sint16 y, bool ally )
  8. :Shot( CUTTER_DEGAT, x, y, ally ), m_velocity( CUTTER_SPEED )
  9. {
  10. if ( ally )
  11. m_velocity = -m_velocity;
  12. }
  13. Cutter::~Cutter()
  14. {
  15. //dtor
  16. }
  17. void Cutter::update()
  18. {
  19. m_x += m_velocity;
  20. }
  21. void Cutter::draw( SDL_Surface* screen )
  22. {
  23. if ( m_exist )
  24. stringRGBA(screen, m_x - 4, m_y - 4, "|", 255, 255, 0, 255);
  25. }
  26. bool Cutter::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 de la ligne
  44. for ( int i(0); i < dimH; i++ ) {
  45. damageBloc( solid, dimH, dimW, i, xImpct, 128 );
  46. }
  47. // Le projectile a atteint sa cible
  48. m_exist = false;
  49. return true;
  50. }