-
Notifications
You must be signed in to change notification settings - Fork 0
/
Missile.java
131 lines (121 loc) · 3.81 KB
/
Missile.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import javafx.scene.image.*;
import java.util.ArrayList;
public class Missile extends BasicBlock {
int direction = 2;
boolean ml = false;
int m_type = 0;
public Missile(Location l, Image im){
super(l,im,BasicBlock.BlockType.MISSILE);
}
public Missile(Location l, int typ) {
super(l, BasicBlock.BlockType.MISSILE);
m_type = typ;
image = new Image("abc.png");
iv = new ImageView(image);
iv.setX(-40);
iv.setY(-40);
iv.setFitHeight(5);
iv.setFitWidth(4);
}
protected boolean movePossible() {
int rt = 0;
int ct = 0;
if (direction == 1){
rt = location.getRow()-5;
ct = location.getCol();
} else if (direction == -1){
rt = location.getRow()+5;
ct = location.getCol();
} else if (direction == 0){
rt = location.getRow();
ct = location.getCol()-5;
} else if (direction == 2){
rt = location.getRow();
ct = location.getCol()+5;
}
Location newLoc = new Location(rt, ct);
BasicBlock[][] map = Data.getData().map;
if (rt < 0 || ct < 0 || rt > 505 || ct > 505 ||map[rt/40][ct/40].location.getCol() != -40 || map[(rt+10)/40][ct/40].location.getCol() != -40 || map[rt/40][(ct + 10)/40].location.getCol() != -40 || map[(rt+10)/40][(ct+10)/40].location.getCol() != -40) {
if (rt < 0 || ct < 0 || rt > 505 || ct > 505) {
} else {
if (map[rt/40][ct/40].location.getCol() != -40) {
System.out.println("SSS");
if (map[rt/40][ct/40].type == 3){
BrickBlock fd = (BrickBlock) map[rt/40][ct/40];
fd.impact(0);
} else if (map[rt/40][ct/40].type == 5) {
Eagle fd = (Eagle) map[rt/40][ct/40];
fd.impact(0);
}
} else if (map[(rt+10)/40][ct/40].location.getCol() != -40) {
System.out.println("SSS");if (map[rt/40][ct/40].type == 3){
BrickBlock fd = (BrickBlock) map[(rt+10)/40][ct/40];
fd.impact(0);
} else if (map[(rt+10)/40][ct/40].type == 5){
Eagle fd = (Eagle) map[(rt+10)/40][ct/40];
fd.impact(0);
}
} else if (map[rt/40][(ct+10)/40].location.getCol() != -40) {
System.out.println("SSS");
if (map[rt/40][(ct+10)/40].type == 3){
BrickBlock fd = (BrickBlock) map[rt/40][(ct+10)/40];
fd.impact(0);
} else if (map[rt/40][(ct+10)/40].type == 5){
Eagle fd = (Eagle) map[rt/40][(ct+10)/40];
fd.impact(0);
}
} else if (map[(rt+10)/40][(ct+10)/40].location.getCol() != -40) {
System.out.println("SSS");
if (map[(rt+10)/40][(ct+10)/40].type == 3){
BrickBlock fd = (BrickBlock) map[(rt+10)/40][(ct+10)/40];
fd.impact(0);
} else if (map[(rt+10)/40][(ct+10)/40].type == 5){
Eagle fd = (Eagle) map[(rt+10)/40][(ct+10)/40];
fd.impact(0);
}
}
}
return false;
}
Player player = Data.getData().player;
if (iv.intersects(player.iv.getBoundsInLocal())){
player.impact(2);
return false;
}
ArrayList<Enemy> enem = Data.getData().enem;
for (int tv = 0; tv < enem.size(); tv++) {
Enemy dv = enem.get(tv);
if (iv.intersects(dv.iv.getBoundsInLocal())){
if (m_type == 1) {
dv.impact(1);
}
return false;
}
}
return true;
}
public void makeMove() {
if (direction == 1)
location.setLocation(location.getRow()-5,location.getCol());
if (direction == -1)
location.setLocation(location.getRow()+5,location.getCol());
if (direction == 0)
location.setLocation(location.getRow(),location.getCol()-5);
if (direction == 2)
location.setLocation(location.getRow(),location.getCol()+5);
iv.setX(location.getCol());
iv.setY(location.getRow());
}
public void doAction(){
if (ml) {
if (movePossible()) {
makeMove();
} else {
System.out.println("Missilfe");
ml = false;
iv.setX(-40);
iv.setY(-40);
}
}
}
}