-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.pde
101 lines (91 loc) · 1.93 KB
/
Bullet.pde
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
public class Bullet
{
private float x;
private float y;
private float diameter;
private boolean active;
public Bullet() //default constructor
{
this.active = false; //setting active variable default value to false
}
/*
overloaded constructor - public method with no return value taking in 3 parameters
*/
public Bullet(float x, float y, float diameter)
{
this.active = false;
this.x = x;
this.y = y;
if ((diameter >=15 ) && (diameter <=25)) //validation so that diameter does not go outside certain dimensions
{
this.diameter = diameter;
} else
{
this.diameter = 20;
}
}
/*
public method with no return displaying the Bullet
*/
public void display()
{
fill(0);
circle(x, y, diameter);
}
/*
public method with no return moving the bullet up the screen by decreasing the y-axis coordinate.
If the y coordinate reaches the top of the screen (y<=0) the resetBullet method is called.
*/
public void move()
{
this.y = y-3;
if (y <= 0)
{
resetBullet();
}
}
//getter methods
public float getX()
{
return x;
}
public float getY()
{
return y;
}
public float getDiameter()
{
return diameter;
}
public boolean getActive()
{
return active;
}
//setter methods
public void setX(float x)
{
this.x = x;
}
public void setY(float y)
{
this.y = y;
}
public void setDiameter(float diameter)
{
if ((diameter >=15 ) && (diameter <=25)) //validation so that diameter does not go outside certain dimensions
{
this.diameter = diameter;
}
}
public void setActive(boolean active)
{
this.active = active;
}
/*
private helper method with no return resetting boolean variable to false.
*/
private void resetBullet()
{
this.active = false;
}
}