-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tank.java
81 lines (79 loc) · 2.35 KB
/
Tank.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
import javafx.scene.image.*;
import java.util.ArrayList;
public class Tank extends BasicBlock{
int play = 0;
boolean killed = false;
Missile missile;
int direction = 2;
int prevdir = 0;
int dele = 0;
Tank(Location l,Image im){
super(l,im,BasicBlock.BlockType.TANK);
}
Tank(Location l){
super(l,BasicBlock.BlockType.TANK);
}
public boolean movePossible(){
int rt = 0;
int ct = 0;
if (direction == 1){
rt = location.getRow()-2;
ct = location.getCol();
} else if (direction == -1){
rt = location.getRow()+2;
ct = location.getCol();
} else if (direction == 0){
rt = location.getRow();
ct = location.getCol()-2;
} else if (direction == 2){
rt = location.getRow();
ct = location.getCol()+2;
}
Location newLoc = new Location(rt, ct);
BasicBlock[][] map = Data.getData().map;
if (rt < 0 || ct < 0 || rt > 485 || ct > 485 ||map[rt/40][ct/40].location.getCol() != -40 || map[(rt+30)/40][ct/40].location.getCol() != -40 || map[rt/40][(ct + 30)/40].location.getCol() != -40 || map[(rt+30)/40][(ct+30)/40].location.getCol() != -40) {
return false;
}
Player player = Data.getData().player;
if (play != 1 && (newLoc.collision(player.location)))
return false;
if (Data.getData().powerup.avail && play == 1) {
if (iv.intersects(Data.getData().powerup.iv.getBoundsInLocal())) {
System.out.println("sds");
Data.getData().powerup.impact(0);
Data.getData().powerup.avail = false;
Data.getData().powerup.on = true;
if (Data.getData().powerup.p_type == 1) {
Data.getData().powerup.on = false;
}
Data.getData().powerup.newPowerup(new Location(-40,-40), 0);
}
}
ArrayList<Enemy> enem = Data.getData().enem;
for (Enemy dv : enem) {
if (!(location.equals(dv.location)) && (newLoc.collision(dv.location)))
return false;
}
return true;
}
protected void makeMove(){
int rt = 0;
int ct = 0;
if (direction == 1){
rt = location.getRow()-2;
ct = location.getCol();
} else if (direction == -1){
rt = location.getRow()+2;
ct = location.getCol();
} else if (direction == 0){
rt = location.getRow();
ct = location.getCol()-2;
} else if (direction == 2){
rt = location.getRow();
ct = location.getCol()+2;
}
location.setLocation(rt, ct);
iv.setX(ct);
iv.setY(rt);
}
}