Debug collisions

This commit is contained in:
Yohann D'ANELLO 2020-02-25 13:57:47 +01:00
parent 8c7522e1d3
commit 3ae852c8f0
2 changed files with 12 additions and 5 deletions

View File

@ -127,6 +127,7 @@ public class GameFrame extends JFrame {
} }
for (Mob mob : new ArrayList<>(mobs)) { for (Mob mob : new ArrayList<>(mobs)) {
getMap().getCase(mob.getX(), mob.getY()).setCollision(Collision.ANY);
mob.tick(this); mob.tick(this);
if (mob.getX() < 0 || mob.isDead()) { if (mob.getX() < 0 || mob.isDead()) {
mobs.remove(mob); mobs.remove(mob);
@ -141,6 +142,8 @@ public class GameFrame extends JFrame {
else else
reward += mob.getReward(); reward += mob.getReward();
} }
else
getMap().getCase(mob.getX(), mob.getY()).setCollision(Collision.PARTIAL);
} }
waveLabel.setText("Vague " + round); waveLabel.setText("Vague " + round);
@ -189,6 +192,14 @@ public class GameFrame extends JFrame {
g.drawImage(s.getImage(), SPRITE_SIZE * tower.getX(), SPRITE_SIZE * tower.getY(), SPRITE_SIZE, SPRITE_SIZE, null, null); g.drawImage(s.getImage(), SPRITE_SIZE * tower.getX(), SPRITE_SIZE * tower.getY(), SPRITE_SIZE, SPRITE_SIZE, null, null);
} }
for (RawCase c : getMap().getCases()) {
if (c.getCollision() == Collision.ANY)
continue;
g.setColor(new Color(0x10000000));
g.fillRect(SPRITE_SIZE * c.getPosX(), SPRITE_SIZE * c.getPosY(), SPRITE_SIZE, SPRITE_SIZE);
}
repaint(); repaint();
} }

View File

@ -74,7 +74,6 @@ public abstract class Mob {
else { else {
tickRemains = getSlowness(); tickRemains = getSlowness();
RawCase current = game.getMap().getCase(getX(), getY()); RawCase current = game.getMap().getCase(getX(), getY());
current.setCollision(Collision.ANY);
if (current.getPosX() == 0) { if (current.getPosX() == 0) {
move(-1, getY()); move(-1, getY());
@ -103,10 +102,7 @@ public abstract class Mob {
} }
} }
if (last == null) { if (last != null) {
current.setCollision(Collision.PARTIAL);
}
else {
while (pred.get(last) != current) while (pred.get(last) != current)
last = pred.get(last); last = pred.get(last);
move(last.getPosX(), last.getPosY()); move(last.getPosX(), last.getPosY());