-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.h
62 lines (45 loc) · 1001 Bytes
/
Player.h
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
#pragma once
#include "Entity.h"
#include "BaseComponent.h"
class Player : public Entity
{
protected:
void UpdateComponents()
{
for (auto i : this->components)
{
i.second->Update();
}
}
void RenderComponents() { for (auto i : this->components) i.second->Render(); }
public:
Player()
{
this->pos = sf::Vector2f(0, 0);
this->vel = sf::Vector2f(0, 0);
this->accel = sf::Vector2f(0, 0);
}
~Player()
{
}
virtual void Update()
{
this->setTarget((sf::Vector2f)sf::Mouse::getPosition());
setVel(getVel() + getAccel());
setPos(getPos() + getVel());
UpdateComponents();
this->shape.setPosition(this->getPos());
}
virtual void Render()
{
this->Window->draw(this->shape);
RenderComponents();
}
void ConfigurePlayer(sf::RenderWindow* w, sf::Texture* t, sf::RectangleShape s)
{
this->Window = w;
this->tex = t;
this->shape = s;
this->shape.setTexture(this->tex);
}
};