📄 flymonkey.java
字号:
package role;
import java.awt.Image;
import assistant.ComputDirection;
import assistant.PublicVar;
import assistant.MoveImageChange;
/**
* 飞猴类
* @author Administrator
*
*/
public class FlyMonkey extends EnemyRole {
/**飞猴图像数组*/
public static Image[][] flyMonkeyImage;
/**图像切换对象*/
private MoveImageChange moveImage = new MoveImageChange(4);
/**向左图像数组*/
private Image[] leftImage= new Image[]{flyMonkeyImage[0][0],
flyMonkeyImage[0][1],flyMonkeyImage[0][2]};
/**向右图像数组*/
private Image[] rightImage= new Image[]{flyMonkeyImage[1][0],
flyMonkeyImage[1][1],flyMonkeyImage[1][2]};
/**是否向右*/
private boolean isRight;
/**飞猴移动数组*/
private double[] dif;
/**
* 构造方法
* @param x X坐标
* @param y Y坐标
* @param state 状态
*/
public FlyMonkey(int x, int y, int state) {
super(x, y, 44, 52, state, 0, -1);
if(state == PublicVar.RIGHT){//初始化飞行方向
isRight = true;
}
this.speed = 8;
/*计算初始飞行方向*/
dif=ComputDirection.getDif(this.x, this.y, this.speed);
}
@Override
/**
* 重写父类move方法
*/
public void move() {
this.setImage();
if(PublicVar.isChipDie == false){//松鼠未死
/*移动*/
this.x+=dif[0];
this.y+=dif[1];
this.rest();//状态复位
}
else{//松鼠死亡向上飞
this.y-=5;
if(this.y <= 50){
this.y = 50;
}
}
}
/**
* 复位方向
*
*/
private void rest(){
if(this.x>600 || this.x<50 || this.y<50 ||this.y>500){
/*重新计算方向*/
dif=ComputDirection.getDif(this.x, this.y, this.speed);
if(dif[0]>0){//复位状态
isRight = true;
}
else{
isRight = false;
}
}
}
/**
* 设置图片
*
*/
private void setImage(){
if(isRight){//向右
this.img = moveImage.imageChange(rightImage);
}
else{//向左
this.img = moveImage.imageChange(leftImage);
}
}
@Override
public int getPoint() {
// TODO 自动生成方法存根
return 4000;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -