-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnergizer.java
51 lines (42 loc) · 1.18 KB
/
Energizer.java
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
package Pacman;
import java.util.ArrayList;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;
/*
* This class is a wrapper class of an Ellipse that represent an Energizer. Its main purpose is to
* define the collision method for an Energizer.
*/
public class Energizer implements SmartObjects{
Ellipse _dot;
Rectangle _rect;
Pacman _pac;
BorderPane _pane;
public Energizer(Pacman pacman, BorderPane pane) {
_pane = pane;
_pac = pacman;
_dot = new Ellipse(10,10);
_dot.setFill(Color.WHITE);
}
public void setX(double x) {
_dot.setCenterX(x+12);
}
public void setY(double y) {
_dot.setCenterY(y+10);
}
public Shape getShape() {
return _dot;
}
//Set the mode to be frightened and remove it from the array and the screen and update the score of the game
public void collision(ArrayList<SmartObjects> arr) {
_pac.setMode(Mode.FRIGHTENED);
if(!arr.isEmpty()) {//it contains a dot/peg
_pac.getPacman().getDot().toFront();
_pane.getChildren().remove(this.getShape());
arr.remove(this);
_pac.updateScore(10);
}
}
}