📄 world.java
字号:
newHidingPlane.initCenterXY();
newHidingPlane.setAction((byte) 0);
newHidingPlane.setCurrentFrame(-1);
//screenActors[enemyNo] = newHidingPlane;
break;
case 5: // 无人机
Actor newAircraft = (Actor) plAircraftActorPool.getNextFree();
newAircraft.initOrbit(enemyFlyData, orbitType);
//screenActors[enemyNo] = newAircraft;
break;
case 6: // 船
Actor newShip = (Actor) shipActorPool.getNextFree();
newShip.initOrbit(enemyFlyData, orbitType);
//screenActors[enemyNo] = newShip;
break;
case 7: // 运输机
transport.setNotUsed(false);
transport.initOrbit(enemyFlyData, orbitType);
break;
}
}
public void doEnemy() {
changeEnemyState(helicopterActorPool);
changeEnemyState(scoutPlaneActorPool);
changeEnemyState(hidingPlaneActorPool);
if (battlePlane.isInvincible() == false) {
changeEnemyState(plAircraftActorPool);
}
changeEnemyState(largePlaneActorPool);
if(transport != null){
transport.changeMyState();
}
if(gameLevel == 2){
changeShipEnemyState(shipActorPool);
}
}
private void changeShipEnemyState(ObjectPool actorPool) {
if (actorPool != null) {
if (actorPool.getUseObjectNum() == 0) {
return;
}
Object[] actors = actorPool.getFreeActor();
for (int idx = 0; idx < actors.length; idx++) {
Actor actor = (Actor) actors[idx];
if (actor.isNotUsed() == true) {
continue;
}
if (isEnemyOutScreen(actor)) {
//System.out.println("2222222222222222");
actorPool.releasUsed(actor);
} else {
actor.changeMyState();
}
}
}
}
private void changeEnemyState(ObjectPool actorPool) {
if (actorPool != null) {
if (actorPool.getUseObjectNum() == 0) {
return;
}
Object[] actors = actorPool.getFreeActor();
for (int idx = 0; idx < actors.length; idx++) {
Actor actor = (Actor) actors[idx];
if (actor.isNotUsed() == true) {
continue;
}
// 如果向碰撞
if (battlePlane.getLiftNum() >= 0 && actor.isCollide(battlePlane, actor)) {
actor.setEnemyLife(actor.getEnemyLife()
- battlePlane.getBattle_life());
battlePlane.setBattle_life(battlePlane.getBattle_life() - 50);
if (battlePlane.getBattle_life() <= 0) {
Bullet bombEffect = (Bullet) bombEffectPool
.getNextFree();
bombEffect.setIPosX(battlePlane.getIPosX());
bombEffect.setIPosY(battlePlane.getIPosY());
BattlePlaneActor.PLANESTATE = GameConstant.STATE_GAME_DIE;
}
if (actor.getEnemyLife() <= 0) {
Bullet bombEffect = (Bullet) bombEffectPool
.getNextFree();
bombEffect.setIPosX(actor.getIPosX());
bombEffect.setIPosY(actor.getIPosY());
BattlePlaneActor.iScore += 50;
actorPool.releasUsed(actors[idx]);
}
} else {
if (isEnemyOutScreen(actor) || actor.getEnemyLife() <= 0) {
actorPool.releasUsed(actors[idx]);
} else {
actor.changeMyState();
}
}
}
}
}
private boolean isEnemyOutScreen(Actor actor) {
if ((actor.getIPosX() >> 8) < -GameConstant.iACTIVE_RECT
|| (actor.getIPosX() >> 8) > GameConstant.iSCREEN_WIDTH
+ GameConstant.iACTIVE_RECT
|| (actor.getIPosY() >> 8) < -GameConstant.iACTIVE_RECT
|| (actor.getIPosY() >> 8) > GameConstant.iSCREEN_HEIGHT
+ GameConstant.iACTIVE_RECT) {
return true;
}
return false;
}
private void doPlaneWeapon() {
changePlaneBullet(planeBulletPool);
for (byte weaponIdx = 0; weaponIdx < weaponType.length; weaponIdx++) {
switch (weaponType[weaponIdx]) {
case 1: // 大型导弹
changeBigMissleState(planeBigMisslePool);
break;
case 2: // 机枪
changeMachineGunState(planeMachineGunPool);
break;
case 3: // 直射火箭
changeRocketState(planeRocketPool);
break;
case 4: //加速
changeSpeedState();
break;
case 5: // 呼叫僚机
changeWingState(planeWingPool);
break;
case 6: // 大型炸弹
changeBombState(planeBombPool);
break;
}
}
}
private void whichDirection(Bullet bullet) {
int tan = 0;
int xSpeed = bullet.getXSpeed();
int ySpeed = bullet.getYSpeed();
if (xSpeed != 0) {
tan = (ySpeed << 8) / xSpeed;
}
if (ySpeed > 0 && (tan > 618 || tan <= -618)) {
// 子弹指向90度方向
if (bullet.getFumeInterval() % 6 == 0) {
newBullet(10, bullet.getIPosX() + (4 << 8), bullet.getIPosY()
+ (17 << 8), 0, -2 << 8);
}
bullet.setIWidth(3 << 8);
bullet.setIHeight(17 << 8);
} else if (ySpeed < 0 && (tan > 618 || tan <= -618)) {
// 子弹指向270度方向
if (bullet.getFumeInterval() % 6 == 0) {
newBullet(10, bullet.getIPosX() + (4 << 8), bullet.getIPosY(),
0, 2 << 8);
}
bullet.setIWidth(3 << 8);
bullet.setIHeight(17 << 8);
}
if (xSpeed > 0) {
if (tan > -106 && tan <= 106) {
// 子弹指向0度方向
if (bullet.getFumeInterval() % 6 == 0) {
newBullet(10, bullet.getIPosX(), bullet.getIPosY()
+ (2 << 8), -2 << 8, 0);
}
bullet.setIWidth(17 << 8);
bullet.setIHeight(3 << 8);
} else if (tan > 106 && tan <= 618) {
// 子弹指向45度方向
if (bullet.getFumeInterval() % 6 == 0) {
newBullet(10, bullet.getIPosX(), bullet.getIPosY()
+ (13 << 8), Tool.getXSpeedByAngel(45, -2), Tool
.getYSPeedByAngel(45, -2));
}
bullet.setIWidth(13 << 8);
bullet.setIHeight(13 << 8);
} else if (tan > -618 && tan <= -106) {
// 子弹指向315度方向
if (bullet.getFumeInterval() % 6 == 0) {
newBullet(10, bullet.getIPosX(), bullet.getIPosY(), Tool
.getXSpeedByAngel(315, -2), Tool.getYSPeedByAngel(
315, -2));
}
bullet.setIWidth(13 << 8);
bullet.setIHeight(13 << 8);
}
}else if (xSpeed < 0) {
if (tan > -618 && tan <= -106) {
// 子弹指向135度方向
if (bullet.getFumeInterval() % 6 == 0) {
newBullet(10, bullet.getIPosX() + (12 << 8), bullet
.getIPosY()
+ (18 << 8), Tool.getXSpeedByAngel(315, 2), Tool
.getYSPeedByAngel(315, 2));
}
bullet.setIWidth(13 << 8);
bullet.setIHeight(13 << 8);
} else if (tan > -106 && tan <= 106) {
// 子弹指向180度方向
if (bullet.getFumeInterval() % 6 == 0) {
newBullet(10, bullet.getIPosX() + (17 << 8), bullet
.getIPosY()
+ (2 << 8), 2 << 8, 0);
}
bullet.setIWidth(17 << 8);
bullet.setIHeight(3 << 8);
} else if (tan > 106 && tan <= 618) {
// 子弹指向225度方向
if (bullet.getFumeInterval() % 6 == 0) {
newBullet(10, bullet.getIPosX() + (13 << 8), bullet
.getIPosY()
+ (6 << 8), Tool.getXSpeedByAngel(45, 2), Tool
.getYSPeedByAngel(45, 2));
}
bullet.setIWidth(13 << 8);
bullet.setIHeight(13 << 8);
}
}else if(xSpeed ==0){
if(ySpeed > 0){
// 子弹指向90度方向
if (bullet.getFumeInterval() % 6 == 0) {
newBullet(10, bullet.getIPosX() + (4 << 8), bullet
.getIPosY()
+ (17 << 8), 0, -2 << 8);
}
bullet.setIWidth(3 << 8);
bullet.setIHeight(17 << 8);
}else if(ySpeed < 0){
// 子弹指向270度方向
if (bullet.getFumeInterval() % 6 == 0) {
newBullet(10, bullet.getIPosX() + (4 << 8), bullet
.getIPosY(), 0, 2 << 8);
}
bullet.setIWidth(3 << 8);
bullet.setIHeight(17 << 8);
}
}
bullet.setFumeInterval(bullet.getFumeInterval() + 1);
}
private void changePlaneBullet(ObjectPool objectPool) {
if (objectPool.getUseObjectNum() == 0) {
return;
}
Object[] bullets = objectPool.getFreeActor();
for (int idx = 0; idx < bullets.length; idx++) {
Bullet bullet = (Bullet) bullets[idx];
if (bullet.isNotUsed() == true) {
continue;
}
if(isCollideInEnemySpirit(helicopterActorPool, bullet)){
BattlePlaneActor.iScore += 10;
objectPool.releasUsed(bullet);
isCollide = false;
continue;
}
if(isCollideInEnemySpirit(hidingPlaneActorPool, bullet)){
BattlePlaneActor.iScore += 10;
//System.out.println("hidingPlane!!!!!!!!");
objectPool.releasUsed(bullet);
isCollide = false;
continue;
}
if(isCollideInEnemySpirit(scoutPlaneActorPool, bullet)){
BattlePlaneActor.iScore += 10;
//System.out.println("scoutPlane!!!!!!!!");
objectPool.releasUsed(bullet);
isCollide = false;
continue;
}
if(isCollideInEnemy(largePlaneActorPool, bullet)){
BattlePlaneActor.iScore += 10;
//System.out.println("largePlane!!!!!!!!");
objectPool.releasUsed(bullet);
isCollide = false;
continue;
}
if(isCollideInEnemy(plAircraftActorPool, bullet)){
BattlePlaneActor.iScore += 10;
//System.out.println("plAircraftActor!!!!!!!!");
objectPool.releasUsed(bullet);
isCollide = false;
continue;
}
if(isCollideInEnemy(shipActorPool,bullet)){
BattlePlaneActor.iScore += 10;
//System.out.println("shipActorPool!!!!!!!!");
objectPool.releasUsed(bullet);
isCollide = false;
continue;
}
if ((bullet.getIPosY() >> 8) < 0) {
//System.out.println("release!!!!!!!!!!!");
objectPool.releasUsed(bullets[idx]);
}else{
//System.out.println("222222222222222222222222222222222");
bullet.changeMyState();
}
}
}
private void changeBigMissleState(ObjectPool actorPool) {
if (actorPool.getUseObjectNum() == 0) {
return;
}
Object[] bullets = actorPool.getFreeActor();
for (int idx = 0; idx < bullets.length; idx++) {
Bullet bullet = (Bullet) bullets[idx];
if (bullet.isNotUsed() == true) {
continue;
}
if(bullet.getFumeInterval() % 6 == 0){
newBullet(10, bullet.getIPosX() + (5 << 8), bullet.getIPosY()
+ (35 << 8), 0, 3 << 8);
}
bullet.setFumeInterval(bullet.getFumeInterval() + 1);
// 它与敌人子弹碰撞
isCollideInEnemyBullet(helicopterBulletPool, bullet);
isCollideInEnemyBullet(largePlaneBulletPool, bullet);
isCollideInEnemyBullet(bossBulletPool, bullet);
if ((bullet.getIPosY() >> 8) < -4) {
actorPool.releasUsed(bullets[idx]);
} else {
bullet.changeMyState();
}
}
}
private void isCollideInEnemyBullet(ObjectPool objectPool, Bullet bullet) {
if (objectPool != null) {
Object[] bullets = objectPool.getFreeActor();
for (int idx = 0; idx < bullets.length; idx++) {
Bullet enemyBullet = (Bullet) bullets[idx];
if (enemyBullet.isNotUsed() == true) {
continue;
}
if (enemyBullet.isCollideInLeftTop(bullet, enemyBullet)) {
objectPool.releasUsed(enemyBullet);
}
}
}
}
private void changeMachineGunState(ObjectPool objectPool) {
if (objectPool.getUseObjectNum() == 0) {
return;
}
Object[] bullets = objectPool.getFreeActor();
for (int idx = 0; idx < bullets.length; idx++) {
Bullet bullet = (Bullet) bullets[idx];
if (bullet.isNotUsed() == true) {
continue;
}
if (isCollideInEnemySpirit(helicopterActorPool, bullet)) {
BattlePlaneActor.iScore += 10;
objectPool.releasUsed(bullet);
isCollide = false;
continue;
}
if(isCollideInEnemySpirit(hidingPlaneActorPool, bullet)){
BattlePlaneActor.iScore += 10;
//System.out.println("hidingPlane!!!!!!!!");
objectPool.releasUsed(bullet);
isCollide = false;
continue;
}
if(isCollideInEnemySpirit(scoutPlaneActorPool, bullet)){
BattlePlaneActor.iScore += 10;
//System.out.println("scoutPlane!!!!!!!!");
objectPool.releasUsed(bullet);
isCollide = false;
continue;
}
if(isCollideInEnemy(largePlaneActorPool, bullet)){
BattlePlaneActor.iScore += 10;
//System.out.println("largePlane!!!!!!!!");
objectPool.releasUsed(bullet);
isCollide = false;
continue;
}
if(isCollideInEnemy(plAircraftActorPool, bullet)){
BattlePlaneActor.iScore += 10;
//System.out.println("plAircraftActor!!!!!!!!");
objectPool.releasUsed(bullet);
isCollide = false;
continue;
}
if(isCollideInEnemy(shipActorPool,bullet)){
BattlePlaneActor.iScore += 10;
//System.out.println("shipActorPool!!!!!!!!");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -