-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacter.h
78 lines (63 loc) · 2.07 KB
/
Character.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
74
75
76
77
78
#pragma once
#include <SFML/Graphics.hpp>
#include <vector>
#include <memory>
#include "AnimationHandler.h"
#include "ITile.h"
enum class MapDirection
{
LEFT,
UP,
RIGHT,
DOWN
};
class Character : public ITile
{
public:
void SetPosition(const sf::Vector2f &pos);
void AddAnim(Animation &anim) override;
sf::RectangleShape *Get(float dt) override;
Character(const sf::Vector2f &size,
sf::Texture *stand_left,
sf::Texture *stand_top,
sf::Texture *stand_right,
sf::Texture *stand_bottom,
sf::Texture *move_left01,
sf::Texture *move_left02,
sf::Texture *move_up01,
sf::Texture *move_up02,
sf::Texture *move_right01,
sf::Texture *move_right02,
sf::Texture *move_down01,
sf::Texture *move_down02,
int zLevel) : m_CurrentDirection(MapDirection::LEFT), m_IsMoving(false)
{
m_Shape.setSize(size);
m_StandSprites.reserve(4);
m_StandSprites.emplace_back(stand_left);
m_StandSprites.emplace_back(stand_top);
m_StandSprites.emplace_back(stand_right);
m_StandSprites.emplace_back(stand_bottom);
m_MoveSprites.reserve(8);
m_MoveSprites.emplace_back(move_left01);
m_MoveSprites.emplace_back(move_left02);
m_MoveSprites.emplace_back(move_up01);
m_MoveSprites.emplace_back(move_up02);
m_MoveSprites.emplace_back(move_right01);
m_MoveSprites.emplace_back(move_right02);
m_MoveSprites.emplace_back(move_down01);
m_MoveSprites.emplace_back(move_down02);
ZLevel = zLevel;
// Set the initial sprite
Turn(MapDirection::DOWN);
}
void Turn(MapDirection dir);
void Move(MapDirection dir); //(const sf::Vector2f& relativeDist)
private:
MapDirection m_CurrentDirection;
// Left, up, right, bottom
std::vector<sf::Texture *> m_StandSprites;
// L1, L2, U1, U2, R1, R2, B1, B2
std::vector<sf::Texture *> m_MoveSprites;
bool m_IsMoving;
};