-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreature.cpp
More file actions
109 lines (86 loc) · 2.41 KB
/
Copy pathCreature.cpp
File metadata and controls
109 lines (86 loc) · 2.41 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "headers.h"
#include "Creature.h"
//Initialize private functions
void Creature::initMovementComponent()
{
m_movementComponent = new MovementComponent{ m_direction, m_velocity, *m_sprite, 400.0f, m_isGrounded };
}
void Creature::initAnimationComponent()
{
m_animationComponent = new AnimationComponent{ *m_sprite, m_velocity };
}
void Creature::initPhysicsComponent()
{
m_physicsComponent = new PhysicsComponent{ 2500.0f, -950.0f, 4600.0f,
sf::Vector2f{900.0f, 900.0f} };
}
void Creature::initSprite(sf::Texture& texture)
{
m_sprite = new sf::Sprite{};
m_sprite->setTexture(texture);
m_sprite->setTextureRect(sf::IntRect{ 5,5,50,58 });
}
void Creature::initHitboxComponent()
{
m_hitboxComponent = new HitboxComponent{ *m_sprite, m_velocity, m_isGrounded};
}
//Constructors / Descructors
Creature::Creature(sf::Texture& texture)
{
this->initSprite(texture);
this->initMovementComponent();
this->initHitboxComponent();
this->initAnimationComponent();
this->initPhysicsComponent();
}
Creature::~Creature()
{
delete m_sprite;
delete m_hitboxComponent;
delete m_animationComponent;
delete m_movementComponent;
delete m_physicsComponent;
}
//Public functions
void Creature::setScale(sf::Vector2f scale)
{
m_sprite->setScale(scale);
m_hitboxComponent->scaleHitboxSize(scale);
m_animationComponent->setScale(scale);
}
void Creature::setBasicFrame(sf::IntRect basicFrame)
{
m_currentFrame = basicFrame;
m_sprite->setTextureRect(m_currentFrame);
m_animationComponent->setBacisFrame( basicFrame );
}
void Creature::setJumpingAndFallingFrame(sf::IntRect jumpingFrame, sf::IntRect fallingFrame)
{
m_animationComponent->setJumpingAndFallingFrame(jumpingFrame, fallingFrame);
}
void Creature::setAnimationStateBounds(float walkNextFrameDIstance, float walkMaxBound, float topWalkBound,
float idleNextFrameDistance, float idleMaxBound, float topidleBound)
{
m_animationComponent->setAnimationBounds(walkNextFrameDIstance, walkMaxBound, topWalkBound,
idleNextFrameDistance, idleMaxBound, topidleBound);
}
void Creature::setMaxHP(int maxHP)
{
m_maxHP = maxHP;
}
const int& Creature::getHP()
{
return m_currentHP;
}
const sf::Vector2f& Creature::getPosition() const
{
return m_sprite->getPosition();
}
const sf::Vector2f& Creature::getSize() const
{
return m_hitboxComponent->getHitbox().getSize();
}
const sf::FloatRect& Creature::getGlobalBounds() const
{
return m_hitboxComponent->getHitbox().getGlobalBounds();
}