📄 boss.java
字号:
/**
* <p>Title: Transpanzer</p>
* <p>Description:
* You cannot remove this copyright and notice.
* You cannot use this file any part without the express permission of the author.
* All Rights Reserved</p>
* @author Jjyo
* @email jjyo@163.com
* @version 1.0.0
*/
import java.util.Random;
public class Boss extends EnemySprite32{
Random random;
public int bossType; //BOSS 类型
public static final int MOTHER_BRAIN=1;
public static final int CRABULLUS=2;
public static final int PHOTOPHAGE=3;
public static final int FRED=4;
public static final int HARD_SHELL=5;
public static final int FROZEN_CRABULLUS=6;
public static final int SOLAR_ENHANCED_FRED=7;
public static final int UNDER_WORLD_LORD=8;
public static final int PLUTONIUM_BOSS=9;
private int attack;
private int dx;
private int dy;
public static int tmpx;
public static int tmpy;
public static boolean isLive; //Boss死了没有
private boolean isHit; //是否被击中
private boolean begin; //Boss开始移动
//构造 传进初始X,Y坐标Boss类型,生命值
public Boss(GameManage gm,int x,int y,int bossType,int pow){
super(gm);
this.x=x;
this.y=y;
this.pow=pow;
this.bossType=bossType;
isHidden=false;
dx=1;
dy=1;
random=new Random();
frameCnt=0;
isLive=true;
}
public void action(){
if(!isHidden){
attack=0;
//判断是否开始移动
if(begin){
//选择BOSS类型
switch(bossType){
case MOTHER_BRAIN:
frameSpeed=5;
//被击中显示帧列
if(isHit){
nextFrame(5,1);
if(++timeCnt>20){
timeCnt=0;
isHit=false;
}
//未被击中显示帧列
}else{
nextFrame(2,1);
if(++timeCnt%50==0)
frameCnt=0;
}
//被主角子弹击中
if(checkBulletDamage()){
isHit=true;
}
//移动到达地图边缘反方向移动
if(x<=0||x>Maps.w*16-96){
dx=-dx;
}
if(y<0||y>Maps.h*16-96){
dy=-dy;
}
if(pow<=0){
frameCnt=3;
TankSprite.HYPER_BEAM=true;
}
break;
}
//计时结束,开始移动
}else {
if(timeCnt++>100)
begin=true;
}
}
//Boss死亡后的动作
if(pow<=0){
isLive=false;
int tmpX=random.nextInt();
int tmpY=random.nextInt();
tmpX=Math.abs(tmpX%10)*TankGameCanvas.width/10;
tmpY=Math.abs(tmpY%10)*TankGameCanvas.height/10;
gm.creatBombEffect(tmpX, tmpY, 3);
//BOSS结束
if(++timeCnt>300){
isHidden=true;
gm.level(18); //转到C15地图
gm.lgr.tankSprite.initOffset(39,3); //计算地图偏移
gm.lgr.c15();
gm.creatBeam(39, 7, Beam.HYPER_BEAM);
}
//未死亡的动作 移动
}else{
if(begin){
x+=dx;
y+=dy;
pow-=attack;
}
}
tmpx=x;
tmpy=y;
}
//与主角子弹碰撞检测
protected boolean checkBulletDamage(){
rect1.dx = 8;
rect1.dy = 8;
rect2.dx = 48;
rect2.dy = 48;
for(int i=gm.lgr.tankBullet.length-1;i>=0;i--){
if(!gm.lgr.tankBullet[i].isHidden){
rect1.x=gm.lgr.tankBullet[i].x;
rect1.y=gm.lgr.tankBullet[i].y;
rect2.x=x+24;
rect2.y=y+10;
if(Rect.IntersectRect(rect1, rect2)){
if(gm.lgr.tankBullet[i].pow<18)
gm.lgr.tankBullet[i].isHidden=true;
attack=gm.lgr.tankBullet[i].pow;
return true;
}
}
}
return false;
}
//BOSS地图
public static final char bossData[][]={
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000},
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -