public class Tank extends FaGame{
//尺寸,方向,速度
private int width = 40;
private int height = 50;
private int speed = 3;
private Direction direction = Direction.UP;
//四个方向图片
private String upimg;
private String downimg;
private String leftimg;
private String rightimg;
//定义子弹冷却状态和间隔时间
private boolean attackcooldown = true;
private attackcooltime = 1000;
//坦克类的构建函数
public Tank (全部args){
super(img,x,y,Game);
this.args = args
}
//上下左右四个方法
public void upward(){
y -=speed;
setimg(upimg);
direction = Direction.UP;
}
//创建setimg方法
public void setimg(String img){
this.img = Toolkit.getDefaultToolkit().getImage(img);
}
//继承线程
class Attackcd extends Thread{
public void run(){
attackcooldown = false;
try{
Thread.sleep(attackcooltime);
}catch(Exception e){
e.printStackTrace();
}
attackcooldown = true;
this.stop();
}
}
//发射方法
public void attack(){
//增加状态判断
if(attackcooldown){
Point p = this.getHeadPoint();
Bullet bullet = new Bullet("子弹图片地址",p.x,p.y,this.youxi,this.direction);
//把子弹加入游戏类的子弹集合
this.Game.bulletlist.add(bullet);
new Attackcd().start();
}
}
//定义子弹原始坐标的方法
public Point getHeadPoint(){
switch(direction){
case UP:
return new Point (x+width/2,y)
}
}
//Override 分别重写父类FaGame两个方法
}
坦克类设置发射状态和间隔
最新推荐文章于 2025-05-01 15:34:21 发布