-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
81 lines (73 loc) · 1.38 KB
/
Player.cpp
File metadata and controls
81 lines (73 loc) · 1.38 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
#include "Player.hpp"
#include "GameStateManager.hpp"
Player::Player(int x, int y, char symbol)
{
this->set_x(x);
this->set_y(y);
this->set_symbol(symbol);
}
void Player::input()
{
if (_kbhit())
{
switch (_getch())
{
case 'a':
this->dir = LEFT;
break;
case 'd':
this->dir = RIGHT;
break;
case 's':
this->dir = STOP;
break;
case 'w':
this->fire();
break;
case 'x':
GameStateManager::isOver = true;
break;
}
}
}
void Player::Move()
{
switch (this->dir)
{
case LEFT:
this->set_x(this->get_x() - 1);
break;
case RIGHT:
this->set_x(this->get_x() + 1);
break;
default:
break;
}
// this->set_x(this->get_x());
// this->set_y(this->get_y());
}
void Player::fire()
{
if (this->get_bullet_timer() == 0)
{
this->bullet.set_position(this->get_x(), this->get_y() - 1);
this->bullets.push_back(this->bullet);
this->set_bullet_timer(2);
}
}
PlayerBullet &Player::get_bullet()
{
return this->bullet;
}
std::vector<PlayerBullet> &Player::get_bullets()
{
return this->bullets;
}
int &Player::get_score()
{
return this->score;
}
void Player::set_score(int score)
{
this->score = score;
}