-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.cpp
53 lines (44 loc) · 1.16 KB
/
object.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
#include "object.h"
#include <list>
#include "wrapped_point.h"
#include <iostream>
using namespace std;
Object::Object() {
commonInit();
}
Object::Object(WrappedPoint position, Point velocity, float rotation_speed) :
position(position), velocity(velocity), rotation_speed(rotation_speed) {
//Annoyingly horrible workaround
commonInit();
}
//FIX: When compiler supports target/delegate constructos
// USE THEM
void Object::commonInit() {
radius = 1.0f;
rotation = 0.0f;
alive = true;
value = 0;
friction = 0.0f;
invincible = false;
}
bool Object::is_removable() const {
return !alive;
}
void Object::step(int delta) {
position += velocity * delta;
position.wrap();
rotation += rotation_speed * delta;
}
bool Object::collide(const Object &other, float proximity) const {
return collide(other, proximity, Point(0,0));
}
bool Object::collide(const Object &other, float proximity, const Point offset) const {
return ((other.position + offset) - position).magnitude_squared() < ((radius+other.radius+proximity)*(radius+other.radius+proximity));
}
bool Object::kill() {
if(!invincible && alive) {
alive = false;
return true;
}
return false;
}