-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.cpp
More file actions
71 lines (54 loc) · 1.63 KB
/
Block.cpp
File metadata and controls
71 lines (54 loc) · 1.63 KB
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
70
71
/*
* Block.cpp
*
* Created on: 8 maj 2010
* Author: meros
*/
#include "Block.h"
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);
b2FixtureDef fixDef;
fixDef.shape = &dropboxShape;
fixDef.density = 0.05f;
fixDef.userData.pointer = reinterpret_cast<uintptr_t>(static_cast<UserData*>(this));
myCollisionBody->CreateFixture(&fixDef);
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();
auto* udA = reinterpret_cast<UserData*>(contact->GetFixtureA()->GetUserData().pointer);
if (udA == static_cast<UserData*>(this)) {
otherFix = contact->GetFixtureB();
}
if (myCollisionBody->GetPosition().y
< otherFix->GetAABB(0).upperBound.y)
contact->SetEnabled(false);
}
}