-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectile.java
More file actions
107 lines (88 loc) · 3.01 KB
/
Projectile.java
File metadata and controls
107 lines (88 loc) · 3.01 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
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
public class Projectile extends TankObjects {
private int Speed;
private BufferedImage shell;
private int panel;
private double xaxis;
private double yaxis;
TankDriver driver;
TankObjectID enemy;
TankGameSounds soundPlayer;
private String hit = "resources/hit.wav";
public Projectile(double x, double y, double a, int speed, TankObjectID id, TankObjectID origin, TankDriver driver) {
super(x, y, id);
this.driver = driver;
Speed = speed;
xxAxis = 17;
yyAxis = 17;
theta = a;
soundPlayer = new TankGameSounds();
xaxis = Math.cos(theta) * Speed;
yaxis = Math.sin(theta) * Speed;
TankGameImage loader = new TankGameImage();
BufferedImage projectile = loader.loadImage("resources/ProjectileStrip.png");
panel = projectile.getWidth() / 60;
shell = projectile.getSubimage(30 * panel, 0, panel, panel);
if (origin == TankObjectID.Player1) {
enemy = TankObjectID.Player2;
} else {
enemy = TankObjectID.Player1;
}
}
@Override
public void create(Graphics models) {
Graphics2D graphics2D = (Graphics2D) models;
graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
AffineTransform update = graphics2D.getTransform();
graphics2D.rotate(theta, x + xxAxis / 3, y + yyAxis / 3);
graphics2D.drawImage(shell, (int)x, (int)y, xxAxis, yyAxis, null);
graphics2D.setTransform(update);
}
@Override
public void createMini(Graphics graphics, int x, int y) {
}
@Override
public Shape getShape() {
return new Rectangle2D.Double(x, y, xxAxis, yyAxis);
}
@Override
public Rectangle getRectangle() {
return new Rectangle((int)x, (int)y, xxAxis, yyAxis);
}
public void value_set(int speed){
Speed = speed;
}
@Override
public void clock() {
x += xaxis;
y += yaxis;
for (int i = 0; i < driver.obj.size(); i++) {
TankObjects tmpObj = driver.obj.get(i);
//collision
if (tmpObj.fetchObject() == TankObjectID.UnbreakableWall || tmpObj.fetchObject() == TankObjectID.BreakableWall ||
tmpObj.fetchObject() == enemy) {
if (getRectangle().intersects(tmpObj.getRectangle())) {
driver.removeObject(this);
if (tmpObj.fetchObject() == TankObjectID.BreakableWall) {
driver.removeObject(tmpObj);
soundPlayer.WAV(hit);
}
if (tmpObj.fetchObject() == TankObjectID.UnbreakableWall) {
soundPlayer.WAV(hit);
}
if (tmpObj.fetchObject() == enemy) {
tmpObj.setHealth(tmpObj.getHealth() - 20);
soundPlayer.WAV(hit);
}
}
}
}
}
}