📄 skull.java
字号:
package role;
import java.awt.Image;
import assistant.PublicVar;
import assistant.MoveImageChange;
/**
* 骷髅类
* @author Administrator
*
*/
public class Skull extends EnemyRole {
/**骷髅图像数组*/
public static Image[][] skullImage;
/**图像切换对象*/
private MoveImageChange moveChange = new MoveImageChange(3);
/**向左图像数组*/
private Image[] leftImage= new Image[]{skullImage[0][0],
skullImage[0][1],skullImage[0][2]};
/**向右图像数组*/
private Image[] rightImage= new Image[]{skullImage[1][0],
skullImage[1][1],skullImage[1][2]};
/**移动计数器*/
private int moveCount;
/**火停留时间计数器*/
private int fireCount;
/**开火计数器*/
private int count;
/**敌人子弹对象*/
public EnemyBullet bullet;
/**是否开火*/
private boolean isFire;
/**骷髅向左还是向右移*/
private boolean isRight;
/**
* 构造方法
* @param x X坐标
* @param y Y坐标
* @param state 向左向右移动状态
*/
public Skull(int x, int y,int state) {
super(x, y, 38, 50, state, 100, 3);
this.speed = 6;
/*设置起始移动方向*/
if(state == PublicVar.RIGHT){
isRight = true;
}
}
@Override
/**
* 重写父类move()方法
*/
public void move() {
// TODO 自动生成方法存根
if(isFire == false){//移动
this.setMove();
this.setFire();
}
else{//开火状态
this.setFireTime();
}
}
/**
* 设置骷髅移动
*
*/
private void setMove(){
if(isRight){//向右
this.img = moveChange.imageChange(rightImage);
x += this.speed;
this.state = PublicVar.RIGHT;
}
else{//向左
this.img = moveChange.imageChange(leftImage);
x -= this.speed;
this.state = PublicVar.LEFT;
}
/*移动计数器大于60,则反向行走*/
if(moveCount >= 60){
moveCount = 0;
isRight = !isRight;
}
moveCount++;
}
/**
* 设置开火
*
*/
private void setFire(){
count++;
if(count >= 40){//开火间隔时间
int tempx = 0;
/*根据状态决定火的起始位置*/
if(this.state == PublicVar.RIGHT){
tempx = x+this.width;
}
else{
tempx = x - 96;
}
/*产生子弹对象*/
bullet = new EnemyBullet(tempx,y-73,state,bulletType);
PublicVar.roleList.add(bullet);
count = 0;
isFire = true;
}
}
/**
* 设置火停留时间
*
*/
private void setFireTime(){
fireCount++;
if(fireCount >= 30){//计数器大于30,则移除火对象
isFire = false;
fireCount = 0;
PublicVar.roleList.remove(bullet);
}
}
@Override
public int getPoint() {
// TODO 自动生成方法存根
if(this.bullet!=null){
PublicVar.roleList.remove(this.bullet);
}
return 1500;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -