-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbullet.cpp
More file actions
57 lines (46 loc) · 838 Bytes
/
bullet.cpp
File metadata and controls
57 lines (46 loc) · 838 Bytes
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
#include "bullet.h"
/*
Bullet(int xpos, int ypos, int xdir, int ydir, int damage, int speed);
void autoMove();
int xdir;
int ydir;
int xpos;
int ypos;
int damage;
int speed;
QImage bulletImage;
QRect bulletRect;
*/
Bullet::Bullet(int damage, int speed)
{
this->damage = damage;
this->speed = speed;
bulletImage.load("bullet.png");
hitTarget = 0;
}
void Bullet::setHit()
{
hitTarget = 1;
}
void Bullet::fired(int xpos, int ypos, int xdir, int ydir)
{
bulletRect = bulletImage.rect();
this->xpos = xpos;
this->ypos = ypos;
this->xdir = xdir;
this->ydir = ydir;
bulletRect = bulletImage.rect();
bulletRect.moveTo(xpos, ypos);
}
void Bullet::autoMove()
{
bulletRect.translate(xdir, ydir);
if (xdir == 1)
xpos++;
else
xpos--;
if (ydir == 1)
ypos++;
else
ypos--;
}