-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.java
117 lines (113 loc) · 4.68 KB
/
Enemy.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
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
import java.util.ArrayList;
import java.util.HashMap;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.geometry.Point2D;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.scene.image.ImageView;
import java.io.*;
import javafx.scene.media.*;
import java.nio.file.*;
import javafx.util.Duration;
public class Enemy extends Alex{
Media stomp = new Media(Paths.get(Paths.get(".") + "/Music/goombadead.mp3").toUri().toString());
MediaPlayer playStomp = new MediaPlayer(stomp);
@Override
public void update(){
super.update();
for (int numG = 0; numG < goombas.size(); numG++){
if (goombaGravity.get(numG).getY() < 1){
goombaGravity.set(numG, goombaGravity.get(numG).add(0, 1));
}
moveGoombaY();
goombas.get(numG).setTranslateY(goombas.get(numG).getTranslateY() + goombaGravity.get(numG).getY());
if (goombas.get(numG).getBoundsInParent().intersects(graphics.player.getBoundsInParent())){
if (goombas.get(numG).getTranslateY() - 35 >= graphics.player.getTranslateY()){
goombas.get(numG).setVisible(false);
goombas.get(numG).setTranslateY(goombas.get(numG).getTranslateY() + 100);
playStomp.seek(Duration.seconds(0.5));
playStomp.play();
System.out.println("\nYou defeated a goomba!");
}
}
if (goombas.get(numG).getTranslateX() >= 1 && goombaTrue.get(numG) == true){
for (int i = 0; i < 1; i++){
for (Node platform : platforms){
if (goombas.get(numG).getBoundsInParent().intersects(platform.getBoundsInParent())){
if (goombaTrue.get(numG) == true){
if (goombas.get(numG).getTranslateX() == platform.getTranslateX() + 28){
goombaTrue.set(numG, false);
goombas.get(numG).setTranslateX(goombas.get(numG).getTranslateX() + 1);
return;
}
}
}
}
for (int numP = 0; numP < goombas.size(); numP++){
if (goombas.get(numP).getBoundsInParent().intersects(goombas.get(numG).getBoundsInParent())){
if (goombaTrue.get(numP) == true){
if (goombas.get(numP).getTranslateX() == goombas.get(numG).getTranslateX() + 28){
goombaTrue.set(numP, false);
goombas.get(numP).setTranslateX(goombas.get(numP).getTranslateX() + 1);
return;
}
}
}
}
goombas.get(numG).setTranslateX(goombas.get(numG).getTranslateX() - 1);
}
}
if (goombas.get(numG).getTranslateX() <= 1){
goombaTrue.set(numG, false);
}
if (goombas.get(numG).getTranslateX() + 28 >= levelWidth - 5){
goombaTrue.set(numG, true);
}
if (goombaTrue.get(numG) == false){
for (int i = 0; i < 1; i++){
for (Node platform : platforms){
if (goombas.get(numG).getBoundsInParent().intersects(platform.getBoundsInParent())){
if (goombaTrue.get(numG) == false){
if (goombas.get(numG).getTranslateX() + 28 == platform.getTranslateX()){
goombaTrue.set(numG, true);
goombas.get(numG).setTranslateX(goombas.get(numG).getTranslateX() - 1);
return;
}
}
}
}
for (int numP = 0; numP < goombas.size(); numP++){
if (goombas.get(numP).getBoundsInParent().intersects(goombas.get(numG).getBoundsInParent())){
if (goombaTrue.get(numP) == false){
if (goombas.get(numP).getTranslateX() + 28 == goombas.get(numG).getTranslateX()){
goombaTrue.set(numP, true);
goombas.get(numP).setTranslateX(goombas.get(numP).getTranslateX() - 1);
return;
}
}
}
}
goombas.get(numG).setTranslateX(goombas.get(numG).getTranslateX() + 1);
}
}
}
}
public void moveGoombaY(){
for (int numG = 0; numG < goombas.size(); numG++){
for (Node platform : platforms){
if (goombas.get(numG).getBoundsInParent().intersects(platform.getBoundsInParent())){
if (goombas.get(numG).getTranslateY() + 30 == platform.getTranslateY()){
goombas.get(numG).setTranslateY(goombas.get(numG).getTranslateY() - 2);
return;
}
}
}
}
}
}