📄 secboss.java
字号:
import javax.microedition.lcdui.Graphics;
public class SecBoss extends Boss {
public SecBoss(){
//world = World.getInstance();
shipXSpeed = new int[24]; // 初始化疯狂攻击子弹的XY上的速度
shipYSpeed = new int[24];
initShipXYSpeed();
xCirlceSpeed = new int[24]; // 初始化疯狂攻击子弹的XY上的速度
yCirlceSpeed = new int[24];
initCrazyFightXYSpeed();
}
public void initData() {
// 初始化BOSS信息
bulletInterval = 2;
moveSpeed = 3;
initSpiritDate("/secBoss.bin", "/secBoss.png", "/secBossCom.bin");
setIPosX((GameConstant.iSCREEN_WIDTH >> 1) << 8);
setIPosY(-104 << 8);
smallCannon = new Cannon[2];
cirlceCannon = new Cannon("/cannon.png");
bossCannon = new Cannon();
trackRoketCannon = new Cannon();
for (int idx = 0; idx < 2; idx++) {
smallCannon[idx] = new Cannon("/cannon.png");
smallCannon[idx].setEnemyLife(60); // 没个小炮塔设置30血
smallCannon[idx].setIWidth(13 << 8);
smallCannon[idx].setIHeight(12 << 8);
}
// 设置小炮的位置
smallCannon[0].setIPosX(getIPosX() - (15 << 8));
smallCannon[0].setIPosY(getIPosY());
smallCannon[1].setIPosX(getIPosX());
smallCannon[1].setIPosY(getIPosY());
// 设置圆炮的位置
cirlceCannon.setIPosX(getIPosX() - (12 << 8));
cirlceCannon.setIPosY(getIPosY() + (23 << 8));
cirlceCannon.setIWidth(16 << 8);
cirlceCannon.setIHeight(15 << 8);
cirlceCannon.setEnemyLife(200);
// 设置Boss主炮的位置
bossCannon.setIPosX(getIPosX() - (12 << 8));
bossCannon.setIPosY(getIPosX() - (30 << 8));
bossCannon.setIWidth(24 << 8);
bossCannon.setIHeight(30 << 8);
bossCannon.setEnemyLife(300);
// 设置跟踪导弹的位置
trackRoketCannon.setIPosX(getIPosX() - (13 << 8));
trackRoketCannon.setIPosY(getIPosY() - (52 << 8));
BOSS_STATE = GameConstant.STATE_BOSS_APPEAR;
}
public void changeMyState() {
switch(BOSS_STATE){
case GameConstant.STATE_BOSS_APPEAR:
dealAutoMove();
break;
case GameConstant.STATE_BOSS_SEC_APPEAR:
case GameConstant.STATE_BOSS_CRAZY_FIGHT:
dealAutoMove();
crazyFight();
isCollide();
break;
case GameConstant.STATE_BOSS_DIE:
//if(bulletInterval == 60){
if ((planeActor.getIPosY() >> 8) <= 0) {
world.cleanAllObecjt();
gameScreen = GameScreen.getInstance();
gameScreen.StopSound();
world.setGameLevel((byte)3);
world.setBossAppear(false);
GameScreen.gameState = GameConstant.STATE_GAME_LOAD; //加载
//GameScreen.gameState = GameConstant.STATE_GAME_TASKCOMPLETE;
break;
}
bomb(getIPosX(), getIPosY(), 0, 0);
//bulletInterval++;
break;
}
}
public void dealAutoMove() {
int posY = getIPosY() + (moveSpeed << 8);
switch (BOSS_STATE) {
case GameConstant.STATE_BOSS_APPEAR:
if ((getIPosY() >> 8) >= 83) {
BOSS_STATE = GameConstant.STATE_BOSS_SEC_APPEAR;
} else {
setIPosY(posY);
changeWeaponState(moveSpeed << 8);
}
break;
case GameConstant.STATE_BOSS_SEC_APPEAR:
case GameConstant.STATE_BOSS_CRAZY_FIGHT:
setIPosX(getIPosX() + shipXSpeed[moveIdx]);
setIPosY(getIPosY() + shipYSpeed[moveIdx]);
changeWeaponState(moveSpeed << 8);
moveIdx++;
if (moveIdx == 24) {
moveIdx = 0;
}
break;
}
}
public void changeWeaponState(int moveSpeed) {
switch (BOSS_STATE) {
case GameConstant.STATE_BOSS_APPEAR:
// 2个小炮移动
for (int idx = 0; idx < 2; idx++) {
smallCannon[idx].setIPosY(smallCannon[idx].getIPosY()
+ moveSpeed);
}
//圆炮移动
cirlceCannon.setIPosY(cirlceCannon.getIPosY() + moveSpeed);
bossCannon.setIPosY(bossCannon.getIPosY() + moveSpeed);
trackRoketCannon.setIPosY(trackRoketCannon.getIPosY() + moveSpeed);
break;
case GameConstant.STATE_BOSS_SEC_APPEAR:
case GameConstant.STATE_BOSS_CRAZY_FIGHT:
// 2个小炮移动
smallCannon[0].setIPosX(getIPosX() - (15 << 8));
smallCannon[0].setIPosY(getIPosY());
smallCannon[1].setIPosX(getIPosX());
smallCannon[1].setIPosY(getIPosY());
// 圆炮移动
cirlceCannon.setIPosX(getIPosX() - (12 << 8));
cirlceCannon.setIPosY(getIPosY() + (23 << 8));
// Boss炮移动
bossCannon.setIPosX(getIPosX() - (12 << 8));
bossCannon.setIPosY(getIPosY() - (30 << 8));
//
trackRoketCannon.setIPosX(getIPosX() - (8 << 8));
trackRoketCannon.setIPosY(getIPosY() - (49 << 8));
break;
}
}
public void clean() {
for (int i = 0; i < 2; i++) {
smallCannon[i] = null;
}
cirlceCannon = null;
bossCannon = null;
trackRoketCannon = null;
shipXSpeed = null;
shipYSpeed = null;
xCirlceSpeed = null;
yCirlceSpeed = null;
missileBullet = null;
cleanSpirit();
}
public void draw(Graphics graphics) {
super.draw(graphics);
drawWeapon(graphics);
}
public void drawWeapon(Graphics graphics) {
if (bossCannon.getEnemyLife() > 0) { // 如果BOSS主体有血
for (int idx = 0; idx < smallCannon.length; idx++) {
if (smallCannon[idx].getEnemyLife() > 0) { // 如果小炮还有血
smallCannon[idx].draw(graphics, 56, 0, 13, 28,
GameConstant.TOPLEFT);
}
}
if (cirlceCannon.getEnemyLife() > 0) { //如果圆炮还有血
cirlceCannon.draw(graphics, 69, 0, 22, 20, GameConstant.TOPLEFT);
}
}
}
private void crazyFight() {
if (bossCannon.getEnemyLife() > 0) {
for (int i = 0; i < 2; i++) { // 2个小炮子弹发射
if (smallCannon[i].getEnemyLife() > 0) {
if (bulletTimes % 30 >= 0 && bulletTimes % 30 <= 5) {
if (bulletInterval % 2 == 0) {
world.newBullet(3,
smallCannon[i].getIPosX() + (7 << 8),
smallCannon[i].getIPosY() + (24 << 8), 0,
-5 << 8);
}
if (bulletInterval == 6) {
bulletInterval = 0;
}
}
}
}
//设置圆炮发射子弹
if (bulletTimes % 70 >= 0 && bulletTimes % 70 <= 4) {
if (cirlceCannon.getEnemyLife() > 0) {
for (int i = 0; i < 4; i++) {
world.newBullet(4, cirlceCannon.getIPosX() + (5 << 8),
cirlceCannon.getIPosY() + (5 << 8),
xCirlceSpeed[i * 5 + (bulletTimes % 70)],
yCirlceSpeed[i * 5 + (bulletTimes % 70)]);
}
}
}
//设置跟踪导弹发射
if (missileInterval % 100 == 0) {
missileBullet = world.newBullet(9, trackRoketCannon.getIPosX(),
trackRoketCannon.getIPosY(), 0, 2 << 8);
}
if (bulletTimes == 75) {
bulletTimes = 29;
}
if(missileInterval == 100){
missileInterval = 0;
}
bulletTimes++;
bulletInterval++;
missileInterval++;
}else{
BOSS_STATE = GameConstant.STATE_BOSS_DIE;
planeActor.setInvincible(true);
BattlePlaneActor.PLANESTATE = GameConstant.STATE_GAME_WIN;
bulletInterval = 0;
}
}
public void isCollideWithBoss(Bullet bullet) {
if (cirlceCannon.getEnemyLife() > 0) {
if (isCollideInLeftTop(bullet, cirlceCannon)) {
cirlceCannon.setEnemyLife(cirlceCannon.getEnemyLife()
- bullet.getDamage());
world.newBullet(1, bullet.getIPosX(), bullet.getIPosY()
- (20 << 8), 0, -4 << 8);
isCollide = true;
if (cirlceCannon.getEnemyLife() <= 0) {
BattlePlaneActor.iScore += 200;
}
}
}
for (int i = 0; i < 2; i++) {
if (smallCannon[i].getEnemyLife() > 0) {
if (isCollideInLeftTop(bullet, smallCannon[i])) {
smallCannon[i].setEnemyLife(smallCannon[i].getEnemyLife()
- bullet.getDamage());
world.newBullet(1, bullet.getIPosX(), bullet.getIPosY()
- (20 << 8), 0, -4 << 8);
// PlaneBulletPool.releasUsed(bullets[idx]);
isCollide = true;
if (smallCannon[i].getEnemyLife() <= 0) {
BattlePlaneActor.iScore += 50;
}
}
}
}
if (isCollideInLeftTop(bullet, bossCannon)) {
bossCannon.setEnemyLife(bossCannon.getEnemyLife()
- bullet.getDamage());
world.newBullet(1, bullet.getIPosX(),
bullet.getIPosY() - (20 << 8), 0, -4 << 8);
isCollide = true;
if (bossCannon.getEnemyLife() <= 0) {
BattlePlaneActor.iScore += 2000;
}
// PlaneBulletPool.releasUsed(bullets[idx]);
}
}
public void isCollideWithBoss() {
if (cirlceCannon.getEnemyLife() > 0) {
cirlceCannon.setEnemyLife(cirlceCannon.getEnemyLife() - 4);
if (cirlceCannon.getEnemyLife() <= 0) {
BattlePlaneActor.iScore += 200;
}
}
for (int i = 0; i < 2; i++) {
if (smallCannon[i].getEnemyLife() > 0) {
smallCannon[i].setEnemyLife(smallCannon[i].getEnemyLife() - 4);
if (smallCannon[i].getEnemyLife() <= 0) {
BattlePlaneActor.iScore += 50;
}
}
}
bossCannon.setEnemyLife(bossCannon.getEnemyLife() - 4);
if (bossCannon.getEnemyLife() <= 0) {
BattlePlaneActor.iScore += 2000;
}
}
private void initShipXYSpeed(){
// 从90度到450度的角 每15度一个角度
for (int idx = 0; idx < 24; idx++) {
shipXSpeed[idx] = Tool.getXSpeedByAngel(90 + 15 * idx, 1);
shipYSpeed[idx] = Tool.getYSPeedByAngel(90 + 15 * idx, 1);
}
}
public void initCrazyFightXYSpeed(){
// 从90度到450度的角 每18度一个角度
for (int idx = 0; idx < 20; idx++) {
xCirlceSpeed[idx] = Tool.getXSpeedByAngel(90 + 18 * idx, 6);
yCirlceSpeed[idx] = Tool.getYSPeedByAngel(90 + 18 * idx, 6);
}
}
private Cannon[] smallCannon; // 小炮
private Cannon cirlceCannon; // 圆炮
private Cannon bossCannon; //Boss炮
private Cannon trackRoketCannon; //跟踪导弹
private int [] shipXSpeed; //船X轴移动的速度
private int [] shipYSpeed; //船Y轴移动的速度
private byte moveIdx = 0; //船移动角度下标
private int[] xCirlceSpeed; //画圆子弹X轴移动的速度
private int[] yCirlceSpeed; //画圆子弹Y轴移动的速度
private byte bulletTimes = 30; //子弹发射记数
private byte missileInterval = 0; //跟踪时间
private Bullet missileBullet = null;
//private World world;
private GameScreen gameScreen;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -