Repository navigation
Expand file tree
/
Copy pathRectangle.cpp
More file actions
63 lines (48 loc) · 1.88 KB
/
Copy pathRectangle.cpp
File metadata and controls
63 lines (48 loc) · 1.88 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
#include "Rectangle.h"
#include "Game.h"
#include "Utility.h"
#include "OSHandler.h"
Rectangle::Rectangle(Game* game, b2Vec2* size_, b2Vec2* position,
bool dynamic, int id, float density, float friction, int groupIndex):
Shape(game, position, dynamic, id, density, friction)
{
size = size_;
// GROUP INDEX:
// 1: All randomly created falling boxes
// 2: All static platforms
// 3: Player and hook
// Define another box shape for our dynamic body.
b2PolygonShape boxShape; //dynamicBox;
boxShape.SetAsBox((size->x/2) * game->getUtility()->getPTM(), (size->y/2) * game->getUtility()->getPTM());
// Define the dynamic body fixture.
b2FixtureDef fixtureDef;
fixtureDef.shape = &boxShape;
// Set collision group. Will not collide with objects of same positive group
fixtureDef.filter.groupIndex = groupIndex;
// Set the box density to be non-zero, so it will be dynamic.
fixtureDef.density = density;
// Override the default friction.
fixtureDef.friction = friction;
// Add the shape to the body.
body->CreateFixture(&fixtureDef);
shape = new sf::RectangleShape(sf::Vector2f(size->x, size->y));
if (!rockTexture.loadFromFile(game->getOSHandler()->getResourcePath() + "placeholder_rock.png")) {
std::cout << "Could not load frog image" << std::endl;
}
float startX = rand() * 50;
float startY = rand() * 50;
shape->setTexture(&rockTexture);
shape->setTextureRect(sf::IntRect(startX, startY, startX + size->x, startY + size->y));
// This makes SFML use the same origin for shapes as Box2D(middle, middle)
shape->setOrigin(size->x/2, size->y/2);
shape->setPosition(position->x, position->y);
userData.isItem = false;
}
Rectangle::~Rectangle()
{
delete size;
delete Shape::shape;
}
b2Vec2* Rectangle::getSize() const {
return size;
}