-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnit.cpp
More file actions
82 lines (54 loc) · 1.28 KB
/
Copy pathUnit.cpp
File metadata and controls
82 lines (54 loc) · 1.28 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
#include "../include/Unit.hpp"
#include <iostream>
Unit::UnitStats::UnitStats(float _hp, float _strenght, float _speed)
: maxHp(_hp)
, hp(_hp)
, strenght(_strenght)
, speed(_speed)
{
}
Unit::Unit(const sf::Vector2f& initPos, const sf::Vector2f& size, EntityGroup group, b2World& world, const UnitStats& _stats)
: Entity(initPos, sf::Vector2f(size.x + 1.0f, size.y + 1.0f), group)
, movement(0.0f, 0.0f)
, animationManager()
, stats(_stats)
, actionTimer(0.0f)
, isControllable(true)
, isAlive(true)
, state(STATE_IDLE)
, currDir(DIR_DOWN)
{
b2BodyDef physicalBodyDef;
physicalBodyDef.type = b2_dynamicBody;
physicalBodyDef.position.Set(abstractBody.getPosition().x, abstractBody.getPosition().y);
physicalBody = world.CreateBody(&physicalBodyDef);
b2PolygonShape boxShape;
boxShape.SetAsBox(size.x, size.y);
b2FixtureDef boxFixtureDef;
boxFixtureDef.shape = &boxShape;
boxFixtureDef.density = 1.0f;
physicalBody->CreateFixture(&boxFixtureDef);
}
Unit::~Unit()
{
}
void Unit::collisionEvent(Entity*)
{
}
void Unit::hurt(float dmg)
{
stats.hp -= dmg;
if(stats.hp <= 0) {
live = false;
}
}
void Unit::stagger()
{
isControllable = false;
state = STATE_STAGGER;
animationManager.setAnimation(state);
}
Unit::UnitStats& Unit::getStats()
{
return stats;
}