-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
101 lines (86 loc) · 2.51 KB
/
Player.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
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
#include "Player.hpp"
#include "Logic.hpp"
#include "TextureHandler.hpp"
#include "SoundHandler.hpp"
Player::Player(Entity &e, bool canMove)
: _cooldownDash(0), entity(e), canMove(canMove)
{
entity.renderable.texture = TextureHandler::getInstance().getTexture(TextureHandler::PLAYER);
entity.renderable.destSize = {0.1, 0.1};
entity.renderable.sourceSize = {0.5, 1};
_animation = 0;
_maxAnimationFrame = 10;
}
void Player::animate()
{
if (!entity.isOnPlanet) {
entity.renderable.sourcePos = {0.5, 0};
}
if (entity.fixture.speed[0] <= 0.0035 && entity.fixture.speed[0] >= -0.0035 &&
entity.fixture.speed[1] <= 0.0035 && entity.fixture.speed[1] >= -0.0035)
{
entity.renderable.sourcePos = {0.0, 0};
return;
}
if (entity.isOnPlanet && ++_animation >= _maxAnimationFrame)
{
if (entity.renderable.sourcePos[0] == 0)
entity.renderable.sourcePos = {0.5, 0};
else
entity.renderable.sourcePos = {0.0, 0};
_animation = 0;
}
}
void Player::update(void)
{
animate();
_cooldownDash -= (_cooldownDash > 0);
if (entity.isOnPlanet)
Logic::getInstance().resetCombo();
}
void Player::acceleration(int dir)
{
Vect<2, double> vec(-this->entity.fixture.pos[1], this->entity.fixture.pos[0]);
this->entity.fixture.speed = (this->entity.fixture.speed * 0.99 + vec.normalized() * (0.0005 * (1.0 + entity.isOnPlanet)) * dir);
}
void Player::dash(int dir)
{
Vect<2, double> vec(-this->entity.fixture.pos[1], this->entity.fixture.pos[0]);
if (entity.isOnPlanet && !_cooldownDash)
{
this->entity.fixture.speed += vec.normalized() * (0.01 * (1.0 + entity.isOnPlanet)) * dir;
_cooldownDash = 15;
SoundHandler::getInstance().playSound(SoundHandler::DASH);
}
}
void Player::jump()
{
if (this->entity.isOnPlanet)
{
this->entity.fixture.speed = this->entity.fixture.speed + this->entity.fixture.pos.normalized() * 0.03;
playRandomPlayerActionSound();
}
}
void Player::fastFall()
{
if (!this->entity.isOnPlanet)
{
this->entity.fixture.speed += -(this->entity.fixture.pos.normalized() * 0.04);
// playRandomPlayerActionSound();
}
}
void Player::getRekt(int dmg)
{
_hp -= dmg;
Player::playRandomPlayerEuuuhSound();
}
void Player::playRandomPlayerActionSound()
{
SoundHandler &sh = SoundHandler::getInstance();
sh.playSound(sh.player_sounds[rand() % sh.player_sounds.size()], 60);
}
void Player::playRandomPlayerEuuuhSound()
{
SoundHandler &sh = SoundHandler::getInstance();
sh.playSound(sh.euuuh[rand() % sh.euuuh.size()], 50);
}