-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPowerUpFuel.java
More file actions
89 lines (72 loc) · 2.1 KB
/
PowerUpFuel.java
File metadata and controls
89 lines (72 loc) · 2.1 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
package org.ergasia.javaspacegame;
import java.awt.Image;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
public class PowerUpFuel {
/*X dimension of the object */
private int x;
/*Y dimension of the object */
private int y;
/*The width of the object */
private int width;
/*The height of the object */
private int height;
private Image image;
/*In this variable is saved the total score */
/*Random object */
private Random rand;
private boolean fuelhit;
private boolean isActive=false;
public PowerUpFuel() {
ImageIcon ii = null;
try {
ii = new ImageIcon(ImageIO.read(Objects.requireNonNull(getClass().getResourceAsStream("/gasolina.png"))));
} catch (IOException e) {
throw new RuntimeException(e);
}
image = ii.getImage();
rand = new Random();
do{
x = 40 + rand.nextInt(720);
y = 30 + rand.nextInt(440);
}while(x > 642 && y < 137);
width = image.getWidth(null);
height = image.getHeight(null);
}
public Image getImage() {
return image;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public void checkForCollision(ArrayList<Ammo> ammos) {
if (fuelhit) return;
for(int i=0; i<ammos.size(); i++){
int ammoX = ammos.get(i).getX();
int ammoY = ammos.get(i).getY();
int ammoWidth = ammos.get(i).getWidth();
int ammoHeight = ammos.get(i).getHeight();
if(ammoY + ammoHeight > y && ammoY + ammoHeight < y + height){
if(ammoX + ammoWidth > x && ammoX < x + width){
image = null;
fuelhit = true;
boolean isActive = true;
}
}
}
}
public boolean fuelCheck(){
return fuelhit;
}
public void changefuelhit() {
this.fuelhit = false;
;
}
}