-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mover.cpp
72 lines (55 loc) · 1.19 KB
/
Mover.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "Mover.h"
Mover::Mover()
{
srand(time(NULL));
position = sf::Vector2f(400, 300);
velocity = sf::Vector2f(0, 0);
accelerate = sf::Vector2f(0,0);
mass = 2;
entity.setPosition(position);
entity.setRadius(10.0f);
entity.setFillColor(sf::Color(41, 128, 185));
entity.setOutlineColor(sf::Color(236, 240, 241));
entity.setOutlineThickness(0.2);
}
void Mover::update(sf::RenderWindow *window)
{
velocity += accelerate;
position += velocity;
entity.setPosition(position);
entity.setScale(sf::Vector2f(mass, mass));
accelerate *= 0.0f;
}
void Mover::addForce(sf::Vector2f force)
{
force /= mass;
accelerate += force;
}
void Mover::checkColision()
{
size = sf::Vector2f(entity.getScale().x * 10.0f, entity.getScale().y * 10.0f) * 2.0f;
if (position.x > 720 ) {
position.x = 720;
velocity.x *= -1;
}
else if (position.x < 0) {
position.x = 0;
velocity.x *= -1;
}
if (position.y > 520) {
position.y = 520;
velocity.y *= -1;
}
else if (position.y < 0)
{
position.y = 0;
velocity.y *= -1;
}
}
void Mover::setPosition(sf::Vector2f location)
{
accelerate += location;
}
Mover::~Mover()
{
}