-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.cpp
173 lines (133 loc) · 2.49 KB
/
bullet.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "bullet.h"
#include <iostream>
bool Bullet::getAttackPlayer() const
{return attackPlayer;}
bool Bullet::getDiag() const
{return isDiagonal;}
int Bullet::getX () const
{return xPos;}
int Bullet::getY () const
{return yPos;}
char Bullet::getSymbol () const
{return symbol;}
void Bullet::setX (int x)
{xPos = x;}
void Bullet::setY (int y)
{yPos = y;}
Bullet::Bullet (bool enemyLaunch, bool moveDiag, int x, int y)
{
attackPlayer = enemyLaunch;
isDiagonal = moveDiag;
image.load("bullet.png");
rect = image.rect();
if(isDiagonal == true){
symbol = '.';
xDir = 1;
}
else if(attackPlayer == true){
symbol = '*';
yDir = 1;
xDir = 0;
}
else{
symbol = '!';
yDir = -1;
xDir = 0;
}
xPos = x + 15;
yPos = y;
destroyed = false;
rect.moveTo(xPos, yPos);
}
Bullet::Bullet()
{
xDir = 1;
yDir = -1;
attackPlayer = false;
isDiagonal = false;
symbol = '!';
//xPos = 200;
//yPos = 300;
image.load("ball.png");
rect = image.rect();
destroyed = false;
rect.moveTo(xPos, yPos);
}
void Bullet::moveBullet (){
if(attackPlayer == true)
yPos++;
else
yPos--;
}
void Bullet::moveBulletDiag(){
yPos++;
xPos++;
}
Bullet::~Bullet() {
std::cout << ("Ball deleted\n");
}
void Bullet::autoMove(int level)
{
for (int i=0; i<=(level+1); i++){
rect.translate(xDir, yDir);
if(rect.left() == 0){
destroyed = true;
}
if(rect.right() == 300){
//delete this;
destroyed = true;
}
if(rect.top() == 0){
destroyed = true;
//delete this;
}
}
}
void Bullet::moveBottom(int bottom)
{
rect.moveBottom(bottom);
}
void Bullet::moveTop(int top)
{
rect.moveTop(top);
}
void Bullet::moveLeft(int left)
{
rect.moveLeft(left);
}
void Bullet::moveRight(int right)
{
rect.moveRight(right);
}
void Bullet::setXDir(int x)
{
xDir = x;
}
void Bullet::setYDir(int y)
{
yDir = y;
}
int Bullet::getXDir()
{
return xDir;
}
int Bullet::getYDir()
{
return yDir;
}
QRect Bullet::getRect()
{
return rect;
}
QImage & Bullet::getImage()
{
return image;
}
bool Bullet::isDestroyed()
{
return destroyed;
}
void Bullet::setDestroyed(bool destr)
{
destroyed = destr;
}