-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.cpp
69 lines (52 loc) · 1.49 KB
/
Block.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Block.cpp
*
* Created on: 8 maj 2010
* Author: meros
*/
#include "Block.h"
#include <iostream>
using namespace std;
Block::Block(b2World& aWorld, float aX, float aY, float aW, float aH,
bool aDynamic) {
myX = aX;
myY = aY;
myW = aW;
myH = aH;
myIsCloud = false;
// Set up collision box
b2BodyDef dropboxDef;
dropboxDef.position = b2Vec2(aX + aW / 2, aY + aH / 2);
//dropboxDef.angle = 0.2;
if (aDynamic)
dropboxDef.type = b2_dynamicBody;
b2PolygonShape dropboxShape;
dropboxShape.SetAsBox(aW / 2, aH / 2);
myCollisionBody = aWorld.CreateBody(&dropboxDef);
myCollisionBody->CreateFixture(&dropboxShape, 0.05f)->SetUserData(
(UserData*) this);
mySprite.LoadTGA("data/groundtile.tga");
}
Block::~Block() {
// TODO Auto-generated destructor stub
}
void Block::Draw(sf::RenderTarget& aTarget, float aXScale, float aYScale,
float aXTranslate, float aYTranslate) {
mySprite.DrawTiling(aTarget, (myX - aXTranslate) * aXScale,
(myY - aYTranslate) * aYScale, (myX + myW - aXTranslate) * aXScale,
(myY + myH - aYTranslate) * aYScale);
}
void Block::SetCloud(bool aCloudFlag) {
myIsCloud = aCloudFlag;
}
void Block::PreSolve(b2Contact* contact, const b2Manifold* oldManifold) {
if (myIsCloud) {
b2Fixture* otherFix = contact->GetFixtureA();
if (contact->GetFixtureA()->GetUserData() == (UserData*) this) {
otherFix = contact->GetFixtureB();
}
if (myCollisionBody->GetPosition().y
< otherFix->GetAABB(0).upperBound.y)
contact->SetEnabled(false);
}
}