坦克大战(一期)-将子弹调整到坦克的中心位置打出

Network
bingor_yhj 3 years ago
parent 9f0365da6c
commit c7a49ad7ab

@ -8,12 +8,12 @@ import java.awt.*;
* @Description:
* @Version: 1.0
*/
public class Bullet extends Frame {
public class Bullet {
private int x, y;
private DirEnum dir;
public static final int WIDTH = 20;
public static final int HEIGHT = 20;
public static final int WIDTH = ResourcesMgr.bulletD.getWidth();
public static final int HEIGHT = ResourcesMgr.bulletD.getHeight();
public static final int SPEED = 5;
private boolean live = true;
private TankFrame tankFrame;

@ -16,6 +16,8 @@ public class Tank {
private boolean move = false;
//为了解决能够在坦克中发射子弹,将创建的子弹通过坦克发射出来,那么需要在坦克类中持有游戏窗口的引用
private TankFrame tankFrame;
public static final int WIDTH = ResourcesMgr.tankD.getWidth();
public static final int HEIGHT = ResourcesMgr.tankD.getHeight();
public Tank(int x, int y, DirEnum dir, TankFrame tankFrame) {
this.x = x;
@ -62,6 +64,8 @@ public class Tank {
}
public void fire() {
tankFrame.bullets.add(new Bullet(this.x, this.y, this.dir, tankFrame));
int bX = this.x + WIDTH/2 - Bullet.WIDTH/2;
int bY = this.y+HEIGHT/2-Bullet.HEIGHT/2;
tankFrame.bullets.add(new Bullet(bX, bY, this.dir, tankFrame));
}
}

Loading…
Cancel
Save