parent
0de31db767
commit
b563018987
@ -0,0 +1,31 @@
|
||||
package com.study.tank;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author xsj
|
||||
* @date 2022/10/28 15:37
|
||||
*/
|
||||
public class Wall extends GameObject {
|
||||
int width;
|
||||
int height;
|
||||
public GameModel gm;
|
||||
public Rectangle rectangle;
|
||||
|
||||
public Wall(int x, int y, int width, int height, GameModel gameModel) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.gm = gameModel;
|
||||
rectangle = new Rectangle(x, y, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
Color c = g.getColor();
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillRect(this.x, this.y, this.width, this.height);
|
||||
g.setColor(c);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.study.tank.cor;
|
||||
|
||||
import com.study.tank.*;
|
||||
|
||||
/**
|
||||
* @author xsj
|
||||
* @date 2022/10/28 15:56
|
||||
*/
|
||||
public class BulletWallCollider implements Collider {
|
||||
|
||||
@Override
|
||||
public boolean collider(GameObject o1, GameObject o2, GameModel gameModel) {
|
||||
if (o1 instanceof Bullet && o2 instanceof Wall) {
|
||||
Bullet bullet = (Bullet) o1;
|
||||
Wall w = (Wall) o2;
|
||||
if (bullet.rectangle.intersects(w.rectangle)) {
|
||||
bullet.die();
|
||||
return true;
|
||||
}
|
||||
} else if (o2 instanceof Bullet && o1 instanceof Wall) {
|
||||
collider(o2, o1, gameModel);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.study.tank.cor;
|
||||
|
||||
import com.study.tank.*;
|
||||
|
||||
/**
|
||||
* @author xsj
|
||||
* @date 2022/10/28 15:43
|
||||
*/
|
||||
public class WallTankCollider implements Collider {
|
||||
|
||||
@Override
|
||||
public boolean collider(GameObject o1, GameObject o2, GameModel gameModel) {
|
||||
if (o1 instanceof Tank && o2 instanceof Wall) {
|
||||
Tank tank = (Tank) o1;
|
||||
Wall w = (Wall) o2;
|
||||
if (tank.group == Group.GOOD) return false;
|
||||
if (tank.rectangle.intersects(w.rectangle)) {
|
||||
tank.stop();
|
||||
}
|
||||
} else if (o2 instanceof Tank && o1 instanceof Wall) {
|
||||
collider(o2, o1, gameModel);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue