-
Notifications
You must be signed in to change notification settings - Fork 0
/
movable.cpp
48 lines (39 loc) · 968 Bytes
/
movable.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
#include "movable.h"
#include "manager.h"
Movable::Movable(const Vector2D &left, const Vector2D &right,
const Vector2D &st_position, const Vector2D &st_speed)
:
speed(st_speed),
position_(st_position),
lb_edge_(left),
rt_edge_(right)
{
}
Vector2D Movable::get_pos(void) const
{
return position_;
}
bool Movable::move()
{
Vector2D old_pos = position_;
Vector2D offset = speed * Manager::getSingleton().getStep();
position_ += offset;
if (position_.x < lb_edge_.x)
position_.x = lb_edge_.x;
if (position_.y < lb_edge_.y)
position_.y = lb_edge_.y;
if (position_.x > rt_edge_.x)
position_.x = rt_edge_.x;
if (position_.y > rt_edge_.y)
position_.y = rt_edge_.y;
return position_ == old_pos;
}
void Movable::initMovable(const Vector2D & left, const Vector2D & right,
const Vector2D & position, const Vector2D & st_speed)
{
lb_edge_ = left;
rt_edge_ = right;
position_ = position;
speed = st_speed;
}
Movable::~Movable() {}