Compare commits

..

No commits in common. '27b0107b7a7d106f7d7d42052e813133b7c04182' and 'f60ecaf688c1534ae06b6e792f1a3e5991b1fd6e' have entirely different histories.

@ -7,9 +7,6 @@ public class Bullet {
private static final int SPEED = 6;
public static int WIDTH = ResourceMgr.bulletD.getWidth();
public static int HEIGHT = ResourceMgr.bulletD.getHeight();
private Rectangle rect = new Rectangle();
private int x, y;
private Dir dir;
@ -23,11 +20,6 @@ public class Bullet {
this.dir = dir;
this.group = group;
this.tf = tf;
rect.x = this.x;
rect.y = this.y;
rect.width = WIDTH;
rect.height = HEIGHT;
}
public Group getGroup() {
@ -81,15 +73,14 @@ public class Bullet {
break;
}
rect.x = this.x;
rect.y = this.y;
if (x < 0 || y < 0 || x > TankFrame.GAME_WIDTH || y > TankFrame.GAME_HEIGHT) living = false;
}
public void collideWith(Tank tank){
if (this.group == tank.getGroup()) return;
if (this.rect.intersects(tank.rect)) {
Rectangle rect1 = new Rectangle(this.x, this.y, WIDTH, HEIGHT);
Rectangle rect2 = new Rectangle(tank.getX(), tank.getY(), Tank.WIDTH, Tank.HEIGHT);
if (rect1.intersects(rect2)) {
tank.die();
this.die();
int eX = tank.getX() + Tank.WIDTH / 2 - Explode.WIDTH / 2;

@ -1,6 +1,6 @@
package com.example.tankbattle;
import java.awt.*;
import java.awt.Graphics;
import java.util.Random;
public class Tank {
@ -9,8 +9,6 @@ public class Tank {
public static int WIDTH = ResourceMgr.GoodTankD.getWidth();
public static int HEIGHT = ResourceMgr.GoodTankD.getHeight();
Rectangle rect = new Rectangle();
private Random random = new Random();
private int x,y;
@ -32,11 +30,6 @@ public class Tank {
this.dir = dir;
this.group = group;
this.tf = tf;
rect.x = this.x;
rect.y = this.y;
rect.width = WIDTH;
rect.height = HEIGHT;
}
public void fire(){
@ -88,31 +81,11 @@ public class Tank {
break;
}
rect.x = this.x;
rect.y = this.y;
if (this.group == Group.BAD && random.nextInt(100) > 95) this.fire();
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