-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.cpp
More file actions
37 lines (31 loc) · 1018 Bytes
/
object.cpp
File metadata and controls
37 lines (31 loc) · 1018 Bytes
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
#include <iostream>
#include "object.h"
#include "collision.h"
#include "physics_world.h"
using namespace std;
Object::Object(float x, float y, float width, float height)
:width(width), height(height), physicsBody(b2_nullBodyId){
pos.x = x;
pos.y = y;
width2 = width/2;
height2 = height/2;
rect = computeRect();
}
void Object::destroyPhysics(PhysicsWorld& world) {
if (b2Body_IsValid(physicsBody)) {
world.destroyBody(physicsBody);
physicsBody = b2_nullBodyId;
}
}
Collision Object::collides(Object *obj){
Rect *objRect = &obj->rect;
Rect *thisRect = &this->rect;
bool left = thisRect->br.x >= objRect->tl.x;
bool right = thisRect->tl.x <= objRect->br.x;
bool bottom = thisRect->br.y >= objRect->tl.y;
bool top = thisRect->tl.y <= objRect->br.y;
Collision collision(left, right, top, bottom);
//cout << left << " " << right << " " << bottom << " " << top << endl;
//cout << collision.collides << endl;
return collision;
}