This repository was archived by the owner on Dec 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.cpp
More file actions
97 lines (80 loc) · 2.08 KB
/
Bullet.cpp
File metadata and controls
97 lines (80 loc) · 2.08 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
//
// Created by firely-pasha on 6/20/17.
//
#include "Texture2D.h"
#include "Bullet.h"
#include "GameLevel.h"
#include "Player.h"
Bullet::Bullet(QVector2D *position, bool upDirection, int id, bool* canShoot, QString* name, bool isPlayer)
: GameObject(name, position, id)
{
speed = 2;
this->upDirection = upDirection;
shouldBeKilled = false;
this->isPlayer = isPlayer;
this->canShoot = canShoot;
*(this->canShoot) = false;
QRect *re;
re = new QRect(31, 432, 1, 4);
Texture2D *texture2D = new Texture2D(":resources/sprites/SpriteSheet.png", *re);
setTexture(texture2D);
QRect *coll = new QRect(0, 0, 1, 4);
setCollider(coll);
}
Bullet::~Bullet()
{
delete canShoot;
}
void Bullet::update()
{
GameObject::update();
if (upDirection)
{
if (position->y() <= 175 - speed)
{
position->setY(position->y() + speed);
}
else
{
(*canShoot) = true;
shouldBeKilled = true;
}
}
else
{
if (position->y() >= 32 - speed)
{
position->setY(position->y() - speed);
}
else
{
(*canShoot) = true;
shouldBeKilled = true;
}
}
updateCollider();
if (isPlayer)
{
for(std::map<int, GameObject*>::iterator it = GameLevel::gameObjects.begin(); it != GameLevel::gameObjects.end(); ++it)
{
QRect coll = *it->second->getCollider();
if (it->second != this && collider->intersects(coll))
{
if (*it->second->getName() == *name)
{
(*canShoot) = true;
it->second->shouldBeKilled = true;
shouldBeKilled = true;
GameLevel::addScore(10);
break;
}
}
}
}
else if (collider->intersects(*GameLevel::getPlayer()->getCollider()))
{
GameLevel::getPlayer()->addHp(-1);
qDebug() << GameLevel::getPlayer()->getHp();
shouldBeKilled = true;
}
}