-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.h
executable file
·73 lines (49 loc) · 1.56 KB
/
entity.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
63
64
65
66
67
68
69
70
71
72
73
#ifndef ENTITY_H
#define ENTITY_H
#include <functional>
#include <vector>
#include <unordered_map>
#include <memory>
#include <QGraphicsPixmapItem>
#include "sound.h"
#include "sprite.h"
class Entity : public QGraphicsPixmapItem
{
public:
Entity(Sprite::Set& sprites);
void playSound(const char path[]);
unsigned int id() const;
unsigned int alive() const;
float speedX() const;
float speedY() const;
void speed(const float x, const float y);
float accelerationX() const;
float accelerationY() const;
void acceleration(const float x, const float y);
float maxSpeedX() const;
float maxSpeedY() const;
void maxSpeed(const float x, const float y);
float maxAccelerationX() const;
float maxAccelerationY() const;
void maxAcceleration(const float x, const float y);
void animation(std::string animation, const unsigned int index=0, std::function<void()> callback=NULL);
void animate(const float elapsed_time);
void move(const float elapsed_time);
void die();
protected:
void updateSprite(std::shared_ptr<Sprite> sprite);
protected:
unsigned int id_;
bool alive_ = true;
float acceleration_[2] {0,0}; // x, y
float speed_[2] {0,0}; // x, y
float max_speed_[2] {999, 999}; // x, y
float max_acceleration_[2] {999, 999}; // x, y
Sprite::Set& sprites_;
std::vector<std::shared_ptr<Sprite>> current_animation_;
unsigned int current_sprite_index_;
std::function<void()> callback_ = NULL;
private:
static unsigned int current_id_;
};
#endif // ENTITY_H