Car.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # ifndef CAR_HEADER_FILE
  2. # define CAR_HEADER_FILE
  3. // Basiques
  4. # include <iostream>
  5. # include <cmath>
  6. # include <vector>
  7. // Random
  8. # include <ctime>
  9. # include <cstdlib>
  10. // SDL
  11. # include <SDL/SDL.h>
  12. # undef main
  13. # include <SDL/SDL_rotozoom.h>
  14. # include <SDL/SDL_gfxPrimitives.h>
  15. // bBox2D
  16. # include <box2d/box2d.h>
  17. # define MULTI 100.0f
  18. enum command { FREE, BREAK, GO, REVERSE };
  19. class Car
  20. {
  21. /// Méthodes
  22. public:
  23. Car();
  24. virtual ~Car();
  25. void destroy( b2World &world );
  26. virtual void init( b2World &world, float x, float y, float angle = 0.0f ) = 0;
  27. void drive( command cmd );
  28. void jump( float correction = 0.0f );
  29. void spin( float tq );
  30. virtual void update();
  31. b2Vec2 GetPosition();
  32. b2Vec2 GetVelocity();
  33. float GetTorque();
  34. float GetSpeed();
  35. bool GetIsOnGround();
  36. protected:
  37. void createMotorWheel( b2World &world, b2Vec2 rel, float friction = 10.0f, float density = 0.25f );
  38. void createFreeWheel( b2World &world, b2Vec2 rel, float friction = 10.0f, float density = 0.25f );
  39. void createCarenage( b2World &world, float x, float y, float friction = 1.0f, float density = 1.0f );
  40. /// Attributs
  41. protected:
  42. SDL_Surface* m_imgCar ;
  43. SDL_Surface* m_imgWheel ;
  44. private:
  45. b2Body* m_bodyCar ;
  46. std::vector< b2Body* > m_bodyWheel ;
  47. std::vector< b2RevoluteJoint* > m_motorAxe ;
  48. std::vector< b2RevoluteJoint* > m_fwdAxe ;
  49. command m_cmd ;
  50. float m_currentTorque ;
  51. float m_currentSpeed ;
  52. float m_sense ;
  53. float m_latence ;
  54. float m_goTorque ;
  55. float m_minTorque ;
  56. float m_maxSpeed ;
  57. };
  58. # endif // CAR_HEADER_FILE