📄 enemybullet.java
字号:
package role;
import java.awt.Image;
import assistant.ComputDirection;
import assistant.PublicVar;
import assistant.MoveImageChange;
/**
* 敌人子弹类
* @author Administrator
*
*/
public class EnemyBullet extends SportRole {
/**敌人闪电子弹图像*/
public static Image[][] ovalBulletImage;
/**敌人风子弹图像*/
public static Image[][] windBulletImage;
/**敌人火子弹图像*/
public static Image[][] fireBulletImage;
/**boss子弹图像*/
public static Image[][] bossBulletImage;
/**子弹类型*/
private int type;
/**BOSS子弹移动数组*/
private double[] dif;
/**当前子弹组图*/
private Image[] moveImage;
/**图像切换对象*/
private MoveImageChange imgChange =new MoveImageChange(3);
/**临时X、Y坐标*/
private double tempX,tempY;
/**
* 构造方法
* @param x X坐标
* @param y Y坐标
* @param width 角色宽度
* @param height 角色高度
* @param state 子弹飞行方向状态
* @param type 子弹类型
*/
public EnemyBullet(int x,int y,
int state,int type){
super(x,y,0,0,state);
this.speed = 8;
this.type = type;
this.tempX = x;
this.tempY = y;
this.setInitImage();//初始化
}
/**
* 设置图像切换数组初始值
*
*/
private void setInitImage(){
if(type == 0){//闪电
this.init(50, 50);
this.moveImage =new Image[]{ovalBulletImage[0][0],
ovalBulletImage[0][1],ovalBulletImage[0][2]};
}
else if(type == 1){//风
this.init(40, 55);
this.moveImage = new Image[]{windBulletImage[0][0],
windBulletImage[0][1],windBulletImage[0][2]};
}
else if(type == 2){//boss
this.init(36, 36);
this.moveImage = new Image[]{bossBulletImage[0][0],
bossBulletImage[0][1]};
dif=ComputDirection.getDif(this.x, this.y, this.speed);
}
else if(type == 3){//火
this.init(96, 93);
if(this.state == PublicVar.LEFT){//根据状态决定图像数组
this.moveImage = new Image[]{fireBulletImage[0][0],
fireBulletImage[0][1],fireBulletImage[0][2],fireBulletImage[0][3]};
}
else{
this.moveImage = new Image[]{fireBulletImage[1][0],
fireBulletImage[1][1],fireBulletImage[1][2],fireBulletImage[1][3]};
}
}
}
/**
* 初始化大小
* @param width 初始宽
* @param height 初始高
*/
private void init(int width,int height){
this.width=width;
this.height=height;
this.rect.width = this.width;
this.rect.height = this.height;
}
@Override
/**
* Method: move
* Description: 覆盖父类移动方法
*/
public void move() {
// TODO 自动生成方法存根
this.img = imgChange.imageChange(moveImage);
if(this.type != 2){
if(this.type != 3){//如果不是火的图像
switch(this.state){
case PublicVar.LEFT://向左
this.x-=this.speed;
break;
case PublicVar.RIGHT://向右
this.x+=this.speed;
break;
}
}
}
else{//BOSS子弹
tempX+=dif[0];
tempY+=dif[1];
this.x=(int)tempX;
this.y=(int)tempY;
}
this.removeThis();//超出屏幕自动移除
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -