-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActor.cpp
More file actions
88 lines (71 loc) · 1.63 KB
/
Actor.cpp
File metadata and controls
88 lines (71 loc) · 1.63 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "Actor.h"
#include "Game.h"
#include <vector>
#include <SFML/Graphics.hpp>
using namespace std;
Actor::Actor()
{
m_location = sf::Vector2f(0.0f, 0.0f);
m_totalExtForces.push_back(sf::Vector2f {0.f, (9.81f*m_mass)});
m_totalExtForces.push_back(sf::Vector2f {0.f, 0.f});
m_totalExtForces.push_back(sf::Vector2f {0.f, 0.f});
}
Actor::~Actor()
{
}
Actor::Actor(sf::Vector2f initialLocation)
{
m_location = initialLocation;
}
void Actor::setLocation(sf::Vector2f location){
m_location=location;
}
void Actor::move(sf::Vector2f offset)
{
m_location+=offset;
}
sf::Vector2f Actor::getLocation(){
return m_location;
}
std::vector<sf::Sprite*> Actor::getDraw()
{
std::vector<sf::Sprite*> toReturn;
std::vector<sf::Sprite*> tmp;
for(int i(0); i<(m_childs.size()); ++i) {
tmp=m_childs[i].getDraw();
for (int j = 0; j < tmp.size(); j++) {
toReturn.push_back(tmp[j]);
}
}
return toReturn;
}
void Actor::setSimulatePhysics(bool simulatePhysics)
{
m_simulatePhysics=simulatePhysics;
}
void Actor::updateComponent()
{
//cout << "Parent overriden" << endl;
}
void Actor::updatePhysicsTick(float dTime)
{
if(m_simulatePhysics)
{
float delta;
delta = (m_clock.getElapsedTime().asMilliseconds())/1000.f;
//m_velocity = m_velocity;
sf::Vector2f sum = {0.f, 0.f};
for(int i(0); i<(m_totalExtForces.size()); ++i) {
sum += m_totalExtForces[i];
}
m_velocity = (sum*delta)/m_mass+m_velocity;
m_location+=m_velocity;
//m_sprite.setPosition(m_location);
m_clock.restart();
}
}
bool Actor::addChild(SceneComponent* newChild)
{
m_childs.push_back(*newChild);
return true;
}