Wall.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // Created by jovian on 18/07/17.
  3. //
  4. #include "Wall.h"
  5. #include <cstdlib>
  6. Wall::Wall(b2Vec2 pos, b2World* physics, WallShape shape)
  7. : Entity(WALL, 0, physics){
  8. // Creation of physical body
  9. b2BodyDef bodyDef;
  10. bodyDef.type = b2_staticBody;
  11. bodyDef.position = pos;
  12. m_body = physics->CreateBody(&bodyDef);
  13. // Creation of shape
  14. b2PolygonShape boxShape;
  15. switch (shape)
  16. {
  17. case TINY :
  18. boxShape.SetAsBox(80.0f / DEFAULT_ZOOM, 80.0f / DEFAULT_ZOOM);
  19. m_imgId = (unsigned int) (2 + rand() % 4);
  20. break;
  21. case HIGH :
  22. boxShape.SetAsBox(80.0f / DEFAULT_ZOOM, 160.0f / DEFAULT_ZOOM);
  23. m_imgId = (unsigned int) (6 + rand() % 4);
  24. break;
  25. case WIDE :
  26. boxShape.SetAsBox(160.0f / DEFAULT_ZOOM, 80.0f / DEFAULT_ZOOM);
  27. m_imgId = (unsigned int) (21 + rand() % 4);
  28. break;
  29. case BIG :
  30. boxShape.SetAsBox(160.0f / DEFAULT_ZOOM, 160.0f / DEFAULT_ZOOM);
  31. m_imgId = (unsigned int) (25 + rand() % 4);
  32. break;
  33. }
  34. // Definition of fixture
  35. b2FixtureDef fixtureDef;
  36. fixtureDef.shape = &boxShape;
  37. fixtureDef.friction = 1.0f;
  38. // Creation of fixture
  39. m_body->CreateFixture(&fixtureDef);
  40. // Link this wall
  41. establishPhysicalLink();
  42. }
  43. void Wall::update() {
  44. // Nothing happens ... the wall can't move !
  45. }