|
|
@ -1,10 +1,28 @@
|
|
|
|
package com.example.tankbattle;
|
|
|
|
package com.example.tankbattle;
|
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Graphics;
|
|
|
|
import java.awt.Graphics;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
|
|
public class Tank {
|
|
|
|
public class Tank {
|
|
|
|
|
|
|
|
private static final int SPEED = 5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static int WIDTH = ResourceMgr.tankD.getWidth();
|
|
|
|
|
|
|
|
public static int HEIGHT = ResourceMgr.tankD.getHeight();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Random random = new Random();
|
|
|
|
|
|
|
|
|
|
|
|
private int x,y;
|
|
|
|
private int x,y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Dir dir = Dir.DOWN;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean moving = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TankFrame tf = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean living = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Group group = Group.BAD;
|
|
|
|
|
|
|
|
|
|
|
|
public int getX() {
|
|
|
|
public int getX() {
|
|
|
|
return x;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -21,17 +39,13 @@ public class Tank {
|
|
|
|
this.y = y;
|
|
|
|
this.y = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Dir dir = Dir.DOWN;
|
|
|
|
public Group getGroup() {
|
|
|
|
private static final int SPEED = 5;
|
|
|
|
return group;
|
|
|
|
|
|
|
|
}
|
|
|
|
public static int WIDTH = ResourceMgr.tankD.getWidth();
|
|
|
|
|
|
|
|
public static int HEIGHT = ResourceMgr.tankD.getHeight();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean moving = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TankFrame tf = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean living = true;
|
|
|
|
public void setGroup(Group group) {
|
|
|
|
|
|
|
|
this.group = group;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isMoving() {
|
|
|
|
public boolean isMoving() {
|
|
|
|
return moving;
|
|
|
|
return moving;
|
|
|
@ -50,13 +64,13 @@ public class Tank {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Tank(int x, int y, Dir dir, Group group, TankFrame tf) {
|
|
|
|
public Tank(int x, int y, Dir dir, TankFrame tf) {
|
|
|
|
|
|
|
|
super();
|
|
|
|
super();
|
|
|
|
this.x = x;
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.y = y;
|
|
|
|
this.dir = dir;
|
|
|
|
this.dir = dir;
|
|
|
|
this.tf = tf;
|
|
|
|
this.tf = tf;
|
|
|
|
|
|
|
|
this.group = group;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
public void paint(Graphics g) {
|
|
|
@ -98,12 +112,14 @@ public class Tank {
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (random.nextInt(10) > 5) this.fire();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void fire(){
|
|
|
|
public void fire(){
|
|
|
|
int bX = this.x + Tank.WIDTH / 2 - Bullet.WIDTH / 2;
|
|
|
|
int bX = this.x + Tank.WIDTH / 2 - Bullet.WIDTH / 2;
|
|
|
|
int bY = this.y + Tank.HEIGHT / 2 - Bullet.HEIGHT / 2;
|
|
|
|
int bY = this.y + Tank.HEIGHT / 2 - Bullet.HEIGHT / 2;
|
|
|
|
tf.bullets.add(new Bullet(bX, bY, this.dir, this.tf));
|
|
|
|
tf.bullets.add(new Bullet(bX, bY, this.dir, this.group, this.tf));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void die() {
|
|
|
|
public void die() {
|
|
|
|