parent
761d0c5c75
commit
b4b9ac582b
@ -0,0 +1,37 @@
|
||||
package com.msb.inter.impl;/**
|
||||
* @Author bingor
|
||||
* @Date 2022/10/11 9:41
|
||||
* @Description: com.msb.inter.impl
|
||||
* @Version: 1.0
|
||||
*/
|
||||
|
||||
import com.msb.inter.Collider;
|
||||
import com.msb.model.Bullet;
|
||||
import com.msb.model.Wall;
|
||||
import com.msb.model.abstracts.GameObject;
|
||||
|
||||
/**
|
||||
*@ClassName BulletWallCollider
|
||||
*@Description TODO
|
||||
*@Author bingor
|
||||
*@Date 2022/10/11 9:41
|
||||
*@Version 3.0
|
||||
*/
|
||||
public class BulletWallCollider implements Collider {
|
||||
@Override
|
||||
public boolean collide(GameObject o1, GameObject o2) {
|
||||
if(o1 instanceof Bullet && o2 instanceof Wall) {
|
||||
Bullet bullet = (Bullet) o1;
|
||||
Wall wall = (Wall) o2;
|
||||
|
||||
if(bullet.getRectangle().intersects(wall.getRectangle())) {
|
||||
bullet.die();
|
||||
}
|
||||
return true; //子弹碰墙,只有子弹消亡,但是墙还是好的,所以责任链还是需要继续
|
||||
} else if (o1 instanceof Wall && o2 instanceof Bullet) {
|
||||
return collide(o2, o1);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.msb.inter.impl;/**
|
||||
* @Author bingor
|
||||
* @Date 2022/10/11 9:41
|
||||
* @Description: com.msb.inter.impl
|
||||
* @Version: 1.0
|
||||
*/
|
||||
|
||||
import com.msb.inter.Collider;
|
||||
import com.msb.model.Tank;
|
||||
import com.msb.model.Wall;
|
||||
import com.msb.model.abstracts.GameObject;
|
||||
|
||||
/**
|
||||
*@ClassName BulletTankCollider
|
||||
*@Description TODO
|
||||
*@Author bingor
|
||||
*@Date 2022/10/11 9:41
|
||||
*@Version 3.0
|
||||
*/
|
||||
public class TankWallCollider implements Collider {
|
||||
@Override
|
||||
public boolean collide(GameObject o1, GameObject o2) {
|
||||
if(o1 instanceof Tank && o2 instanceof Wall) {
|
||||
Tank tank = (Tank) o1;
|
||||
Wall wall = (Wall) o2;
|
||||
if(tank.getRectangle().intersects(wall.getRectangle())) {
|
||||
tank.goBack();
|
||||
}
|
||||
return true; //坦克与墙相撞,坦克和墙不会消失,所以责任链应该继续
|
||||
} else if((o1 instanceof Wall && o2 instanceof Tank)) {
|
||||
return collide(o2, o1);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue