-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweapon.cpp
More file actions
68 lines (58 loc) · 1.04 KB
/
weapon.cpp
File metadata and controls
68 lines (58 loc) · 1.04 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
#include "weapon.h"
#include <iostream>
/*
Weapon(int type);
~Weapon();
Bullet* bullets;
Gun* gun;
*/
Weapon::Weapon()
{
gun = new Pistol(-1,-1);
player = NULL;
}
Weapon::Weapon(int type, UserPlayer& play)
{
this->type = type;
if (type == 0)
{
gun = new Pistol(-1,-1);
}
else if (type == 1)
{
gun = new LMG(-1,-1);
}
else if (type == 2)
{
gun = new Shotgun(-1,-1);
}
else
{
gun = new Sniper(-1,-1);
}
player = &play;
}
void Weapon::shoot()
{
if (gun->shoot())
{
Bullet* newBullet = new Bullet(gun->getDamage(), gun->getSpeed());
newBullet->fired(player->getXpos() + player->getXdir(), player->getYpos() + player->getYdir(), player->getXdir(), player->getYdir());
bullets.push_back(newBullet);
}
for (int i = 0; i < 6; i++)
{
QVector<Bullet*>::iterator biter;
int found = 0;
for (biter = bullets.begin(); biter != bullets.end(); biter++)
{
if ((*biter)->getXpos() >1000 || (*biter)->getYpos() > 1000)
{
found = 1;
break;
}
}
if (found == 1)
bullets.erase(biter);
}
}