Foe.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "Foe.h"
  2. Foe::Foe()
  3. :SpaceShip( false ), m_speed( 1 )
  4. {
  5. Uint32 tabMins[SHOT_NB] = FOE_MIN;
  6. Uint32 tabAdds[SHOT_NB] = FOE_ADD;
  7. for ( unsigned int i(1); i < SHOT_NB; i++ )
  8. {
  9. m_loading[i] = SDL_GetTicks();
  10. m_delay[i] = tabMins[i] + ( rand() % tabAdds[i] );
  11. }
  12. }
  13. Foe::Foe( Uint16 speed )
  14. :SpaceShip( false ), m_speed( speed )
  15. {
  16. Uint32 tabMins[SHOT_NB] = FOE_MIN;
  17. Uint32 tabAdds[SHOT_NB] = FOE_ADD;
  18. for ( unsigned int i(1); i < SHOT_NB; i++ )
  19. {
  20. m_loading[i] = SDL_GetTicks();
  21. m_delay[i] = tabMins[i] + ( rand() % tabAdds[i] );
  22. }
  23. }
  24. Foe::~Foe()
  25. {
  26. //dtor
  27. }
  28. void Foe::update()
  29. {
  30. // Collision
  31. SpaceShip::update();
  32. // Teste l'existence
  33. if ( !getIsAlive() )
  34. return ;
  35. // Déplacement
  36. m_pos.x += m_speed;
  37. // Feu
  38. Uint32 last( SDL_GetTicks() );
  39. Uint32 tabMins[SHOT_NB] = FOE_MIN;
  40. Uint32 tabAdds[SHOT_NB] = FOE_ADD;
  41. for ( unsigned int i(1); i < SHOT_NB; i++ )
  42. {
  43. if ( last - m_loading[i] > m_delay[i] ){
  44. fire( i );
  45. m_loading[i] = SDL_GetTicks();
  46. m_delay[i] = tabMins[i] + ( rand() % tabAdds[i] );
  47. }
  48. }
  49. }