-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbullet.cpp
More file actions
72 lines (70 loc) · 1.14 KB
/
bullet.cpp
File metadata and controls
72 lines (70 loc) · 1.14 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
#include "bullet.h"
using namespace std;
//Constructor. (x,y) is initial position. d is the direction the bullet
//is fired
bullet::bullet(int x, int y, char d)
{
image.load("bubble.png");
rect = image.rect();
rect.moveTo(x,y);
dir = d;
destroy = false;
}
//Return postion of element
QRect bullet::getRect()
{
return rect;
}
//Return image of element
QImage & bullet::getImage()
{
return image;
}
//Depending on dir variable, moves bullet in appropriate direction
void bullet::move()
{
if (dir == 'l')
{
if (rect.left() > 15)
{
for (int i = 0; i < 16; i++)
rect.moveLeft(rect.left() - 1);
}
else
destroy = true;
}
else if (dir == 'r')
{
if (rect.right() < 983)
{
for (int i = 0; i < 16; i++)
rect.moveRight(rect.right() + 1);
}
else
destroy = true;
}
else if (dir == 'u')
{
if (rect.top() > 15)
{
for (int i = 0; i < 16; i++)
rect.moveTop(rect.top() - 1);
}
else
destroy = true;
}
else if (dir == 'd')
{
if (rect.bottom() < 733)
{
for (int i = 0; i < 16; i++)
rect.moveBottom(rect.bottom() + 1);
}
else
destroy = true;
}
}
bool bullet::getDestroy()
{
return destroy;
}