-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cpp
129 lines (120 loc) · 2.56 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "player.h"
#include "pistol.h"
#include "bazooka.h"
#include "sniperrifle.h"
#include "board.h"
Player::Player(Board *_map, float _speed, int _maxHp, int _width, int _height)
:Creature(_map,_speed,_maxHp,_width,_height)
{
Weapons.push_back(new Pistol());
Weapons.push_back(new Bazooka());
Weapons.push_back(new SniperRifle());
Weapon=Weapons.at(0);
}
Player::~Player()
{
for(int i=0;i<(int)Weapons.size();i++)
{
delete Weapons.at(i);
}
Weapons.clear();
}
void Player::move(Board *_map)
{
if(move_up)
{
if(!checkCollisionUp(_map))
{
Y-=Speed;
}
}
if(move_right)
{
if(!checkCollisionRight(_map))
{
X+=Speed;
}
}
if(move_down)
{
if(!checkCollisionDown(_map))
{
Y+=Speed;
}
}
if (move_left)
{
if(!checkCollisionLeft(_map))
{
X-=Speed;
}
}
}
void Player::shoot(Board *_map)
{
if(PlayerShootOn)
{
float startX;
float startY;
if((PlayerDstX-Width/2)<=X-2)
{
startY=Y+Height/2;
startX=X-4;
}
else if((PlayerDstY-Height/2)<=Y-2)
{
startY=Y-4;
startX=X+Width/2;
}
else if((PlayerDstX-Width/2)>=X+Width+2)
{
startY=Y+Height/2;
startX=X+Width+2;
}
else if((PlayerDstY-Height/2)>=X+Height+2)
{
startY=Y+Height+4;
startX=X+Width/2;
}
_map->addMobile(Weapon->CreateBullet(PlayerDstX,PlayerDstY,startX,startY));
}
}
void Player::ChangeWeapon()
{
if(pistolOn)
{
Pistol* tmp;
for(int i=0;i<(int)Weapons.size();i++)
{
tmp=dynamic_cast<Pistol*>(Weapons.at(i));
if(tmp)
{
Weapon=Weapons.at(i);
}
}
}
else if(bazookaOn)
{
Bazooka* tmp;
for(int i=0;i<(int)Weapons.size();i++)
{
tmp=dynamic_cast<Bazooka*>(Weapons.at(i));
if(tmp)
{
Weapon=Weapons.at(i);
}
}
}
else if(sniperrifleOn)
{
SniperRifle* tmp;
for(int i=0;i<(int)Weapons.size();i++)
{
tmp=dynamic_cast<SniperRifle*>(Weapons.at(i));
if(tmp)
{
Weapon=Weapons.at(i);
}
}
}
}