-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectile.java
More file actions
86 lines (70 loc) · 1.82 KB
/
Projectile.java
File metadata and controls
86 lines (70 loc) · 1.82 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
import java.awt.Image;
import java.io.File;
import java.util.ArrayList;
import javax.imageio.ImageIO;
public class Projectile {
private int pos_x;
private int pos_y;
private int width = 30;
private int height =30;
private int speed =10;
private Image projectilImage;
//constructor
public Projectile(){
this.pos_x = 0;
}
public Projectile(int pos_x, int pos_y){
this.pos_x = pos_x;
this.pos_y = pos_y;
try{
this.projectilImage = ImageIO.read(new File("Image/projectile_1.png"));
}
catch(Exception e){
System.out.println("kevin is a wasted yute");
}
}
//inBound function
public boolean inbound(int y){
if(y > 0 && y< 720){
return true;
}
else return false;
}
public boolean playerProjectileCollision(ArrayList<Character> enemies, Score score) {
for (Character e : enemies) {
if (this.getPosX() >= e.getPosX() && this.getPosX() <= e.getPosX() + e.getWidth() &&
this.getPosY() >= e.getPosY() && this.getPosY() <= e.getPosY() + e.getHeight()) {
e.setHp(e.getHp() - 1);
score.setScore(score.getScore()+10);
return true;
}
}
return false;
}
// getter function
public int getPosX(){
return this.pos_x;
}
public Image getProjectImage(){
return this.projectilImage;
}
public int getPosY(){
return this.pos_y;
}
public int getWidth(){
return this.width;
}
public int getHeight(){
return this.height;
}
public int getSpeed(){
return this.speed;
}
// setter function
public void setPosX(int x){
this.pos_x = x;
}
public void setPosY(int y){
this.pos_y = y;
}
}