-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
115 lines (92 loc) · 2.57 KB
/
Player.cpp
File metadata and controls
115 lines (92 loc) · 2.57 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
108
109
110
111
112
113
114
115
//
// Created by segalle on 11/7/21.
//
#include "Player.h"
namespace entities {
namespace characters {
Player::Player() : MovingEntity(),
inputs(nullptr),
counter(0)
{
inputs = new InputManager();
id = 1;
health = 100;
}
Player::~Player() {
delete inputs;
}
void Player::run() {
if(inputs->isKeyPressed(actions.left) && inputs->isKeyPressed(actions.right)){
speed.x = 0;
}
else if(inputs->isKeyPressed(actions.left)){
speed.x = -moving_speed;
direction = -1;
}
else if(inputs->isKeyPressed(actions.right)){
speed.x = moving_speed;
direction = 1;
}
else{
speed.x = 0;
}
fire = nullptr;
attackCounter();
attack();
jump();
position += speed;
}
void Player::attack() {
if(can_attack && inputs->isKeyPressed(actions.shoot)){
fire = new Star();
fire->setDirection(direction);
fire->setPosition(sprite->getGlobalBounds().width/2 + position.x - 40, sprite->getGlobalBounds().height/2 + position.y - 20);
counter = 0;
}
}
void Player::jump() {
if (ground && inputs->isKeyPressed(actions.jump)) {
speed.y = jump_speed;
ground = false;
}
else{
fall();
}
}
void Player::score(int score) {
points += score;
}
int Player::getScore(){
return points;
}
void Player::attackCounter() {
counter++;
if(counter < 144){
can_attack = false;
}
else{
can_attack = true;
}
}
int Player::getCollisionDamage() {
return 0;
}
Entity *Player::getProjectile() {
Entity* value = static_cast<Entity*>(fire);
fire = nullptr;
return value;
}
void Player::setMapping(Actions actions) {
this->actions = actions;
}
void Player::operator++() {
points += 10;
}
void Player::setScore(int value) {
points = value;
}
float Player::moving_speed = 5;
float Player::jump_speed = -14;
int Player::points = 0;
}
}