边界检测

master
kn5886348135 3 years ago
parent f60ecaf688
commit 3131dbdfb5

@ -86,6 +86,24 @@ public class Tank {
if (this.group == Group.BAD && random.nextInt(100) > 95) {
randomDir();
}
boundsCheck();
}
private void boundsCheck() {
if (this.x < 0) {
this.x = 2;
}
if (this.y < 28) {
this.y = 28;
}
if (this.x > TankFrame.GAME_WIDTH - Tank.WIDTH) {
this.x = TankFrame.GAME_WIDTH - Tank.WIDTH;
}
if (this.y > TankFrame.GAME_HEIGHT - Tank.HEIGHT) {
this.y = TankFrame.GAME_HEIGHT - Tank.HEIGHT;
}
}
private void randomDir() {

Loading…
Cancel
Save