|
|
|
@ -1,5 +1,10 @@
|
|
|
|
|
package com.example.tankbattle;
|
|
|
|
|
|
|
|
|
|
import com.example.tankbattle.cor.BulletTankCollider;
|
|
|
|
|
import com.example.tankbattle.cor.Collider;
|
|
|
|
|
import com.example.tankbattle.cor.ColliderChain;
|
|
|
|
|
import com.example.tankbattle.cor.TankTankCollider;
|
|
|
|
|
|
|
|
|
|
import java.awt.Color;
|
|
|
|
|
import java.awt.Graphics;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
@ -11,16 +16,27 @@ public class GameModel {
|
|
|
|
|
List<Bullet> bullets = new ArrayList<>();
|
|
|
|
|
List<Tank> tanks = new ArrayList<>();
|
|
|
|
|
List<Explode> explodes = new ArrayList<>();
|
|
|
|
|
ColliderChain chain = new ColliderChain();
|
|
|
|
|
|
|
|
|
|
List<GameObject> objects = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
public GameModel() {
|
|
|
|
|
int initTankCount = Integer.valueOf(PropertyMgr.get("initTankCount"));
|
|
|
|
|
|
|
|
|
|
// 初始化敌方坦克
|
|
|
|
|
for (int i = 0; i < initTankCount; i++) {
|
|
|
|
|
tanks.add(new Tank(50 + i * 80, 200, Dir.DOWN, Group.BAD, this));
|
|
|
|
|
add(new Tank(50 + i * 80, 200, Dir.DOWN, Group.BAD, this));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void add(GameObject go) {
|
|
|
|
|
this.objects.add(go);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void remove(GameObject go) {
|
|
|
|
|
this.objects.remove(go);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
|
Color c = g.getColor();
|
|
|
|
|
g.setColor(Color.WHITE);
|
|
|
|
@ -30,22 +46,25 @@ public class GameModel {
|
|
|
|
|
g.setColor(c);
|
|
|
|
|
|
|
|
|
|
myTank.paint(g);
|
|
|
|
|
for (int i = 0; i < bullets.size(); i++) {
|
|
|
|
|
bullets.get(i).paint(g);
|
|
|
|
|
for (int i = 0; i < objects.size(); i++) {
|
|
|
|
|
objects.get(i).paint(g);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < tanks.size(); i++) {
|
|
|
|
|
tanks.get(i).paint(g);
|
|
|
|
|
// 互相碰撞逻辑
|
|
|
|
|
for (int i = 0; i < objects.size(); i++) {
|
|
|
|
|
for (int j = i + 1; j < objects.size(); j++) {
|
|
|
|
|
GameObject o1 = objects.get(i);
|
|
|
|
|
GameObject o2 = objects.get(j);
|
|
|
|
|
// collider.collide(o1, o2);
|
|
|
|
|
// collider2.collide(o1, o2);
|
|
|
|
|
chain.collide(o1, o2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < explodes.size(); i++) {
|
|
|
|
|
explodes.get(i).paint(g);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < bullets.size(); i++) {
|
|
|
|
|
for (int j = 0; j < tanks.size(); j++)
|
|
|
|
|
bullets.get(i).collideWith(tanks.get(j));
|
|
|
|
|
}
|
|
|
|
|
// for (int i = 0; i < bullets.size(); i++) {
|
|
|
|
|
// for (int j = 0; j < tanks.size(); j++)
|
|
|
|
|
// bullets.get(i).collideWith(tanks.get(j));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// for (Iterator<Bullet> it = bullets.iterator(); it.hasNext()) {
|
|
|
|
|
// Bullet b = it.next();
|
|
|
|
|