-
Notifications
You must be signed in to change notification settings - Fork 0
/
CharacterTopDown.cpp
71 lines (60 loc) · 1.55 KB
/
CharacterTopDown.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
#include "CharacterTopDown.h"
void CharacterTopDown::SetPosition(const sf::Vector2f &pos)
{
m_Shape.setPosition(pos);
}
void CharacterTopDown::AddAnim(Animation &anim)
{
m_AnimHandler.AddAnim(anim);
}
// Sets the correct sprite from the animation result and returns the shape to be rendered
sf::RectangleShape *CharacterTopDown::Get(float dt)
{
int frame = m_AnimHandler.Update(dt);
// int spriteIndex = ((int)m_CurrentDirection * 2) + frame;
m_Shape.setTexture(m_StandSprites[0]);
return &m_Shape;
}
sf::Vector2f CharacterTopDown::GetPosition()
{
return m_Shape.getPosition();
}
void CharacterTopDown::SetRotation(float deg)
{
m_Shape.setRotation(deg);
}
void CharacterTopDown::Turn(float deg)
{
// sf::Texture* pTex = m_StandSprites[0];
// m_Shape.setTexture(pTex);
m_Shape.rotate(deg);
// m_CurrentDirection = dir;
// m_AnimHandler.ChangeAnim((unsigned int)dir);
// m_Shape.setTexture(m_StandSprites[(int)m_CurrentDirection]);
}
void CharacterTopDown::Move(MapDirection dir)
{
sf::Vector2f dist;
// Every direction has 2 sprites, use
// int sprIndex = ((int)dir) * 2;
if (dir == MapDirection::LEFT)
{
dist.x = -32.0f;
}
else if (dir == MapDirection::UP)
{
dist.y = -32.0f;
}
else if (dir == MapDirection::RIGHT)
{
dist.x = 32.0f;
}
else if (dir == MapDirection::DOWN)
{
dist.y = 32.0f;
}
// Update moving sprite
// m_Shape.setTexture(m_MoveSprites[sprIndex]);
// Actually move the object
m_Shape.move(dist);
}