⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enemy.java

📁 一款运行于手机的Java游戏神灯传奇源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    case A3: //A3
      if (runtime++ < scriptLength) {
        switch (scriptNum) {
        case 0:
          move( -getSpeedX(), getSpeedY());
          if (runtime + 1 >= scriptLength) {
            scriptNum = 1;
            runtime = 0;
          }
          break;
        case 1:
          move( -getSpeedX(), -getSpeedY());
          if (runtime + 1 >= scriptLength) {
            scriptNum = 0;
            runtime = 0;
          }
          break;
        }
      }
      break;

    case A4: //A4
      if (runtime++ < scriptLength) {
        switch (scriptNum) {
        case 0:
          if (super.delayShoot <= 0) {
            fire(pLocX, pLocY);
          }
          move(0, getSpeedY());
          break;
        case 1:
          if (super.delayShoot <= 0) {
            fire(pLocX, pLocY);
          }
          if (pLocY < 15) {
            move(0, getSpeedY());
          }
          break;
        case 2:
          move(getSpeedX(), 0);
          break;
        }
      } else {
        runtime = 0;
        scriptNum++;
        if (scriptNum == 1) {
          scriptLength = 20;
        }
        if (scriptNum > 2) {
          scriptNum = 2;
        }
      }
      break;

    case A5: //A5
      if (runtime++ < scriptLength) {
        switch (scriptNum) {
        case 0:
        default:
          if (super.delayShoot <= 0) {
            fire(pLocX, pLocY);
          }
          move(0, -getSpeedY());
          break;
        case 1:
          if (super.delayShoot <= 0) {
            fire(pLocX, pLocY);
          }
          break;
        case 2:
          move(getSpeedX(), 0);
          break;
        }
      } else {
        runtime = 0;
        scriptNum++;
        if (scriptNum == 1) {
          scriptLength = 20;
        }
        if (scriptNum > 2) {
          scriptNum = 2;
        }
      }
      break;

    case A6:
      if (runtime++ < scriptLength) {
        switch (scriptNum) {
        case 0:
          if (super.delayShoot <= 0) {
            fire(pLocX, pLocY);
          }
          move(0, getSpeedY());
          break;
        case 1:
          if (super.delayShoot <= 0) {
            fire(pLocX, pLocY);
          }
          break;
        case 2:
          if (pLocX < super.getLocationX()) {
            move( -getSpeedX() / 2, 0);
          } else {
            move(getSpeedX() / 2, 0);
          }
          if (pLocY < super.getLocationY()) {
            move(0, -getSpeedY() / 2);
          } else {
            move(0, getSpeedY() / 2);
          }
          break;
        }
      } else {
        runtime = 0;
        scriptNum++;
        if (scriptNum == 1) {
          scriptLength = 20;
        }
        if (scriptNum > 2) {
          scriptLength = 2;
          scriptNum = 2;
        }
      }
      break;

    case A7:
      if (runtime++ < scriptLength) {
        switch (scriptNum) {
        case 0:
        default:
          move( -getSpeedX(), 0);
          break;
        case 1:
          move(0, getSpeedY());
          if (runtime >= scriptLength) scriptNum = 2;
          break;
        case 2:
          move(0, -getSpeedY());
          if (runtime >= scriptLength) scriptNum = 1;
          break;
        case 3:
          if (runtime >= scriptLength) scriptNum = 1;
          break;
        }
      } else {
        runtime = 0;
        if (scriptNum == 0) scriptNum = 3;
        if (scriptNum == 1) {
          scriptLength = (canvasHeight - getLocationY() - super.getHeight()) /
                         getSpeedY();
        }
        if (scriptNum == 2) {
          scriptLength = getLocationY() / getSpeedY();
        }
        if (scriptNum == 3) {
          scriptLength = 20;
        }
      }
      break;

    case A8: //A8
      if (runtime++ < scriptLength) {
        switch (scriptNum) {
        case 0:
          if (super.delayShoot <= 0) {
            fire(pLocX, pLocY);
          }
          move(0, -getSpeedY());
          break;
        case 1:
          if (super.delayShoot <= 0) {
            fire(pLocX, pLocY);
          }
          break;
        case 2:
          if (pLocX < super.getLocationX()) {
            move( -getSpeedX() / 2, 0);
          } else {
            move(getSpeedX() / 2, 0);
          }
          if (pLocY < super.getLocationY()) {
            move(0, -getSpeedY() / 2);
          } else {
            move(0, getSpeedY() / 2);
          }
          break;
        }
      } else {
        runtime = 0;
        scriptNum++;
        if (scriptNum == 1) {
          scriptLength = 20;
        }
        if (scriptNum > 2) {
          scriptLength = 2;
          scriptNum = 2;
        }
      }
      break;

    case A9: //A9
      if (runtime++ < scriptLength) {
        if (pLocX <= super.getLocationX()) {
          if (pLocY <= super.getLocationY()) {
            move( -getSpeedX() / 2, -getSpeedY());
          } else {
            move( -getSpeedX() / 2, getSpeedY());
          }
        } else {
          move( -getSpeedX(), 0);
        }
      } else {
        runtime = 0;
        scriptLength = 2;
      }
      break;

    case A10: //A10
      if (runtime++ < scriptLength) {
        switch (scriptNum) {
        case 0:
        default:
          if (pLocX + 20 < super.getLocationX()) {
            if (pLocY <= super.getLocationY()) {
              move( -getSpeedX(), -getSpeedY());
            } else {
              move( -getSpeedX(), getSpeedY());
            }
          }
          break;
        case 1:

          //近战攻击
          if (super.delayShoot <= 0) {
            fire(pLocX, pLocY);
          }
          break;
        case 2:
          move( -getSpeedX(), 0);
          if (pLocY < super.getLocationY()) {
            move(0, -getSpeedY());
          } else {
            move(0, getSpeedY());
          }
          break;
        }
      } else {
        runtime = 0;
        scriptNum++;
        if (scriptNum == 1) {
          scriptLength = 90;
        }
        if (scriptNum > 2) {
          scriptLength = 2;
          scriptNum = 2;
        }
      }
      break;

    case A11: //A11
      if (runtime++ < scriptLength) {
        switch (scriptNum) {
        case 0:
        default:
          move( -getSpeedX(), 0);
          break;
        case 1:
          move(speedX, speedY);
          if (super.getLocationX() <= canvasWidth / 3 ||
              super.getLocationY() <= 0 ||
              super.getLocationX() + 50 >= canvasWidth ||
              super.getLocationY() + 50 > canvasHeight) {
            scriptLength = 0;
          }
          if (super.delayShoot <= 0) {
            fire(pLocX, pLocY);
            super.delayShoot = bDShoot[type] - Control.getStage() * 5;
          }
          break;
        }
      } else {
        runtime = 0;
        scriptNum++;
        if (scriptNum >= 1) {
          speedX = Tools.getRand( -3, 3);
          speedY = Tools.getRand( -3, 3);
          scriptLength = Tools.getRand(20, 100);
          scriptNum = 1;
        }
      }
      break;

    case A12: //A12
      if (runtime++ < scriptLength) {
        switch (scriptNum) {
        case 0:
        default:
          move( -getSpeedX(), 0);
          break;
        case 1:
          move(speedX, speedY);
          if (super.getLocationX() <= canvasWidth / 3 ||
              super.getLocationX() + 50 >= canvasWidth) {
            speedX = ( -1) * speedX;
          }
          if (super.getLocationY() <= 0 ||
              super.getLocationY() + 50 > canvasHeight) {
            speedY = ( -1) * speedY;
          }
          if (super.delayShoot <= 0) {
            fire(pLocX, pLocX);
            super.delayShoot = bDShoot[type] - Control.getStage() * 5;
          }
          break;
        case 2:
          move(speedX, 0);
          if (super.getLocationX() <= 0) {
            scriptLength = 0;
          }
          break;
        case 3:
          move(speedX, 0);
          if (runtime + 1 >= scriptLength) {
            scriptNum = 0;
          }
          break;
        }
      } else {
        runtime = 0;
        scriptNum++;
        if (scriptNum == 1) {
          speedX = Tools.getRand( -3, 3);
          speedY = Tools.getRand( -3, 3);
          scriptLength = 100;
        }
        if (scriptNum == 2) {
          speedX = -8;
          scriptLength = ( -1) * getLocationX() / speedX;
        }
        if (scriptNum == 3) {
          speedX = 5;
          //#if NOK_7210 || NOK_7260 || NOK_6101
          //# scriptLength = 15;
          //#else
          scriptLength = 20;
          //#endif
        }
      }
      break;

    }
  }

  /**
   * 敌人开火,每种敌人都有自己的开火规律和子弹轨迹
   *
   * @param pLocX
   * @param pLocY
   */
  public void fire(int pLocX, int pLocY) {
    if (isDead())
      return;
    super.delayShoot = super.bDelayShoot;
    switch (bulletType) {
    default:
      fireBullet(PlayScreen.getEnemyBulletPool(), 9 + super.gunId,
                 super.bHitPower, super.bSpeed, 0,
                 super.curLoc.getX() + super.curLoc.getWidth() / 2,
                 super.curLoc.getY() + super.curLoc.getHeight() / 2,
                 super.bWidth, super.bHeight);
      break;
    case 2: //B2
      fireBullet(PlayScreen.getEnemyBulletPool(), 9 + super.gunId,
                 super.bHitPower, super.bSpeed, 0,
                 super.curLoc.getX() + super.curLoc.getWidth() / 2,
                 super.curLoc.getY() + super.curLoc.getHeight() / 2,
                 super.bWidth, super.bHeight);
      break;
    case 10:
      break;
    }
  }

  /**
   * 获得该敌人所对应的分数
   *
   * @return
   */
  public int getScore() {
    return score;
  }

  public void render(Graphics g) {
    int posX = super.curLoc.getX();
    int posY = super.curLoc.getY();
    //int width = super.curLoc.getWidth();
    //int height = super.curLoc.getHeight();
    if (visible)
      switch (super.type) {
      default:
        if (!isDestroy()) { //画敌人
          enemyImageSet.draw(g, super.currentState, super.currentFrame, posX,
                             posY);
        } else {           //画爆炸
          explodeImageSet.draw(g, 0, super.curExpAniId, posX, posY);
        }
        break;
      case 26:
      case 27:
      case 28:
      case 29:
        if (!isDestroy()) { // 画Boss
          //enemyImageSet.draw(g, super.currentState,0, posX, posY);
          bossImageSet.draw(g, 0, 0, posX, posY);
          bossShieldFlash++;
          int flashTime = this.getEnergy();
          if (flashTime < 150) flashTime = 150;
          if (bossShieldFlash * 10 >= flashTime) {
            bossShieldFlash = 0;
            //闪烁
            //enemyImageSet.draw(g, super.currentState,1, posX, posY);
            bossImageSet.draw(g, 0, 1, posX, posY);
          }
        } else { //画Boss爆炸
          explodeImageSet.draw(g, 0, super.curExpAniId, posX, posY);
          bossIsDead = true;
        }
        break;
      }
    if (isDestroy()) {
      if (delayExpChange-- <= 0) {
        if (++super.curExpAniId >= explodeImageSet.getTotalFrames(0)) {
          dead();
        }
        delayExpChange = 0;
      }
    }
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -