parent
0092ad544e
commit
09d84ecaec
@ -0,0 +1,13 @@
|
||||
package com.msb.inter;
|
||||
|
||||
import com.msb.model.abstracts.GameObject;
|
||||
|
||||
/**
|
||||
* @Author bingor
|
||||
* @Date 2022/10/11 9:39
|
||||
* @Description: com.msb.inter
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface Collider {
|
||||
public void collide(GameObject o1, GameObject o2);
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
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.Tank;
|
||||
import com.msb.model.abstracts.GameObject;
|
||||
|
||||
/**
|
||||
*@ClassName BulletTankCollider
|
||||
*@Description TODO
|
||||
*@Author bingor
|
||||
*@Date 2022/10/11 9:41
|
||||
*@Version 3.0
|
||||
*/
|
||||
public class BulletTankCollider implements Collider {
|
||||
@Override
|
||||
public void collide(GameObject o1, GameObject o2) {
|
||||
if(o1 instanceof Bullet && o2 instanceof Tank) {
|
||||
Bullet bullet = (Bullet) o1;
|
||||
Tank tank = (Tank) o2;
|
||||
if(bullet.getGroup() == tank.getGroup()) return;
|
||||
|
||||
if(bullet.getRectangle().intersects(tank.getRectangle())) {
|
||||
bullet.die();
|
||||
tank.die();
|
||||
}
|
||||
} else if (o1 instanceof Tank && o2 instanceof Bullet) {
|
||||
collide(o2, o1);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
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.abstracts.GameObject;
|
||||
|
||||
/**
|
||||
*@ClassName BulletTankCollider
|
||||
*@Description TODO
|
||||
*@Author bingor
|
||||
*@Date 2022/10/11 9:41
|
||||
*@Version 3.0
|
||||
*/
|
||||
public class TankTankCollider implements Collider {
|
||||
@Override
|
||||
public void collide(GameObject o1, GameObject o2) {
|
||||
if(o1 instanceof Tank && o2 instanceof Tank) {
|
||||
Tank tank1 = (Tank) o1;
|
||||
Tank tank2 = (Tank) o2;
|
||||
if(tank1.getRectangle().intersects(tank2.getRectangle())) {
|
||||
tank1.goBack();
|
||||
tank2.goBack();
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.msb.model.abstracts;/**
|
||||
* @Author bingor
|
||||
* @Date 2022/10/11 9:23
|
||||
* @Description: com.msb.model.abstracts
|
||||
* @Version: 1.0
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
*@ClassName GameObject
|
||||
*@Description TODO
|
||||
*@Author bingor
|
||||
*@Date 2022/10/11 9:23
|
||||
*@Version 3.0
|
||||
*/
|
||||
public abstract class GameObject {
|
||||
protected int x,y;
|
||||
public abstract void paint(Graphics g);
|
||||
}
|
Loading…
Reference in new issue