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

📄 game.java

📁 j2me简单实例,j2me教程加源码,希望大家喜欢
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                  CREDITS_BOARD_Y, Graphics.VCENTER | Graphics.HCENTER);
      /* paint credits */
      int start_y = (CREDITS[m_Position].length * CREDITS_TEXT_GAP) / 2 -
          (CREDITS_TEXT_GAP / 2);
      for (int i = 0; i < CREDITS[m_Position].length; i++) {
        g.setColor(COLOR_ACTIVE);
        ToolBox.drawOutlinedText(g, m_CreditsFont, CREDITS[m_Position][i],
                                 CREDITS_TEXT_X,
                                 CREDITS_TEXT_Y - start_y +
                                 (i * CREDITS_TEXT_GAP));
      } // ~for
      if (System.currentTimeMillis() - m_LastTime > 2000) {
        m_Position++;
        if (m_Position > CREDITS.length - 1) {
          m_Position = 0;
        }
        m_LastTime = System.currentTimeMillis();
      } // ~if
    }
    if (bSelectKeyDown && bGameMenuAnimationOver()) {
      changeState(STATE_MAINMENU);
    }
  }

  /**
   * 画准备界面
   * @param g Graphics
   */
  protected void drawReady(Graphics g) {
    g.setClip(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    g.setColor(0);
    g.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    m_ReadyAnimation.setNextFrame();
    m_ReadyAnimation.paint(g, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2,
                           PieceSprite.TRANS_NONE);
    if (bGameReadyAnimationOver()) {
      //#if SAMSUNG_D508
//#             drawMenuWord(58, 62, g);
      //#else
      drawMenuWord(58, 57, g);
      //#endif
    }
  }

  public void drawMenuWord(int coorX, int coorY, Graphics g) {
    //#if MOTO_E680
//#         g.setFont(m_HelpFont);
//#         g.setColor(255, 255, 0);
//#         g.drawString(EVERYSCREENNAME[currentScreen],
//#                 (SCREEN_WIDTH - SCREEN_W_K700) / 2 + coorX,
//#                 (SCREEN_HEIGHT - SCREEN_H_K700) / 2 +coorY, 20);
//#         g.drawString("挑战者:",
//#                 (SCREEN_WIDTH - SCREEN_W_K700) / 2 + coorX,
//#                 (SCREEN_HEIGHT - SCREEN_H_K700) / 2 + coorY + (FONT_HEIGHT - 1), 20);
//#         try {
//#             g.drawImage(thisImgRoleHead,
//#                     (SCREEN_WIDTH - SCREEN_W_K700) / 2 + coorX + 15,
//#                     (SCREEN_HEIGHT - SCREEN_H_K700) / 2 + coorY + 2 * (FONT_HEIGHT - 1),
//#                     20);
//#         } catch (Exception e) {
//#             System.out.println("This is drawReady");
//#         }
//#         g.drawString("获胜条件",
//#                 (SCREEN_WIDTH - SCREEN_W_K700) / 2 + coorX,
//#                 (SCREEN_HEIGHT - SCREEN_H_K700) / 2 + coorY +
//#                 2 * (FONT_HEIGHT - 1) + thisImgRoleHead.getHeight(),
//#                 20);
//#         g.drawString(" " + EVERYBONUS[currentScreen][currentRole] + "分",
//#                 (SCREEN_WIDTH - SCREEN_W_K700) / 2 + coorX,
//#                 (SCREEN_HEIGHT - SCREEN_H_K700) / 2 + coorY +
//#                 3 * (FONT_HEIGHT - 1) + thisImgRoleHead.getHeight(),
//#                 20);
    //#else
    g.setFont(m_HelpFont);
    g.setColor(255, 255, 0);
    g.drawString(EVERYSCREENNAME[currentScreen], coorX,
                 coorY - V600_WORD_HEIGHT, 20);
    g.drawString(HINT[9], coorX, coorY + (FONT_HEIGHT - 1) - V600_WORD_HEIGHT,
                 20);
    try {
      g.drawImage(thisImgRoleHead, coorX + 15,
                  coorY + 2 * (FONT_HEIGHT - 1) - V600_WORD_HEIGHT,
                  20);
    }
    catch (Exception e) {
      System.out.println("This is drawReady");
    }
    g.drawString(HINT[10], coorX,
                 coorY + 2 * (FONT_HEIGHT - 1) + thisImgRoleHead.getHeight() -
                 V600_WORD_HEIGHT,
                 20);
    g.drawString(" " + EVERYBONUS[currentScreen][currentRole] + HINT[11],
                 coorX,
                 coorY + 3 * (FONT_HEIGHT - 1) + thisImgRoleHead.getHeight() -
                 V600_WORD_HEIGHT,
                 20);
    //#endif
  }

  /**
   * 函数功能:线程的执行内容
   * 参数:无
   * 返回值:无
   * 备注:
   */
  boolean bitting = false;
  public void run() {
    long time;
    while (threadLoop) {
      time = System.currentTimeMillis();
      switch (gameState) {
        case STATE_NULL:
          loadingLogoImage();
          changeState(STATE_LOGO1);
          break;
        case STATE_LOGO1: //程序开始时读取Logo图片
          try {
            Thread.sleep(1000);
            changeState(STATE_LOGO2);
            imgLogo1 = null;
          }
          catch (Exception e) {}
          break;
        case STATE_LOGO2:
          try {
            Thread.sleep(2000);
            changeState(STATE_COVER);
            imgLogo2 = null;
          }
          catch (Exception e) {}
          break;
        case STATE_COVER:
          if (bCoverAnimationOver()) {
            try {
              Thread.sleep(1000);
              changeState(STATE_LOADING);
              m_CoverAnimation = null;
              imgCover = null;
              imgLoading = loadImage(IMAGE_LOADING);
            }
            catch (Exception e) {}
          }
          break;
        case STATE_LOADING:
          if (loadingGameImage()) {
            changeState(STATE_DEMO);
            imgLoading = null;
          }
          break;
        case STATE_MAINMENU:
          if (bDemoAnimationOver()) {
            m_DemoAnimation = null;
          }
          break;
        case STATE_INIT:
          init();
          if (loadingGuage2 == 5) {
            loadingGuage2 = 0;
            m_ReadyAnimation.setFrame( (short) 0);
            changeState(STATE_GAMEREADY);
          }
          break;
        case STATE_GAME:
          if (!m_Paused) {
            CheckPass(); //检测是否已经过关
            moveMap(); // 移动地图
            //根据角色状态的不同,分别进行不同的操作
            if (thisRole.getRoleStatus() == ROLESTATUS_INJURE) {
              roleBackInjure();
            }
            else {
              //检测角色的姿势
              if (thisRole.getRoleStatus() != ROLESTATUS_INJURE) {
                if (thisRole.getRolePose() == ROLEPOSE_JUMP) {
                  if (thisRole.getRoleTool() == ROLETOOL_NONE
                      || thisRole.getRoleTool() == ROLETOOL_BAT
                      || thisRole.getRoleTool() == ROLETOOL_BOTTLE
                      || thisRole.getRoleTool() == ROLETOOL_MOTOHAT) {
                    roleJump();
                  }
                  else if (thisRole.getRoleTool() == ROLETOOL_BATHIT) {
                    if (bitting == false) {
                      switch (currentRole) {
                        case ROLE_BOY:
                          thisRole.player.setAnimation(12, false);
                          break;
                        case ROLE_GIRL:
                          thisRole.player.setAnimation(36, false);
                          break;
                        case ROLE_NINJA:
                          thisRole.player.setAnimation(23, false);
                          break;
                      }
                      bitting = true;
                    }
                    if (!thisRole.player.bAnimationOver()) {
                      thisRole.player.setNextFrame();
                    }
                    else {
                      bitting = false;
                      thisRole.setRoleTool(ROLETOOL_BAT);
                      switch (currentRole) {
                        case ROLE_BOY:
                          thisRole.player.setAnimation(2, true);
                          break;
                        case ROLE_GIRL:
                          thisRole.player.setAnimation(26, false);
                          break;
                        case ROLE_NINJA:
                          thisRole.player.setAnimation(39, false);
                          break;
                      }
                    }
                    roleJump();
                  }
                  else if (thisRole.getRoleTool() == ROLETOOL_BOTTLEHIT) {
                    if (bitting == false) {
                      switch (currentRole) {
                        case ROLE_BOY:
                          thisRole.player.setAnimation(13, false);
                          break;
                        case ROLE_GIRL:
                          thisRole.player.setAnimation(37, false);
                          break;
                        case ROLE_NINJA:
                          thisRole.player.setAnimation(24, false);
                          break;
                      }
                      bitting = true;
                    }
                    if (!thisRole.player.bAnimationOver()) {
                      thisRole.player.setNextFrame();
                    }
                    else {
                      bitting = false;
                      thisRole.setRoleTool(ROLETOOL_BOTTLE);
                      switch (currentRole) {
                        case ROLE_BOY:
                          thisRole.player.setAnimation(3, true);
                          break;
                        case ROLE_GIRL:
                          thisRole.player.setAnimation(27, true);
                          break;
                        case ROLE_NINJA:
                          thisRole.player.setAnimation(15, true);
                          break;
                      }
                    }
                    roleJump();
                  }
                }
                else if (thisRole.getRolePose() == ROLEPOSE_NORMAL) {
                  if (thisRole.getRoleTool() == ROLETOOL_BATHIT) {
                    if (bitting == false) {
                      switch (currentRole) {
                        case ROLE_BOY:
                          thisRole.player.setAnimation(12, false);
                          break;
                        case ROLE_GIRL:
                          thisRole.player.setAnimation(36, true);
                          break;
                        case ROLE_NINJA:
                          thisRole.player.setAnimation(23, true);
                          break;
                      }
                      bitting = true;
                    }
                    if (!thisRole.player.bAnimationOver()) {
                      thisRole.player.setNextFrame();
                    }
                    else {
                      bitting = false;
                      thisRole.setRoleTool(ROLETOOL_BAT);
                      switch (currentRole) {
                        case ROLE_BOY:
                          thisRole.player.setAnimation(2, true);
                          break;
                        case ROLE_GIRL:
                          thisRole.player.setAnimation(26, true);
                          break;
                        case ROLE_NINJA:
                          thisRole.player.setAnimation(39, true);
                          break;
                      }
                    }
                  }
                  else if (thisRole.getRoleTool() == ROLETOOL_BOTTLEHIT) {
                    if (bitting == false) {
                      switch (currentRole) {
                        case ROLE_BOY:
                          thisRole.player.setAnimation(13, false);
                          break;
                        case ROLE_GIRL:
                          thisRole.player.setAnimation(37, false);
                          break;
                        case ROLE_NINJA:
                          thisRole.player.setAnimation(24, false);
                          break;
                      }
                      bitting = true;
                    }
                    if (!thisRole.player.bAnimationOver()) {
                      thisRole.player.setNextFrame();
                    }
                    else {
                      bitting = false;
                      thisRole.setRoleTool(ROLETOOL_BOTTLE);
                      switch (currentRole) {
                        case ROLE_BOY:
                          thisRole.player.setAnimation(3, true);
                          break;
                        case ROLE_GIRL:
                          thisRole.player.setAnimation(27, true);
                          break;
                        case ROLE_NINJA:
                          thisRole.player.setAnimation(15, true);
                          break;
                      }
                    }
                  }
                }
              }
              //检测是否越过障碍物
              if (thisRole.getRoleStatus() != ROLESTATUS_INJURE) {
                checkOverFraise();
              }
              //检测是否碰到障碍物
              if (thisRole.getRoleStatus() != ROLESTATUS_INJURE) {
                checkFraise();
              }
              //检测是否碰到敌人
              if (thisRole.getRoleStatus() != ROLESTATUS_INJURE) {
                checkEnemy();
              }
              //检测是否碰到奖品
              if (thisRole.getRoleStatus() != ROLESTATUS_INJURE) {
                checkBonus();
              }
              if (thisRole.getRoleStatus() != ROLESTATUS_INJURE) {
                //检测是否碰到工具
                int tmpY = thisRole.getRoleY() +
                    thisRole.player.currentFrameCollisionH;
                switch (checkTool()) {
                  case TOOL_BAT:
                    thisRole.setRoleTool(ROLETOOL_BAT);
                    if (thisRole.getRolePose() == ROLEPOSE_NORMAL ||
                        thisRole.getRolePose() == ROLEPOSE_JUMP) {
                      switch (currentRole) {
                        case ROLE_BOY:
                          thisRole.player.setAnimation(2, true);
                          break;
                        case ROLE_GIRL:
                          thisRole.player.setAnimation(26, true);
                          break;
                        case ROLE_NINJA:
                          thisRole.player.setAnimation(39, true);
                          break;
                      }
                      thisRole.setRoleY(tmpY -
                                        thisRole.player.currentFrameCollisionH);
                   

⌨️ 快捷键说明

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