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

📄 mscreen.java~5~

📁 手机游戏小游戏 合金弹头 J2ME S60模拟器源代码
💻 JAVA~5~
📖 第 1 页 / 共 5 页
字号:
  private final void hero_setcframe(int cframe_id){
    hero_cframe = cframe_id;
    hero_frectw = heroaction[hero_action][hero_cframe][HERO_FRAME_RECTW];
    hero_frectt = heroaction[hero_action][hero_cframe][HERO_FRAME_RECTT];
  }

  private final void hero_action_play(){
    if(((hero_status & STATUS_FIRE) == STATUS_FIRE_SWORDS) ||
      ((hero_status & STATUS_FIRE) == STATUS_FIRE_THROWS)){
      if(hero_cframe < heroaction[hero_action].length - 1)
        hero_cframe ++;
    }else
      hero_cframe = (hero_cframe < heroaction[hero_action].length - 1)? hero_cframe + 1: 0;
  }
  private final boolean hero_action_finish(){
    return hero_cframe == heroaction[hero_action].length - 1;
  }
  /**********************************************
   * 移动主角位置 这个位置使用的是主角的直接坐标 不是网格坐标
   * @param x int 主角在地图上的绝对位置X
   * @param y int 主角在地图上的绝对位置Y
   **********************************************/
  private final void hero_move(int x, int y){
    hero_pos_x = x;
    hero_pos_y = y;
    adScreen();
  }

  /**********************************************
   * 画出主角的
   **********************************************/
  private final void hero_draw() {
    int[] fram = heroaction[hero_action][hero_cframe];
    if(hero_cflash > 0) hero_cflash--;
    if((hero_cflash & 1) == 1) return;
    int part_l, part_t, part_w, part_h, show_x, show_y;
    int rotate = (hero_direct == -1)? 0 : 0x2000;
    for(int i = 0; i < 2; i++){
      part_l = hero_pos_x - ((hero_direct == -1)?
                             fram[HERO_FRAME_PARTSTART + i * HERO_FRAME_PARTCOUNT + HERO_FRAME_FRAML]:
                             fram[HERO_FRAME_PARTSTART + i * HERO_FRAME_PARTCOUNT + HERO_FRAME_FRAMR]);
      part_t = hero_pos_y - fram[HERO_FRAME_PARTSTART + i * HERO_FRAME_PARTCOUNT + HERO_FRAME_FRAMT];
      part_w = fram[HERO_FRAME_PARTSTART + i * HERO_FRAME_PARTCOUNT + HERO_FRAME_FRAML] +
          fram[HERO_FRAME_PARTSTART + i * HERO_FRAME_PARTCOUNT + HERO_FRAME_FRAMR];
      part_h = fram[HERO_FRAME_PARTSTART + i * HERO_FRAME_PARTCOUNT + HERO_FRAME_FRAMT] +
          fram[HERO_FRAME_PARTSTART + i * HERO_FRAME_PARTCOUNT + HERO_FRAME_FRAMB];
      show_x = hero_pos_x - ((hero_direct == -1)?fram[HERO_FRAME_PARTSTART +
                             i * HERO_FRAME_PARTCOUNT + HERO_FRAME_FACEL]:
                             fram[HERO_FRAME_PARTSTART + i * HERO_FRAME_PARTCOUNT + HERO_FRAME_FACER]);
      show_y = hero_pos_y - fram[HERO_FRAME_PARTSTART + i * HERO_FRAME_PARTCOUNT + HERO_FRAME_FACET];
      clipRect(part_l, part_t, part_w, part_h);
      drawFace(hero_face, show_x, show_y, rotate);
    }
  }

  /**********************************************
   * 主角接近了怪物 用于主角是否7用刀来攻击
   * @return boolean 当有怪物达到主角出到距离返回True
   **********************************************/
  private final boolean hero_near(){ // w17, h11
    int sword_l = hero_pos_x - ((hero_direct == -1) ? 17: 0);
    int sword_r = hero_pos_x + ((hero_direct == -1) ? 0: 17);
    int sword_t = hero_pos_y - 11;
    int sword_b = hero_pos_y + 11;
    boolean rt = false;
    for(int i = ogres.size() - 1; i >= 0; i--){
      int[] ogre = (int[])ogres.elementAt(i);
      int[] defin = ogre_getdefin(ogre);
      if((ogre[OGRE_DEATH] > 0) || (defin[OGRE_DEFIN_STYLE] == 1))continue;
      int[] frame = ogre_getframe(ogre);
      if((ogre[OGRE_POS_X] - frame[OGRE_FRAME_RECTW] < sword_r) &&
         (ogre[OGRE_POS_X] + frame[OGRE_FRAME_RECTW] > sword_l) &&
         (ogre[OGRE_POS_Y] - frame[OGRE_FRAME_RECTT] < sword_b) &&
         (ogre[OGRE_POS_Y] + 11                      > sword_t)){
        rt = true;
        break;
      }
    }
    for(int i = pawns.size() - 1; i >= 0; i--){
      int[] pawn = (int[])pawns.elementAt(i);
      if((pawn[PAWN_POS_X] - PAWN_HALFW < sword_r) &&
         (pawn[PAWN_POS_X] + PAWN_HALFW > sword_l) &&
         (pawn[PAWN_POS_Y] - PAWN_HALFH < sword_b) &&
         (pawn[PAWN_POS_Y] + PAWN_HALFH > sword_t) &&
         (pawn[PAWN_STATE] == 0)){
        rt = true;
        break;
      }
    }
    return rt;
  }

  private final void hero_deadone(){
    if(hero_being <= 0){
      hero_death = true;
      return;
    }
    time_init();
    //重新初始化主角参数
    hero_cflash = 20;

    hero_anima = 10;
    hero_bombcount = 10;
    hero_setfirestatus(STATUS_FIRE_NORMAL);
    hero_death = false;
    hero_being --;
    hero_spd_y = 0;
    //查找可以站立的位置
    if(hero_old_x < position_x){
      for(int i = (position_x  >> 3) + 1; i < ((position_x + screen_w) >> 3) - 3; i++){
        for(int j = position_y >> 3; j < (position_y + screen_h) >> 3; j ++){
          if (grid_cellvalue(i, j) > 0) {
            hero_pos_x = i << 3;
            hero_pos_y = (j << 3) - 100;
            return;
          }
        }
      }
    }else{
      hero_pos_x = hero_old_x;
      hero_pos_y = hero_old_y - 100;
    }
  }

  private final void hero_addscore(int score){
    if(hero_score / 10000 < (hero_score + score) / 10000){
      sound_play(SOUND_GETBEING);
      hero_being ++;
    }
    hero_score += score;
  }

  private final void hero_gainprop(){
    for(int i = props.size() - 1; i  >= 0; i--){
      int[] prop = (int[])props.elementAt(i);
      if((prop[PROP_POS_X] + (PROP_POS_W >> 1) > hero_pos_x - hero_frectw) &&
         (prop[PROP_POS_Y] > hero_pos_y - hero_frectt) &&
         (hero_pos_x + hero_frectw > prop[PROP_POS_X] - (PROP_POS_W >> 1)) &&
         (hero_pos_y + 11 > prop[PROP_POS_Y] - PROP_POS_H)){
        switch(prop[PROP_INDEX]){
          case 0://0 猪
          case 1://1 屎
          case 2://2 蘑菇
          case 3://3 勋章
          case 4://4 鱼
          case 5://5 烤鸡
            hero_addscore(prop[PROP_TOTAL]);
            info_create(hero_pos_x, hero_pos_y - 10, prop[PROP_TOTAL]);
            break;
          case 6://6 炸弹
            hero_bombcount += prop[PROP_TOTAL];
            break;
          case 7://7 机枪
            if(hero_shot_type == SHOT_TYPE_TOMM)
              hero_shotcount += prop[PROP_TOTAL];
            else{
              hero_shotcount = prop[PROP_TOTAL];
              hero_shot_type = SHOT_TYPE_TOMM;
            }
            break;
          case 8://8 导弹
            if(hero_shot_type == SHOT_TYPE_MISS)
              hero_shotcount += prop[PROP_TOTAL];
            else{
              hero_shotcount = prop[PROP_TOTAL];
              hero_shot_type = SHOT_TYPE_MISS;
            }
            break;
          case 9://9 火焰
          case 10://10 激光
          case 11://11 霰弹
            break;
        }
        props.removeElementAt(i);
      }
    }
  }
  /**********************************************
   * 调整屏幕在地图上的位置
   **********************************************/
  private final void hero_adScene() {
    if((platid == MISSION_1_PLAT_FINAL) || (platid == MISSION_2_PLAT_FINAL) || (platid == MISSION_3_PLAT_FINAL)){
      int x_pre = ((hero_direct == -1) ?  hero_pos_x - screen_w * 2 / 3 :
                   hero_pos_x + screen_w * 2 / 3 - screen_w) - position_x;
      if((x_pre > 100) || (x_pre < -100))
        position_x += (x_pre > 0) ? x_pre - 100 : x_pre + 100;
      else
        position_x += x_pre / 3;
    }else{
      if (hero_pos_x - screen_w / 3 > position_x)
        position_x = hero_pos_x - screen_w / 3;
    }
    position_y += ((hero_pos_y - screen_h / 2) - position_y) / 3;
    if(position_x < 0) position_x = 0;
    else if (position_x + screen_w > plat_w * 8) position_x = plat_w * 8 - screen_w;
    if (position_y < 0) position_y = 0;
    else if (position_y + screen_h > plat_h * 8) position_y = plat_h * 8 - screen_h;
  }

  /**********************************************
   * 主角RUN方法
   **********************************************/
  private final void hero_exec() {
    //读取按键信息
    int key_Press = key_Statuse;
    if(mission_final_tally > 0) key_Press = 0;
    if((hero_status & STATUS_FIRE) == STATUS_FIRE_DEATHS) key_Press = 0;

    if(hero_bombtally > 0) hero_bombtally --;
    if(hero_shottally > 0) hero_shottally --;
    if((hero_shot_type != 0) && (hero_shotcount <= 0)) hero_shot_type = 0;

    if(hero_pos_y > plat_h * 8){
      hero_deadone();
    }else{
      //控制主角移动
      hero_gainprop();
      hero_frectw = heroaction[hero_action][hero_cframe][HERO_FRAME_RECTW];
      hero_frectt = heroaction[hero_action][hero_cframe][HERO_FRAME_RECTT];
      switch (hero_status & STATUS_MAIN) {
        case STATUS_MAIN_STAND: hero_stand(key_Press); break;
        case STATUS_MAIN_SQUAT: hero_squat(key_Press); break;
        case STATUS_MAIN_INAIR: hero_inair(key_Press); break;
      }
      hero_frectw = heroaction[hero_action][hero_cframe][HERO_FRAME_RECTW];
      hero_frectt = heroaction[hero_action][hero_cframe][HERO_FRAME_RECTT];
      hero_select_action();
      switch(hero_status & STATUS_FIRE){
        case STATUS_FIRE_ATTACK: hero_fire(); break;
        case STATUS_FIRE_THROWS: hero_toss(); break;
        case STATUS_FIRE_SWORDS: hero_sword();break;
      }
    }
    hero_action_play();
    hero_adScene();  //随着主角的移动 调整屏幕在地图上的位置
  }

  /**********************************************
   * 主角站在平台上的动作处理
   * @param key_Press int 按键按下状态数据
   **********************************************/
  private final void hero_stand_key(int key_Press){
    switch(key_Press){
      case KEY_DOWN:
        hero_setmainstatus(STATUS_MAIN_SQUAT);
        hero_setportstatus(STATUS_PORT_BASE);
        return;
      case KEY_JUMP:
        hero_setmainstatus(STATUS_MAIN_INAIR);
        hero_spd_y = SPEED_VERT_START;
        return;
      case KEY_LEFT:
        hero_direct = -1;
        break;
      case KEY_RIGH:
        hero_direct = 1;
        break;
      case KEY_OVER:
        hero_setportstatus(STATUS_PORT_OVER);
        break;
    }
  }

  private final void hero_stand(int key_Press){
    if(!hero_stan()){
      hero_setmainstatus(STATUS_MAIN_INAIR);
      return;
    }else if((key_Press & KEY_LEFT) != 0){
      hero_direct = -1;
      hero_setmovestatus(STATUS_MOVE_MOVE);
      hero_walk();
    }else if((key_Press & KEY_RIGH) != 0){
      hero_direct = 1;
      hero_setmovestatus(STATUS_MOVE_MOVE);
      hero_walk();
    }else
      hero_setmovestatus(STATUS_MOVE_REST);

    if((key_Press & KEY_OVER) != 0)
      hero_setportstatus(STATUS_PORT_OVER);
    else
      hero_setportstatus(STATUS_PORT_BASE);

    switch(hero_status & STATUS_FIRE){
      case STATUS_FIRE_NORMAL:
        if(((key_Press & KEY_TOSS) != 0) && (hero_bombtally <= 0))
          hero_setfirestatus(STATUS_FIRE_THROWS);
        else if((key_Press & KEY_FIRE) != 0){
          if(hero_near())
            hero_setfirestatus(STATUS_FIRE_SWORDS);
          else
            hero_setfirestatus(STATUS_FIRE_ATTACK);
        }
        break;
      case STATUS_FIRE_ATTACK:
        if(((key_Press & KEY_TOSS) != 0) && (hero_bombtally <= 0))
          hero_setfirestatus(STATUS_FIRE_THROWS);
        else if((key_Press & KEY_FIRE) == 0)
          hero_setfirestatus(STATUS_FIRE_NORMAL);
        else if(hero_near())
          hero_setfirestatus(STATUS_FIRE_SWORDS);
        break;
      case STATUS_FIRE_THROWS:
        if(hero_action_finish()){
          if((key_Press & KEY_FIRE) == 0)
            hero_setfirestatus(STATUS_FIRE_NORMAL);
          else if(hero_near())
            hero_setfirestatus(STATUS_FIRE_SWORDS);
          else
            hero_setfirestatus(STATUS_FIRE_ATTACK);
        }
        break;
      case STATUS_FIRE_SWORDS:
        if(hero_action_finish()){
          if((key_Press & KEY_FIRE) == 0)
            hero_setfirestatus(STATUS_FIRE_NORMAL);
          else if(hero_near())
            hero_setfirestatus(STATUS_FIRE_SWORDS);
          else
            hero_setfirestatus(STATUS_FIRE_ATTACK);
        }
        break;
      case STATUS_FIRE_DEATHS:
        if(hero_action_finish()){
          hero_deadone();
        }
        break;
    }
  }

  /**********************************************
   * 主角蹲在平台上的动作处理
   *

⌨️ 快捷键说明

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