-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGun.pde
54 lines (46 loc) · 1.05 KB
/
Gun.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
/**
* Used by the player to defeat Enemies (Minoutars)
*/
public class Gun {
public int x;
public int y;
public Maze m;
public boolean broken = false;
// Change in percent for the sword to break when used!
private double chance = 0.50;
private boolean pickedUp = false;
public Gun(int x, int y, Maze m) {
this.x = x;
this.y = y;
this.m = m;
}
/**
* Uses the gun
*
* If the gun breaks after using it will still return true
* Returns true if the broken boolean is true
*
*/
public boolean use() {
if (broken) return false;
broken = willBreak();
return true;
}
/** Returns if the sword should break when used */
public boolean willBreak() {
double r = Math.random();
return (r >= chance);
}
/**
* Will render nothing if the gun has been picked up
* Else renders a pixel art gun to the screen
*/
public void update() {
if (pickedUp) return;
image(
m.stor.gun,
(x * Settings.STEP) + Settings.STEP / 2,
(y * Settings.STEP) + Settings.STEP / 2
);
}
}