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

📄 framecanvas.java

📁 J2ME手机游戏的矿架程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                   monster[i].x-monster[i].w/2,
                   monster[i].y-monster[i].h,
                   monster[i].w,monster[i].h);
       if(monster[i].who!=99 &&                     //it is a  monster
         (canSee ||                                 //it is in srceen
          monster[i].who==4 || monster[i].who==5 || //knife or bomGo
          monster[i].who==7 || monster[i].who==8 || //boss
          monster[i].blood<1))                      //dead
       {
         switch (monster[i].who)
         {
           default:
                  if(monster[i].hurt%2==0)
                     _drawImg(g,imgMonster[monster[i].who][monster[i].face-right],
                         monster[i].x,
                         monster[i].y-imgMonster[monster[i].who][monster[i].face-right].getHeight(),
                         imgMonster_XY[monster[i].who][monster[i].frame][0],
                         0,
                         imgMonster_XY[monster[i].who][monster[i].frame][1],
                         imgMonster[monster[i].who][monster[i].face-right].getHeight(),
                         imgMonster[monster[i].who][monster[i].face-right].getWidth(),
                         monster[i].face,monster[i].w);
                  switch(monster[i].who)
                  {
                     case 0:
                          _doMonsterKnife(i);
                          break;
                     case 1:
                          _doMonsterGun(i);
                          break;
                     case 2:
                          _doMonsterKnife(i);
                          break;
                     case 3:
                          monster_die++;
                          _doMonsterBom(i);
                          break;
                  }
                  break;
             case 7:
             case 8:
               if(monster[i].life==1 && Math.abs(man.x-monster[i].x)<40 && man.y==monster[i].y)
               {
                  _initHereTalk(4);
                  monster[i].life=0;

                  if(man.x>monster[i].x)
                  {
                     monster[i].face=right;
                     man.face=left;
                  }
                  else
                  {
                     monster[i].face=left;
                     man.face=right;
                  }
               }

               int moveY=0;
               if(monster[i].who==7 && monster[i].frame==3)
               {
                  moveY=2;
               }

               if(monster[i].who==8 || monster[i].hurt%2==0)
               _drawImg(g,imgMonster[7][monster[i].face-right],
                        monster[i].x,//-imgMonster_XY[monster[i].who][monster[i].frame][1]/2,
                        monster[i].y-imgMonster[7][0].getHeight()+moveY,
                        imgMonster_XY[monster[i].who][monster[i].frame][0],0,
                        imgMonster_XY[monster[i].who][monster[i].frame][1],
                        imgMonster[7][0].getHeight(),
                        imgMonster[7][0].getWidth(),
                        monster[i].face,
                        (byte)imgMonster_XY[monster[i].who][monster[i].frame][1]);//monster[i].w);
                  switch(monster[i].who)
                  {
                     case 7:
                          _doBoss(i);
                          break;
                     case 8:
                          _doBossLeg(i);
                          break;
                  }
                  break;
             case 4://子弹
                  monster_die++;
                  _cjcDrawImg(g,imgMonster[1][0],monster[1].x,monster[1].y-7,0,0,7,7);
                  _doKinfe(g);
                  break;
             case 5://炮弹
                  monster_die++;
                  _cjcDrawImg(g,imgMonster[4][0],
                              monster[0].x,
                              monster[0].y-18,
                              bomGo_XY[monster[0].frame][0],
                              0,
                              bomGo_XY[monster[0].frame][1],
                              18);
                  _doMonsterBomGo();
                  break;
             case 6://food
                  monster_die++;
                  if(monster[i].face>1)
                  {
                     break;
                  }
                  _cjcDrawImg(g,imgMonster[monster[i].who][0],
                              monster[i].x- 8,
                              monster[i].y-17,
                              imgMonster_XY[monster[i].who][monster[i].face][0],
                              0,
                              imgMonster_XY[monster[i].who][monster[i].face][1],
                              17);
                  _doFood(i);
                  break;
         }
       }
       else if(monster[i].who==99 || monster[i].who==3 || monster[i].who==6)
       {
         monster_die++;
       }
     }

     //is pass gate?
     if(monster.length==monster_die)
     {
        gate++;
        _initGame();
     }
     //debug======================================
     //debug======================================
     //debug======================================
//     g.setColor(0xff0000);
//     g.drawString("monster_die:"+monster_die   ,20+mapX,100+mapY,20);
//     g.drawString("monster_all:"+monster.length,20+mapX,120+mapY,20);
   }
//******************************************************************************
//RUN 区
 //==============================================================================
//move 远景
//------------------------------------------------------------------------------
 private void _brainMoveMap_manInMap_goMiddle()
 {
     byte where=99;
     byte UD=1;
     byte LR=1;

     for(int i=0;i<mapMoveSp_fast;i++)
     {
       //Up and Down
       if(UD==1)
       if(man.y-mapY >= man.MidY+2 && mapY < mapY_max)
       {
          mapY++;
       }
       else  if(man.y-mapY<man.MidY && mapY > mapY_min)
       {
          mapY--;
       }
       else//map在UD方向不需要再卷动了
       {
          UD=0;
       }
       //Right and Left
       if(man.frame<36)
       if(!(i<mapMoveSp_slow))
       {
          continue;
       }

       int MidX=man.R_midX;
       if(man.face==right)
       {
          MidX=man.R_midX;
       }
       else
       {
          MidX=man.L_midX;
       }

       if(LR==1)
       if(man.x-mapX >= MidX+1 && mapX < mapX_max)///
       {
          mapX++;
          where=1;
       }
       else if(man.x-mapX < MidX && mapX > mapX_min)///
       {
          mapX--;
          where=0;
       }
       else//map在LR方向不需要再卷动了
       {
          LR=0;
       }

       if(LR==0 && UD==0)
       {
          break;
       }
    }
 }
//==============================================================================
 //share sub program canGo? in map
 public  boolean isCanGo_mapCell[][]=
 {
    {false,
    false,true,true,false,true,true,true,false,false,false,true,true,true,false,false},

    {false,
    false,true,true,true,true,true,true,false,false,true,true,false,false,true,true,false,false,
    true,true,true,true,true,true,false,false,true,true},
 };
 public byte nail_index[]={2,2};

 private byte _inMap_canGo_left(int x,int y,int w,int h)
 {
   if(isCanGo_mapCell[(gate+1)%2][map[(y-h)/mapCellH][(x-w/2-boot-4)/mapCellW]] &&
      isCanGo_mapCell[(gate+1)%2][map[(y-1)/mapCellH][(x-w/2-boot-4)/mapCellW]])
   {
      return 1;
   }

   return 0;
 }

 private byte _inMap_canGo_right(int x,int y,int w,int h)
 {
   if(isCanGo_mapCell[(gate+1)%2][map[(y-h)/mapCellH][(x+w/2+boot+4)/mapCellW]] &&
      isCanGo_mapCell[(gate+1)%2][map[(y-1)/mapCellH][(x+w/2+boot+4)/mapCellW]])
   {
      return 1;
   }

   return 0;
 }

 private byte _inMap_canGo_up(int x,int y,int w,int h)
 {
   if(isCanGo_mapCell[(gate+1)%2][map[(y-h)/mapCellH][(x-w/2)/mapCellW]] &&
      isCanGo_mapCell[(gate+1)%2][map[(y-h)/mapCellH][(x+w/2)/mapCellW]])
    {
      return 1;
    }

    return 0;
 }

 private byte _inMap_canGo_down(int x,int y,int w,int h)
 {
   if(isCanGo_mapCell[(gate+1)%2][map[(y)/mapCellH][(x-w/2)/mapCellW]] &&
      isCanGo_mapCell[(gate+1)%2][map[(y)/mapCellH][(x+w/2)/mapCellW]])
    {
      return 1;
    }

    return 0;
 }
//==============================================================================
 private int man_Hurt(int hurt,int bigOrSmall_hurt)
 {
     if(man.hurt!=0 || man.blood<1)
     {
        return 0;
     }

     if(_inMap_canGo_down(man.x,man.y,man.w,man.h)==0
          &&
        (bigOrSmall_hurt==0
          ||
        (bigOrSmall_hurt!=1 && _getRandomNumInTwo(0,50)>10)))
     {//hurt1
        man.blood-=hurt;
        if(man.frame!=17)
        {
           man.frame=17;
        }
        else
        {
           man.frame=0;
        }
     }
     else
     {//big hurt
        man.blood-=hurt+1;
        man.frame=15;
        man.UDSp=-12;
     }

     if(man.blood<=0)
     {
        man.frame=15;
     }

     return 0;
 }

 private void _manHurtFace(short monsterX)
 {
     if(man.x>monsterX)
     {
        man.face=left;
     }
     else
     {
        man.face=right;
     }
 }

 private byte _do_man()
 { //dec the hurt time
   if(man.hurt>0)
   {
      man.hurt--;
   }
   //add the man.magic
   if(man.magic<man.max_magic && gameTime%10==0)
   {
      man.magic++;
   }

   if(man.hurt==0 && man.frame!=15 && man.frame!=16 && man.frame!=17)
   if(map[(man.y)/mapCellH-1][(man.x-man.w/2)/mapCellW]==nail_index[(gate+1)%2] ||
      map[(man.y)/mapCellH-1][(man.x+man.w/2)/mapCellW]==nail_index[(gate+1)%2])
   {
      man_Hurt(4,1);
   }

 if(man.blood<1)
 if(man.frame!=15 && man.frame!=16)
 {
    man.frame=15;
 }

   switch(man.frame)
   {
      case 0://stop
      case 1:
      case 2:
      case 3:
           if(keyRepeat==false && gameTime%3==0)
              man.frame=(byte)((man.frame+1)%4);
           break;
      case 22://jump att
      case 23:
           if(gameTime%3==0)
              man.frame++;
           break;
      case 24://jump att last
           if(gameTime%2==0)
              man.frame=14;
           break;
      case 30://xiang jiao quan last
           man.frame=0;
           break;
      case 25://xiang jiao quan
      case 26:
      case 27:
      case 28:
      case 29:
           man.frame++;
           break;
      case 31:
      case 32:
      case 33:
      case 34:
      case 8:
      case 9:
           man.frame++;
           break;
      case 35:
           man.frame=0;
           break;
      case 10:
           if(gameTime%2==0)
           {
              man.frame=11;
           }
           break;
      case 11:
           if(gameTime%2==0)
           {
              man.frame=10;
           }
           break;
      case 14://down
           if(man.UDSp<0)
           {
              man.frame=12;
           }

           if(_inMap_canGo_down(man.x,man.y,man.w,man.h)==0)
           {
              man.frame=0;
           }
           break;
      case 12:
           if(man.UDSp<0 && Math.abs(man.UDSp)<8)
           {
              man.frame++;
           }
           break;
      case 17://hurt
//           if(gameTime%2==0)
           {
              man.frame=0;
           }

           if(man.face==left && _inMap_canGo_right(man.x,man.y,man.w,man.h)==1)
           {
              man.x+=man.LRSp/2;
           }
           else if(man.face==right && _inMap_canGo_left(man.x,man.y,man.w,man.h)==1)
           {
              man.x-=man.LRSp/2;
           }
           break;
      case 15://die 1
           if(_inMap_canGo_down(man.x,man.y,man.w,man.h)==1)
           {
             if(man.face==left
                 &&
                _inMap_canGo_right(man.x,man.y,man.w,man.h)==1)
             {
                man.x+=man.LRSp;
             }
             else if(man.face==right
                &&
               _inMap_canGo_left(man.x,man.y,man.w,man.h)==1)
             {
                man.x-=man.LRSp;
             }
           }
           else if(man.UDSp==0)
           {
              man.frame++;
           }
           break;
      case 16://die down
           if(gameTime%3==0)
           {
              man.hurt=14;
              if(man.blood>0)
                 man.frame=0;
           }

           if(man.blood<1)
           {
              key_delay=10;
              game_state=GAME_MAN_DEAD;
           }
           break;
      case 36://冲出去
      case 37:
      case 38:
      case 39:
      case 40:

⌨️ 快捷键说明

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