if((this.x>=et.x && this.x <= et.x + 20//第一个点x在内
&& this.y>=et.y && this.y <= et.y + 30)//第一个点y在内
||(this.x + 20>=et.x && this.x+ 20 <= et.x + 20//第二个点x在内
&& this.y >=et.y && this.y <= et.y + 30)//第二个点y在内
){
b = true;
}
}
if(et.direct == 2 || et.direct == 3){//左或右
if((this.x>=et.x && this.x <= et.x + 30//第一个点x在内
&& this.y>=et.y && this.y <= et.y + 20)//第一个点y在内
||(this.x + 20>=et.x && this.x+ 20 <= et.x + 30//第二个点x在内
&& this.y >=et.y && this.y <= et.y + 20)//第二个点y在内
){
b = true;
}
}
}
}
break;
case 1://向下
for(int i = 0; i < ets.size(); i++){
EnemyTask et = ets.get(i);
if(et != this){
if(et.direct == 0 || et.direct == 1){//上或下
if((this.x>=et.x && this.x <= et.x + 20//第一个点x在内
&& this.y + 30>=et.y && this.y + 30 <= et.y + 30)//第一个点y在内
||(this.x + 20>=et.x && this.x+ 20 <= et.x + 20//第二个点x在内
&& this.y + 30>=et.y && this.y + 30 <= et.y + 30)//第二个点y在内
){
b = true;
}
}
if(et.direct == 2 || et.direct == 3){//左或右
if((this.x>=et.x && this.x <= et.x + 30//第一个点x在内
&& this.y + 30 >=et.y && this.y + 30 <= et.y + 20)//第一个点y在内
||(this.x + 20 >=et.x && this.x+ 20 <= et.x + 30//第二个点x在内
&& this.y + 30 >=et.y && this.y + 30 <= et.y + 20)//第二个点y在内
){
b = true;
}
}
}
}
break;
case 2:
for(int i = 0; i < ets.size(); i++){
EnemyTask et = ets.get(i);
if(et != this){
if(et.direct == 0 || et.direct == 1){//上或下
if((this.x>=et.x && this.x <= et.x + 20//第一个点x在内
&& this.y>=et.y && this.y <= et.y + 30)//第一个点y在内
||(this.x >=et.x && this.x<= et.x + 20//第二个点x在内
&& this.y + 20 >=et.y && this.y + 20 <= et.y + 30)//第二个点y在内
){
b = true;
}
}
if(et.direct == 2 || et.direct == 3){//左或右
if((this.x>=et.x && this.x <= et.x + 30//第一个点x在内
&& this.y>=et.y && this.y <= et.y + 20)//第一个点y在内
||(this.x >=et.x && this.x<= et.x + 30//第二个点x在内
&& this.y + 20>=et.y && this.y + 20 <= et.y + 20)//第二个点y在内
){
b = true;
}
}
}
}
break;
case 3:
for(int i = 0; i < ets.size(); i++){
EnemyTask et = ets.get(i);
if(et != this){
if(et.direct == 0 || et.direct == 1){//上或下
if((this.x + 30>=et.x && this.x + 30 <= et.x + 20//第一个点x在内
&& this.y>=et.y && this.y <= et.y + 30)//第一个点y在内
||(this.x + 30 >=et.x && this.x+ 30 <= et.x + 20//第二个点x在内
&& this.y + 20 >=et.y && this.y + 20 <= et.y + 30)//第二个点y在内
){
b = true;
}
}
if(et.direct == 2 || et.direct == 3){//左或右
if((this.x + 30>=et.x && this.x + 30 <= et.x + 30//第一个点x在内
&& this.y>=et.y && this.y <= et.y + 20)//第一个点y在内
||(this.x + 30>=et.x && this.x+ 30 <= et.x + 30//第二个点x在内
&& this.y + 20>=et.y && this.y + 20 <= et.y + 20)//第二个点y在内
){
b = true;
}
}
}
}
break;
default:
break;
}
return b ;
}
@Override
public void run() {
int a = (int) (Math.random() * 10 + 2);//连动步数
int times = 0;
while(true){
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//if(x > 0 && x < 400 - 30 & y > 0 && y < 300 - 30){
//if(!this.isTouchOhterTank()){
switch(this.direct){
case 0:
//System.out.println(isTouchOhterTank());
for(int i = 0 ;i < a ; i++){
if(y - this.speed > 0 && !this.isTouchOhterTank()){
y -= this.speed;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
case 1:
for(int i = 0 ;i < a ; i++){
if(y + speed < 300 - 30 && !this.isTouchOhterTank()){
y += this.speed;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
case 2:
for(int i = 0 ;i < a ; i++){
if(x - speed > 0 && !this.isTouchOhterTank()){
x -= this.speed;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
case 3:
for(int i = 0 ;i < a ; i++){
if(x + speed < 400 - 30 && !this.isTouchOhterTank()){
x += this.speed;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
}
//}
times ++;
if(times % 2 == 0){
if(isLive){
if(ss.size() < 3){
shot s = null;
switch (dir