📄 enemyrole.java
字号:
package role;
import java.awt.Graphics;
import javax.swing.JFrame;
import assistant.PublicVar;
/**
* <p>
* Copyright (C),
* FileName: Captive
* Desctiptoin: 本类为敌人基类
* @author : lovo
*
* @version 1.00 2008/3/11
*/
public abstract class EnemyRole extends SportRole {
/**敌人生命值*/
protected int life = 1;
/**敌人产生子弹频率*/
protected int frequency;
/**计数器*/
protected int count;
/**子弹类型*/
protected int bulletType;
/**角色被击中时,飞行状态*/
protected int flyState;
/**是否记分*/
protected boolean isSetPonint = true;
/**
* 构造方法
* @param x: X坐标
* @param y Y坐标
* @param width 宽度
* @param height 高度
* @param state 敌人状态
* @param bulletType 子弹类型
* @param frequency 子弹频率
*/
protected EnemyRole(int x,int y,
int width,int height,int state,
int frequency,int bulletType){
super(x,y,width,height,state);
this.bulletType= bulletType;
this.frequency=frequency;
}
/**
* 产生子弹
*
*/
protected void createBullet(){
if(count>frequency){//当计数器大于子弹产生频率时,产生子弹
int tempy=0;
if(this.bulletType == 0){//子弹起始Y坐标
tempy=y+this.height-50;
}
else{
tempy=y+this.height-55;
}
PublicVar.roleList.add(new EnemyBullet(x+width/2,tempy,state,bulletType));
count=0;
}
count++;
}
/**
* 设置生命值
* @param flyState 飞行方向
*/
public void setLife(int flyState){
life--;
this.flyState=flyState;
}
/**
* 绘制自身图形
* @param g : 画笔
* @param jf : 窗体画布
*/
@Override
public void drawMyself(Graphics g,JFrame jf){
if(this.life == 0){//如果敌人生命值为零,则死亡
if(isSetPonint){
PublicVar.source+=this.getPoint();
isSetPonint = false;
}
this.y -= 7;
if(this.flyState == PublicVar.RIGHT ||
this.flyState == PublicVar.UP){//设置X坐标
this.x += 10;
}
else{
this.x -= 10;
}
this.removeThis();//移除敌人
}
else{//生命不为零,调用move方法
this.move();
}
this.setDraw(g, jf);//调用父类绘制方法
}
/**
* 设置分数
*
*/
public abstract int getPoint();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -