1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- //
- // Created by jovian on 18/07/17.
- //
- #include "Wall.h"
- #include <cstdlib>
- Wall::Wall(b2Vec2 pos, b2World* physics, WallShape shape)
- : Entity(WALL, 0, physics){
-
- // Creation of physical body
- b2BodyDef bodyDef;
- bodyDef.type = b2_staticBody;
- bodyDef.position = pos;
- m_body = physics->CreateBody(&bodyDef);
- // Creation of shape
- b2PolygonShape boxShape;
- switch (shape)
- {
- case TINY :
- boxShape.SetAsBox(80.0f / DEFAULT_ZOOM, 80.0f / DEFAULT_ZOOM);
- m_imgId = (unsigned int) (2 + rand() % 4);
- break;
- case HIGH :
- boxShape.SetAsBox(80.0f / DEFAULT_ZOOM, 160.0f / DEFAULT_ZOOM);
- m_imgId = (unsigned int) (6 + rand() % 4);
- break;
- case WIDE :
- boxShape.SetAsBox(160.0f / DEFAULT_ZOOM, 80.0f / DEFAULT_ZOOM);
- m_imgId = (unsigned int) (21 + rand() % 4);
- break;
- case BIG :
- boxShape.SetAsBox(160.0f / DEFAULT_ZOOM, 160.0f / DEFAULT_ZOOM);
- m_imgId = (unsigned int) (25 + rand() % 4);
- break;
- }
- // Definition of fixture
- b2FixtureDef fixtureDef;
- fixtureDef.shape = &boxShape;
- fixtureDef.friction = 1.0f;
- // Creation of fixture
- m_body->CreateFixture(&fixtureDef);
- // Link this wall
- establishPhysicalLink();
- }
- void Wall::update() {
- // Nothing happens ... the wall can't move !
- }
|