15 Ramp::Ramp(b2World* world, sf::RenderWindow& window,
config::sTerrain terrainParam,
int WINDOW_X_PX,
double bodyLength)
16 :
Terrain(world, window, terrainParam, WINDOW_X_PX, bodyLength){
17 m_M_TO_PX = WINDOW_X_PX / (2*m_runaway);
26 m_M_TO_PX = WINDOW_X_PX / (2*m_runaway);
27 printf(
"m_M_TO_PX: %f, \n", m_M_TO_PX);
33 BodyDef.position = b2Vec2(0, 0);
34 BodyDef.type = b2_staticBody;
35 m_groundBody = world->CreateBody(&BodyDef);
37 b2EdgeShape edgeShape;
40 edgeShape.Set( b2Vec2(0,m_posY), b2Vec2(m_runaway,m_posY) );
41 firstR.shape = &edgeShape;
42 m_groundBody->CreateFixture(&firstR);
45 edgeShape.Set( b2Vec2(m_runaway,m_posY), b2Vec2(m_runaway,m_posY+m_height) );
46 slope.shape = &edgeShape;
47 m_groundBody->CreateFixture(&slope);
50 edgeShape.Set( b2Vec2(m_runaway,m_posY+m_height), b2Vec2(3*m_runaway,m_posY+m_height) );
51 endR.shape = &edgeShape;
52 m_groundBody->CreateFixture(&endR);
57 sf::VertexArray lines(sf::LinesStrip, 4);
58 lines[0].position = sf::Vector2f(0, m_posY*m_M_TO_PX);
59 lines[1].position = sf::Vector2f(m_runaway*m_M_TO_PX, m_posY*m_M_TO_PX);
60 lines[2].position = sf::Vector2f(m_runaway*m_M_TO_PX, (m_posY+m_height)*m_M_TO_PX);
61 lines[3].position = sf::Vector2f(2*m_runaway*m_M_TO_PX, (m_posY+m_height)*m_M_TO_PX);
64 lines[0].color = sf::Color::Black;
65 lines[1].color = sf::Color::Black;
66 lines[2].color = sf::Color::Black;
67 lines[3].color = sf::Color::Black;
74 return b2Vec2(m_runaway, m_posY);
78 return b2Vec2(m_runaway, m_posY);
82 return b2Vec2((m_runaway), (m_posY+m_height));
void createBody(b2World *world)
b2Vec2 getTopLeftCorner()
void create(b2World *world, sf::RenderWindow &window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength=1)
b2Vec2 getTopRightCorner()
Implementation of the Ramp class which inherit from the Terrain class.
void drawBody(sf::RenderWindow &window)
virtual void create(b2World *world, sf::RenderWindow &window, config::sTerrain terrainParam, int WINDOW_X_PX, double bodyLength)