Part.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "Part.h"
  2. Part::Part()
  3. :Shot( PART_DEGAT ), m_speedX( 5 ), m_speedY( 1 ), m_lvl( 255 )
  4. {
  5. m_part[0] = '#';
  6. m_part[1] = 0;
  7. }
  8. Part::Part( Sint16 x, Sint16 y, Sint16 speedX, Sint16 speedY, Uint8 lvl, char part, bool ally )
  9. :Shot( PART_DEGAT, x, y, ally ), m_speedX( speedX ), m_speedY( speedY ), m_lvl( lvl )
  10. {
  11. m_part[0] = part;
  12. m_part[1] = 0;
  13. }
  14. Part::~Part()
  15. {
  16. //dtor
  17. }
  18. void Part::update()
  19. {
  20. if ( !m_exist )
  21. return;
  22. m_x += m_speedX;
  23. m_y += m_speedY;
  24. Uint8 deg( 1 + ( rand() % 20 ) );
  25. if ( m_lvl < deg)
  26. m_exist = false;
  27. m_lvl -= deg;
  28. }
  29. void Part::draw( SDL_Surface* screen )
  30. {
  31. if ( m_exist )
  32. stringRGBA(screen, m_x - 4, m_y - 4, m_part, 255, m_lvl, m_lvl, 255);
  33. }
  34. bool Part::damageSolid( Uint8** solid, const Uint16 dimH, const Uint16 dimW, const SDL_Rect& hitbox )
  35. {
  36. // Déterminer les coordonnées d'impact
  37. Uint16 yImpct( ( m_y - hitbox.y ) / 8 );
  38. Uint16 xImpct( ( m_x - hitbox.x ) / 8 );
  39. // Débris détruit si contact
  40. m_exist = !damageBloc( solid, dimH, dimW, yImpct, xImpct, 42 );
  41. return !m_exist;
  42. }