-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBounceOnBorderPC.cpp
More file actions
53 lines (39 loc) · 991 Bytes
/
BounceOnBorderPC.cpp
File metadata and controls
53 lines (39 loc) · 991 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "BounceOnBorderPC.h"
BounceOnBorderPC::BounceOnBorderPC() :
BounceOnBorderPC(true, true, true, true) {
}
BounceOnBorderPC::BounceOnBorderPC(bool left, bool right, bool top, bool bot) :
left_(left), right_(right), top_(top), bot_(bot) {
}
BounceOnBorderPC::~BounceOnBorderPC() {
}
void BounceOnBorderPC::update(Container* c, Uint32 time) {
Vector2D p = c->getPosition();
Vector2D v = c->getVelocity();
if ( top_ ) {
if (p.getY() <= 0) {
p.setY(0);
v.setY( -v.getY() );
}
}
if ( bot_ ) {
if (p.getY() + c->getHeight() >= c->getGame()->getWindowHeight()) {
p.setY(c->getGame()->getWindowHeight() - c->getHeight());
v.setY( -v.getY() );
}
}
if ( left_ ) {
if (p.getX() <= 0) {
p.setX(0);
v.setX( -v.getX() );
}
}
if ( right_ ) {
if (p.getX() + c->getWidth() >= c->getGame()->getWindowWidth()) {
p.setX(c->getGame()->getWindowWidth() - c->getWidth());
v.setX( -v.getX() );
}
}
c->setPosition(p);
c->setVelocity(v);
}