-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbullet.cpp
More file actions
120 lines (99 loc) · 2.56 KB
/
Copy pathbullet.cpp
File metadata and controls
120 lines (99 loc) · 2.56 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
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
/*#################################################################
BattleMage bullet.cpp
Copyright (C) 2012 Quentin Hsu
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
To contact the author, email: haloqa@gmail.com
##################################################################*/
#include "bullet.h"
#include <QRadialGradient>
#include <QPainter>
bullet::bullet() : QGraphicsEllipseItem()
{
type = 1; //first type of bullet
setRect(-10.0,-10.0,20.0,20.0); //set bullet size
QPointF temp(370, 370); // initialize a position
set_current(temp);
speed = 0;
//color bullet red gradient
QRadialGradient rGrad( 0.0, 0.0, 10.0, 0.0, 0.0);
rGrad.setColorAt(0.0, QColor(255,255,255));
rGrad.setColorAt(0.5, QColor(200,100,20));
rGrad.setColorAt(1.0, QColor(255,0,0,0));
setBrush(QBrush(rGrad));
setPen(QPen(Qt::NoPen)); //no outline
active = false;
}
void bullet::advance(int phase)
{
if(phase = 1)
{
setPoint(current, current.x() - speed, current.y()); //move left based off speed
setPos(current);
if(current.x() < 0) //delete bullet if off screen
{
active = false;
}
}
}
//setters and getters
void bullet::set_current(int x, int y)
{
QPointF temp(x, y);
current = temp;
}
void bullet::set_current(double x, double y)
{
QPointF temp(x, y);
current = temp;
}
void bullet::set_current(QPointF temp)
{
current = temp;
}
QPointF bullet::get_current()
{
return current;
}
void bullet::set_active(bool x)
{
active = x;
}
bool bullet::get_active()
{
return active;
}
void bullet::setPoint(QPointF& current, int x, int y) //function to set QPointF's easier
{
current.setX(x);
current.setY(y);
}
void bullet::setPoint(QPointF& current, double x, double y)
{
current.setX(x);
current.setY(y);
}
void bullet::set_speed(double x)
{
speed = x;
}
double bullet::get_speed()
{
return speed;
}
void bullet::set_type(int i)
{
type = i;
}
int bullet::get_type()
{
return type;
}