-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_object.cpp
57 lines (42 loc) · 1.35 KB
/
game_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
54
55
56
57
#include "game_object.h"
/** Game object implementation part **/
GameObject::GameObject(sf::Vector2f coords, sf::Shape *form,
const sf::Color &color) {
shape = form;
shape->setPosition(coords);
shape->setFillColor(color);
}
sf::Vector2f GameObject::getPosition() const {
return shape->getPosition();
}
void GameObject::setPosition(const sf::Vector2f &pos) {
shape->setPosition(pos);
}
bool GameObject::isIntersects(const GameObject& another) const {
return this->getRight() >= another.getLeft() && this->getLeft() <= another.getRight() &&
this->getBottom() >= another.getTop() && this->getTop() <= another.getBottom();
}
/** Movable object implementation part **/
MovableObject::MovableObject(sf::Vector2f coords, sf::Shape *form, float speed_rate,
sf::Vector2f vel, const sf::Color &color) :
GameObject(coords, form, color),
velocity(vel),
move_rate(speed_rate) { }
void MovableObject::update() {
shape->move(velocity);
}
sf::Vector2f MovableObject::getVelocity() const {
return velocity;
}
void MovableObject::setVelocity(const sf::Vector2f &v) {
velocity = v;
}
void MovableObject::setVelocityX(float vx) {
velocity.x = vx;
}
void MovableObject::setVelocityY(float vy) {
velocity.y = vy;
}
float MovableObject::getMoveRate() const {
return move_rate;
}