-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpaceship.java
More file actions
152 lines (120 loc) · 2.85 KB
/
Spaceship.java
File metadata and controls
152 lines (120 loc) · 2.85 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import javafx.scene.image.* ;
import javafx.scene.layout.* ;
public class Spaceship
{
private int health ;
private double x, y, width, height ;
private ImageView imageView ;
private Pane pane ;
private String name ;
private Boolean destroyed ;
public Spaceship(ImageView tempImageView, double tempX, double tempY, Pane tempPane)
{
this.imageView = tempImageView ;
this.width = this.imageView.getFitWidth() ;
this.height = this.imageView.getFitHeight() ;
this.x = tempX - (this.width/2) ; // sets the x coordinate of the center of the entity
this.y = tempY - (this.height/2) ; // sets the y coordinate of the center of the entity
this.pane = tempPane ;
this.imageView.setLayoutX(this.x) ;
this.imageView.setLayoutY(this.y) ;
this.pane.getChildren().add(this.imageView) ;
this.destroyed = false ;
}
public Laser fire()
{
double tempX = this.x + (this.width/2) ;
double tempY = this.y ;
Laser laser = new Laser(tempX, tempY, 3, 15, this.pane) ;
if(this.name.equals("PLAYER"))
laser.setDirection("UP") ;
else
laser.setDirection("DOWN") ;
return laser ;
}
// determines if it's been hit by a laser
public Boolean hit(Laser laser)
{
// create a new BoundingBox for this entity
BoundingBox boundingBox = getBoundingBox() ;
return boundingBox.isColliding(laser.getBoundingBox()) ;
}
public void destruct()
{
this.pane.getChildren().remove(this.imageView) ;
this.destroyed = true ;
}
public Boolean destroyed()
{
return this.destroyed ;
}
public BoundingBox getBoundingBox()
{
return new BoundingBox(this.x, this.y, this.width, this.height) ;
}
public String getName()
{
return this.name ;
}
public Double getX()
{
return this.x ;
}
public Double getY()
{
return this.y ;
}
public Double getWidth()
{
return this.width ;
}
public Double getHeight()
{
return this.height ;
}
public Pane getPane()
{
return this.pane ;
}
public Integer getHealth()
{
return this.health ;
}
public void setName(String temp)
{
this.name = temp ;
}
public void setX(double tempX)
{
this.x = tempX ;
this.imageView.setLayoutX(this.x) ;
}
public void setY(double tempY)
{
this.y = tempY ;
this.imageView.setLayoutY(this.y) ;
}
public void setWidth(double tempWidth)
{
this.width = tempWidth ;
this.imageView.setFitWidth(this.width) ;
}
public void setHeight(double tempHeight)
{
this.height = tempHeight ;
this.imageView.setFitHeight(this.height) ;
}
public void setHealth(int h)
{
this.health = h ;
}
public void setPane(Pane tempPane)
{
this.pane = tempPane ;
}
public void setImage(Image tempImg)
{
this.imageView = new ImageView(tempImg) ;
this.pane.getChildren().add(imageView) ;
}
}