Java游戏开发之坦克大战代码(8)

class Hero extends Tank{
 //
 public Hero(int x , int y, int direct
   , int type,int speed, boolean isLive){
  super(x, y, direct, type,speed , isLive);
 }
 Vector<shot> ss = new Vector<shot>();
 shot s = null;
 //开火
 public void shotEnemy(){
  //System.out.println("shotEnemy");
  if(Recoder.getMyLife() > 0){//生命没有了,不能发子弹
   
   switch (this.direct) {
   case 0://向上
    s = new shot(x + 10 , y ,0);
    ss.add(s);
    break;
   case 3://右
    s = new shot(x + 30 , y + 10 , 3);
    ss.add(s);
    break;
   case 1://向下
    s = new shot(x + 10 , y + 30 , 1);
    ss.add(s);
    break;
   case 2://向左
    s = new shot(x  , y + 10 , 2);
    ss.add(s);
    break;
   default:
    break;
   }
   Thread t = new Thread(s);
   t.start();
   
  }
 }
 
 //向上,下,左,右
 public void MoveUp(){
  if(y - this.speed > 0){
  y -= speed;
  }
 } 
 public void MoveDown(){
  if(y + this.speed < 300 -30){
  y += speed;
  }
 }
 public void MoveLeft(){
  if(x - this.speed > 0){
  x -= speed;
  }
 }
 public void MoveRight(){
  if(x + this.speed < 400 -30){
  x += speed;
  }
 }
}
class shot implements Runnable{
 int x ,y;
 int direct;
 int speed = 20; //子弹速度
 boolean isShot = true;
 boolean isLive = true;//子弹是否活着
 public shot(int x,int y, int direct){
  this.x = x;
  this.y = y;
  this.direct = direct;
 
 
 }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/34fa2e4cb3df2ac646cd1064dd4540ad.html