MarioMainSprite.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:38k
源码类别:

J2ME

开发平台:

Java

  1. /**
  2.  * <p>Title: Mario</p>
  3.  * <p>Description:
  4.  * You cannot remove this copyright and notice.
  5.  * You cannot use this file any part without the express permission of the author.
  6.  * All Rights Reserved</p>
  7.  * <p>Copyright: lizhenpeng (c) 2004</p>
  8.  * <p>Company: LP&P</p>
  9.  * @author lizhenpeng
  10.  * @version 1.0.0
  11.  */
  12. package mario;
  13. import javax.microedition.lcdui.*;
  14. import lipeng.*;
  15. import java.io.*;
  16. public class MarioMainSprite
  17.   extends LPSprite
  18. {
  19.   public MarioMainSprite(MarioGameManage gm, LPMaps map)
  20.   {
  21.     this.gm = gm;
  22.     this.judgeMap = map;
  23.     mainSpriteState = SMALL_SPRITE;
  24.     this.gm = gm;
  25.   }
  26. //method
  27.   public void action()
  28.   {
  29.     bgdx=0;
  30.     bgdy=0;
  31.     switch(mainSpriteState)
  32.     {
  33.       case GROW_SPRITE:
  34.         if(++growCnt==10)
  35.         {
  36.           mainSpriteState=NORMAL_SPRITE;
  37.           growCnt=0;
  38.         }
  39.         else
  40.         {
  41.           if(growCnt%2==0)
  42.           {
  43.             y+=16;
  44.           }
  45.           else
  46.           {
  47.             y-=16;
  48.           }
  49.         }
  50.         break;
  51.       case BECOME_FIRE:
  52.         if(++becomeCnt==10)
  53.         {
  54.           mainSpriteState=FIRE_SPRITE;
  55.           becomeCnt=0;
  56.         }
  57.         break;
  58.       case DEAD_SPRITE:
  59.         if(deadCnt==0)
  60.         {
  61.           dy=-10;
  62.           frameCnt=10;
  63.         }
  64.         frameCnt=10;
  65.         ++dy;
  66.         y+=dy;
  67.         if(++deadCnt>=20)
  68.         {
  69.           deadCnt=0;
  70.           mainSpriteState=SMALL_SPRITE;
  71.           gm.gameState=MarioGameManage.GAMESTATE_REINIT;
  72.         }
  73.         break;
  74.       case BECOME_SMALL:
  75.         if(++becomeCnt==10)
  76.         {
  77.           mainSpriteState=SMALL_SPRITE;
  78.           becomeCnt=0;
  79.         }
  80.         break;
  81.       default:
  82.       {
  83.         dy+=2;
  84.         checkSpriteCollisionVertical();
  85.         checkTileCollisionVertical();
  86.         mainSpriteDamage();
  87.         y+=dy;
  88.         if(y+this.judgeMap.y<0)
  89.         {
  90.           y=0;
  91.           dy=0;
  92.         }
  93.         if(y<=MarioMIDlet.gameCanvas.height/4
  94.            ||
  95.            ((this.judgeMap.y!=
  96.              this.judgeMap.tileSize*this.judgeMap.h-
  97.              MarioMIDlet.gameCanvas.height)
  98.             &&y>=MarioMIDlet.gameCanvas.height/4)
  99.           )
  100.         {
  101.           this.bgdy=(MarioMIDlet.gameCanvas.height/4-y)>>2;
  102.           if(bgdy-this.judgeMap.y<
  103.              MarioMIDlet.gameCanvas.height-
  104.              this.judgeMap.tileSize*this.judgeMap.h)
  105.           {
  106.             bgdy=MarioMIDlet.gameCanvas.height-
  107.               this.judgeMap.tileSize*this.judgeMap.h+this.judgeMap.y;
  108.           }
  109.           if((this.judgeMap.y<=0)&&y<MarioMIDlet.gameCanvas.height/4)
  110.           {
  111.             this.judgeMap.y=0;
  112.             bgdy=0;
  113.           }
  114.         }
  115.         else
  116.         {
  117.           bgdy=0;
  118.         }
  119.         if((allAction&LPKeyMask.MASK_KEY_LEFT)!=0)
  120.         {
  121.           this.isLeft=true;
  122.           if(--dx<-MOVE_SPEED)
  123.           {
  124.             dx=-MOVE_SPEED;
  125.           }
  126.           if(checkTileCollisionHorizon())
  127.           {
  128.             dx=0;
  129.           }
  130.         }
  131.         else if((allAction&LPKeyMask.MASK_KEY_RIGHT)!=0)
  132.         {
  133.           this.isLeft=false;
  134.           if(++dx>MOVE_SPEED)
  135.           {
  136.             dx=MOVE_SPEED;
  137.           }
  138.           if(checkTileCollisionHorizon())
  139.           {
  140.             dx=0;
  141.           }
  142.         }
  143.         else
  144.         {
  145.           if(dx>0)
  146.           {
  147.             if(checkTileCollisionHorizon())
  148.             {
  149.               dx=0;
  150.             }
  151.             else
  152.             {
  153.               --dx;
  154.             }
  155.           }
  156.           else if(dx<0)
  157.           {
  158.             if(checkTileCollisionHorizon())
  159.             {
  160.               dx=0;
  161.             }
  162.             else
  163.             {
  164.               ++dx;
  165.             }
  166.           }
  167.         }
  168.         if(!checkSpriteCollisionHorizon())
  169.         {
  170.           x+=dx;
  171.           if(dx<0)
  172.           {
  173.             if(distance>=-gm.canvas.width)
  174.             {
  175.               distance+=dx;
  176.             }
  177.           }
  178.           if(distance<0)
  179.           {
  180.             if(dx>0)
  181.             {
  182.               distance+=dx;
  183.             }
  184.           }
  185.         }
  186.         else
  187.         {
  188.           dx=0;
  189.         }
  190.         if(this.x!=MarioMIDlet.gameCanvas.width/4)
  191.         {
  192.           this.bgdx=MarioMIDlet.gameCanvas.width/4-x;
  193.           if(distance<-(gm.canvas.width-MarioMIDlet.gameCanvas.width/4))
  194.           {
  195.             bgdx=0;
  196.           }
  197.         }
  198.         else
  199.         {
  200.           bgdx=0;
  201.         }
  202.         if(judgeMap.x-bgdx<0
  203.            ||
  204.            judgeMap.x-bgdx>
  205.            judgeMap.tileSize*judgeMap.w-MarioMIDlet.gameCanvas.width
  206.           )
  207.         {
  208.           bgdx=0;
  209.         }
  210.         if(mainSpriteState==FIRE_SPRITE)
  211.         {
  212.           if((allAction&LPKeyMask.MASK_KEY_OK_FLAG)!=0)
  213.           {
  214.             fire();
  215.           }
  216.           checkBulletDamage();
  217.         }
  218.         x+=this.bgdx;
  219.         judgeMap.x-=this.bgdx;
  220.         y+=this.bgdy;
  221.         judgeMap.y-=this.bgdy;
  222.         int tmpDy=this.bgdy;
  223.         if(judgeMap.y<0)
  224.         {
  225.           tmpDy=bgdy+judgeMap.y;
  226.           this.bgdy=-judgeMap.y;
  227.           judgeMap.y=0;
  228.           y+=this.bgdy;
  229.         }
  230.         bgdy=tmpDy;
  231.         if(x<0)
  232.         {
  233.           x=0;
  234.         }
  235.         if(this.x>=MarioMIDlet.gameCanvas.width-32)
  236.         {
  237.           this.x=MarioMIDlet.gameCanvas.width-32;
  238.         }
  239.         if(isLeft)
  240.         {
  241.           offset=5;
  242.         }
  243.         else
  244.         {
  245.           offset=0;
  246.         }
  247.         if(dy!=0)
  248.         {
  249.           frameCnt=offset+3;
  250.         }
  251.         else if(((allAction&LPKeyMask.MASK_KEY_LEFT)!=0)
  252.                 ||((allAction&LPKeyMask.MASK_KEY_RIGHT)!=0))
  253.         {
  254.           walk();
  255.         }
  256.         else if(dy==0&&(allAction&LPKeyMask.MASK_KEY_UP_FLAG)==0)
  257.         {
  258.           frameCnt=offset;
  259.         }
  260.         if(isProtected)
  261.         {
  262.           isHidden=!isHidden;
  263.           if(protectCnt++==protectInterval)
  264.           {
  265.             protectCnt=0;
  266.             isProtected=false;
  267.             isHidden=false;
  268.           }
  269.         }
  270.         else
  271.         {
  272.           checkEnemyCollision();
  273.         }
  274.         if((allAction&LPKeyMask.MASK_KEY_OK_FLAG)!=0)
  275.         {
  276.           if(mainSpriteState==FIRE_SPRITE)
  277.           {
  278.             frameCnt=offset+1;
  279.           }
  280.           allAction&=~LPKeyMask.MASK_KEY_OK_FLAG;
  281.         }
  282.         checkStaticSpriteCollision();
  283.         if(y>this.judgeMap.tileSize*this.judgeMap.h)
  284.         {
  285.           if(gm.menu.isVolOn)
  286.           {
  287.             gm.beatPlayer.replay();
  288.           }
  289.           gm.gameState=MarioGameManage.GAMESTATE_REINIT;
  290.         }
  291.       }
  292.       break;
  293.     }
  294.   }
  295.   private void spriteDeadAction()
  296.   {
  297.     if(gm.menu.isVolOn)
  298.     {
  299.       gm.beatPlayer.replay();
  300.     }
  301.     if(mainSpriteState==SMALL_SPRITE)
  302.     {
  303.       mainSpriteState=DEAD_SPRITE;
  304.       return;
  305.     }
  306.     else
  307.     {
  308.       mainSpriteState=BECOME_SMALL;
  309.       isProtected=true;
  310.       this.protectCnt=0;
  311.       this.protectInterval=20;
  312.       return;
  313.     }
  314.   }
  315.   private void checkEnemyCollision()
  316.   {
  317.     int i;
  318.     switch(mainSpriteState)
  319.     {
  320.       case SMALL_SPRITE:
  321.         rect1.x = x+2;
  322.         rect1.y = y;
  323.         rect1.dx = 12;
  324.         rect1.dy = 16;
  325.         break;
  326.       case NORMAL_SPRITE:
  327.       case FIRE_SPRITE:
  328.         rect1.x = x+6;
  329.         rect1.y = y+2;
  330.         rect1.dx = 20;
  331.         rect1.dy = 30;
  332.         break;
  333.     }
  334.     rect2.dx = 14;
  335.     rect2.dy = 14;
  336.     for(i=gm.enemy.length-1;i>=0;--i)
  337.     {
  338.       if(!gm.enemy[i].isHidden)
  339.       {
  340.         if(gm.enemy[i].isCheck)
  341.         {
  342.           rect2.x = gm.enemy[i].x;
  343.           rect2.y = gm.enemy[i].y;
  344.           if(LPRect.IntersectRect(rect1,rect2))
  345.           {
  346.             spriteDeadAction();
  347.             return;
  348.           }
  349.         }
  350.       }
  351.     }
  352.     for(i=gm.tortoise.length-1;i>=0;--i)
  353.     {
  354.       if(!gm.tortoise[i].isHidden)
  355.       {
  356.         if(gm.tortoise[i].isCheck)
  357.         {
  358.           rect2.x=gm.tortoise[i].x;
  359.           rect2.y=gm.tortoise[i].y+8;
  360.           if(LPRect.IntersectRect(rect1,rect2))
  361.           {
  362.             if(Math.abs(rect1.y+rect1.dy-(rect2.y))>6)
  363.             {
  364.               spriteDeadAction();
  365.               return;
  366.             }
  367.           }
  368.         }
  369.       }
  370.     }
  371.   }
  372.   private void mainSpriteDamage()
  373.   {
  374.     if(dy>=0)
  375.     {
  376.       int i;
  377.       rect1.y=y;
  378.       rect2.dx=16;
  379.       rect2.dy=16;
  380.       if(mainSpriteState==SMALL_SPRITE)
  381.       {
  382.         rect1.x=x;
  383.         rect1.dx=16;
  384.         rect1.dy=16;
  385.       }
  386.       else
  387.       {
  388.         rect1.x=8;
  389.         rect1.dx=20;
  390.         rect1.dy=32;
  391.       }
  392.       for(i=gm.enemy.length-1;i>=0;--i)
  393.       {
  394.         if(!gm.enemy[i].isHidden)
  395.         {
  396.           if(gm.enemy[i].isCheck)
  397.           {
  398.             if((gm.enemy[i].y>=y+rect1.dy)
  399.                &&(gm.enemy[i].y<=y+dy+rect1.dy)
  400.                &&(x>gm.enemy[i].x-13)&&(x<=gm.enemy[i].x+10))
  401.             {
  402.               gm.enemy[i].changeState();
  403.               if(gm.menu.isVolOn)
  404.               {
  405.                 gm.beatPlayer.replay();
  406.               }
  407.             }
  408.           }
  409.         }
  410.       }
  411.       for(i=gm.tortoise.length-1;i>=0;--i)
  412.       {
  413.         if(!gm.tortoise[i].isHidden)
  414.         {
  415.           if((gm.tortoise[i].y+8>=y+rect1.dy)
  416.              &&(gm.tortoise[i].y+8<=y+dy+rect1.dy)
  417.              &&(x>gm.tortoise[i].x-13)&&(x<=gm.tortoise[i].x+10))
  418.           {
  419.             dy=-8;
  420.             gm.tortoise[i].changeState();
  421.             if(gm.menu.isVolOn)
  422.             {
  423.               gm.beatPlayer.replay();
  424.             }
  425.           }
  426.         }
  427.       }
  428.     }
  429.   }
  430.   private boolean checkStaticSpriteCollision()
  431.   {
  432.     int i;
  433.     rect2.dx = 16;
  434.     rect2.dy = 16;
  435.     switch(mainSpriteState)
  436.     {
  437.       case SMALL_SPRITE:
  438.         rect1.x=x+2;
  439.         rect1.y=y;
  440.         rect1.dx=14;
  441.         rect1.dy=16;
  442.         break;
  443.       default:
  444.         rect1.x=x+8;
  445.         rect1.y=y+1;
  446.         rect1.dx=16;
  447.         rect1.dy=31;
  448.         break;
  449.     }
  450.     rect2.dx = 14;
  451.     rect2.dy = 16;
  452.     for(i=gm.mashRooms.length-1;i>=0;--i)
  453.     {
  454.       if(!gm.mashRooms[i].isHidden)
  455.       {
  456.         switch(mainSpriteState)
  457.         {
  458.           case SMALL_SPRITE:
  459.             rect2.x = gm.mashRooms[i].x;
  460.             rect2.y = gm.mashRooms[i].y;
  461.             if(LPRect.IntersectRect(rect1,rect2))
  462.             {
  463.               if(gm.menu.isVolOn)
  464.               {
  465.                 gm.beatPlayer.replay();
  466.               }
  467.               if(gm.mashRooms[i].frameCnt==6)
  468.               {
  469.                 gm.mashRooms[i].isHidden=true;
  470.                 mainSpriteState=GROW_SPRITE;
  471.                 growCnt=0;
  472.                 return true;
  473.               }
  474.               else if(gm.mashRooms[i].frameCnt==8)
  475.               {
  476.                 // add a person
  477.                 gm.mashRooms[i].isHidden=true;
  478.                 return true;
  479.               }
  480.             }
  481.             break;
  482.           case NORMAL_SPRITE:
  483.           case FIRE_SPRITE:
  484.             rect2.x=gm.mashRooms[i].x;
  485.             rect2.y=gm.mashRooms[i].y;
  486.             if(LPRect.IntersectRect(rect1,rect2))
  487.             {
  488.               if(gm.mashRooms[i].frameCnt==8)
  489.               {
  490.                 if(gm.menu.isVolOn)
  491.                 {
  492.                   gm.beatPlayer.replay();
  493.                 }
  494.                 // add a person
  495.                 gm.mashRooms[i].isHidden=true;
  496.                 return true;
  497.               }
  498.             }
  499.             break;
  500.         }
  501.       }
  502.     }
  503.     rect2.dy = 10;
  504.     rect2.dx = 10;
  505.     for(i=gm.flowers.length-1;i>=0;--i)
  506.     {
  507.       if(!gm.flowers[i].isHidden)
  508.       {
  509.         rect2.x=gm.flowers[i].x+3;
  510.         rect2.y=gm.flowers[i].y+2;
  511.         switch(mainSpriteState)
  512.         {
  513.           case SMALL_SPRITE:
  514.             if (LPRect.IntersectRect(rect1, rect2))
  515.             {
  516.               if(gm.menu.isVolOn)
  517.               {
  518.                 gm.beatPlayer.replay();
  519.               }
  520.               gm.flowers[i].isHidden = true;
  521.               mainSpriteState = GROW_SPRITE;
  522.               return true;
  523.             }
  524.             break;
  525.           case NORMAL_SPRITE:
  526.             if(LPRect.IntersectRect(rect1,rect2))
  527.             {
  528.               if(gm.menu.isVolOn)
  529.               {
  530.                 gm.beatPlayer.replay();
  531.               }
  532.               gm.flowers[i].isHidden=true;
  533.               mainSpriteState=BECOME_FIRE;
  534.               return true;
  535.             }
  536.             break;
  537.           case FIRE_SPRITE:
  538.             if (LPRect.IntersectRect(rect1, rect2))
  539.             {
  540.               if(gm.menu.isVolOn)
  541.               {
  542.                 gm.beatPlayer.replay();
  543.               }
  544.               gm.flowers[i].isHidden = true;
  545.               mainSpriteState = FIRE_SPRITE;
  546.               return true;
  547.             }
  548.             break;
  549.         }
  550.       }
  551.     }
  552.     rect2.dx = 14;
  553.     rect2.dy = 14;
  554.     switch(gm.gameState)
  555.     {
  556.       case MarioGameManage.GAMESTATE_GAMELOOP:
  557.         for(i=gm.staticGold.length-1;i>=0;--i)
  558.         {
  559.           if(!gm.staticGold[i].isHidden)
  560.           {
  561.             rect2.x = gm.staticGold[i].x;
  562.             rect2.y = gm.staticGold[i].y;
  563.             if(LPRect.IntersectRect(rect1,rect2))
  564.             {
  565.               gm.staticGold[i].isHidden = true;
  566.               if(++gm.goldNum==100)
  567.               {
  568.                 gm.goldNum = 0;
  569.               }
  570.               if(gm.menu.isVolOn)
  571.               {
  572.                 gm.beatPlayer.replay();
  573.               }
  574.             }
  575.           }
  576.         }
  577.         break;
  578.     }
  579.     return false;
  580.   }
  581.   public void judgeKeyCode(int keyCode, int gameKeyCode)
  582.   {
  583.     switch (gameKeyCode)
  584.     {
  585.       case Canvas.UP:
  586.         if (dy == 0)
  587.         {
  588.           if ( ( ( (allAction & LPKeyMask.MASK_KEY_UP) == 0)
  589.                 && ( (allAction & LPKeyMask.MASK_KEY_UP_FLAG) == 0)))
  590.           {
  591.             allAction |= LPKeyMask.MASK_KEY_UP_FLAG | LPKeyMask.MASK_KEY_UP;
  592.             dy -= 18;
  593.           }
  594.         }
  595.         break;
  596.       case Canvas.FIRE:
  597.         if((((allAction&LPKeyMask.MASK_KEY_OK)==0)
  598.             &&((allAction&LPKeyMask.MASK_KEY_OK_FLAG)==0)))
  599.         {
  600.           allAction|=LPKeyMask.MASK_KEY_OK|LPKeyMask.MASK_KEY_OK_FLAG;
  601.         }
  602.         break;
  603.       case Canvas.LEFT:
  604.         allAction |= LPKeyMask.MASK_KEY_LEFT;
  605.         break;
  606.       case Canvas.RIGHT:
  607.         allAction |= LPKeyMask.MASK_KEY_RIGHT;
  608.         break;
  609.       default:
  610.         switch (keyCode)
  611.         {
  612.           case Canvas.KEY_NUM2:
  613.             if(dy==0)
  614.             {
  615.               if((((allAction&LPKeyMask.MASK_KEY_UP)==0)
  616.                   &&((allAction&LPKeyMask.MASK_KEY_UP_FLAG)==0)))
  617.               {
  618.                 allAction|=LPKeyMask.MASK_KEY_UP_FLAG|LPKeyMask.MASK_KEY_UP;
  619.                 dy-=18;
  620.               }
  621.             }
  622.             break;
  623.           case Canvas.KEY_NUM4: //left
  624.             allAction |= LPKeyMask.MASK_KEY_LEFT;
  625.             break;
  626.           case Canvas.KEY_NUM6: //right
  627.             allAction |= LPKeyMask.MASK_KEY_RIGHT;
  628.             break;
  629.           case Canvas.KEY_NUM5:
  630.             if((((allAction&LPKeyMask.MASK_KEY_OK)==0)
  631.                 &&((allAction&LPKeyMask.MASK_KEY_OK_FLAG)==0)))
  632.             {
  633.               allAction|=LPKeyMask.MASK_KEY_OK|LPKeyMask.MASK_KEY_OK_FLAG;
  634.             }
  635.             break;
  636.         }
  637.         break;
  638.     }
  639.   }
  640.   public void freeKey(int keyCode, int gameKeyCode)
  641.   {
  642.     switch (gameKeyCode)
  643.     {
  644.       case Canvas.FIRE:
  645.         allAction &= ~LPKeyMask.MASK_KEY_OK;
  646.         break;
  647.       case Canvas.UP:
  648.         allAction &= ~LPKeyMask.MASK_KEY_UP;
  649.         break;
  650.       case Canvas.DOWN:
  651.         allAction &= ~LPKeyMask.MASK_KEY_DOWN;
  652.         break;
  653.       case Canvas.LEFT:
  654.         allAction &= ~LPKeyMask.MASK_KEY_LEFT;
  655.         break;
  656.       case Canvas.RIGHT:
  657.         allAction &= ~LPKeyMask.MASK_KEY_RIGHT;
  658.         break;
  659.       default:
  660.         switch (keyCode)
  661.         {
  662.           case Canvas.KEY_NUM4: //left
  663.             allAction &= ~LPKeyMask.MASK_KEY_LEFT;
  664.             break;
  665.           case Canvas.KEY_NUM6:
  666.             allAction &= ~LPKeyMask.MASK_KEY_RIGHT; //right
  667.             break;
  668.           case Canvas.KEY_NUM2:
  669.             allAction &= ~LPKeyMask.MASK_KEY_UP; //jump
  670.             break;
  671.           case Canvas.KEY_NUM8:
  672.             allAction &= ~LPKeyMask.MASK_KEY_DOWN;
  673.             break;
  674.           case Canvas.KEY_NUM5:
  675.             allAction &= ~LPKeyMask.MASK_KEY_OK;
  676.             break;
  677.         }
  678.         break;
  679.     }
  680.   }
  681.   private void walk()
  682.   {
  683.     frameCnt++;
  684.     if (this.frameCnt > 3 + offset || this.frameCnt < 1 + offset)
  685.     {
  686.       this.frameCnt = 1 + offset;
  687.     }
  688.   }
  689.   private boolean checkTileCollisionVertical()
  690.   {
  691.     if (mainSpriteState == SMALL_SPRITE)
  692.     {
  693.       // 16X16
  694.       if (this.dy > 0)
  695.       {
  696.         isJumpOver = true;
  697.         for (int i = (y + this.judgeMap.y+15) /
  698.              this.judgeMap.tileSize+1;
  699.              i <= (y + this.judgeMap.y + dy) / this.judgeMap.tileSize+1; i++)
  700.         {
  701.           if (i < 0 || i > judgeMap.h - 1)
  702.           {
  703.             continue;
  704.           }
  705.           int xTile1 = (x + this.judgeMap.x + 2) / this.judgeMap.tileSize;
  706.           int xTile2 = (x + this.judgeMap.x + 14) / this.judgeMap.tileSize;
  707.           if (xTile2 > this.judgeMap.w - 1 || xTile1 < 0)
  708.           {
  709.             return false;
  710.           }
  711.           if ( ( (this.judgeMap.mapArray[i][xTile1] >> 8) & 0x02) == 0x02)
  712.           {
  713.             dy = (i - 1) * this.judgeMap.tileSize - (y + this.judgeMap.y);
  714.             allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
  715.             return true;
  716.           }
  717.           if ( ( (this.judgeMap.mapArray[i][xTile2] >> 8) & 0x02) == 0x02)
  718.           {
  719.             dy = (i - 1) * this.judgeMap.tileSize - (y + this.judgeMap.y);
  720.             allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
  721.             return true;
  722.           }
  723.         }
  724.       }
  725.       else if (dy < 0)
  726.       {
  727.         for (int i = (y + this.judgeMap.y + dy) / this.judgeMap.tileSize;
  728.              i <= (y + this.judgeMap.y) / this.judgeMap.tileSize; i++)
  729.         {
  730.           if (i < 0 || i > judgeMap.h - 1)
  731.           {
  732.             continue;
  733.           }
  734.           int xTile1 = (x + this.judgeMap.x + 2) / this.judgeMap.tileSize;
  735.           int xTile2 = (x + this.judgeMap.x + 14) / this.judgeMap.tileSize;
  736.           if (xTile2 > this.judgeMap.w - 1 || xTile1 < 0)
  737.           {
  738.             return false;
  739.           }
  740.           if ( ( (this.judgeMap.mapArray[i][xTile1] >> 8) & 0x08) == 0x08)
  741.           {
  742.             dy = 0;
  743.             allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
  744.             if(isJumpOver)
  745.             {
  746.               changeUpSpriteState();
  747.               isJumpOver =false;
  748.             }
  749.             return true;
  750.           }
  751.           if ( ( (this.judgeMap.mapArray[i][xTile2] >> 8) & 0x08) == 0x08)
  752.           {
  753.             dy = 0;
  754.             if(isJumpOver)
  755.             {
  756.               changeUpSpriteState();
  757.               isJumpOver =false;
  758.             }
  759.             allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
  760.             return true;
  761.           }
  762.           if ( ( (this.judgeMap.mapArray[i][xTile1] >> 8) & 0x01) == 0x01)
  763.           {
  764.             dy = 0;
  765.             allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
  766.             return true;
  767.           }
  768.           if ( ( (this.judgeMap.mapArray[i][xTile2] >> 8) & 0x01) == 0x01)
  769.           {
  770.             dy = 0;
  771.             allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
  772.             return true;
  773.           }
  774.         }
  775.       }
  776.       else
  777.       {
  778.         isJumpOver = true;
  779.       }
  780.     }
  781.     else
  782.     {
  783.       //32 X 32
  784.       if (this.dy > 0)
  785.       {
  786.         isJumpOver = true;
  787.         for (int i = (y + this.judgeMap.y+15) /
  788.              this.judgeMap.tileSize + 2;
  789.              i <= (y + this.judgeMap.y + dy) / this.judgeMap.tileSize + 2; i++)
  790.         {
  791.           if (i < 0 || i > judgeMap.h - 1)
  792.           {
  793.             continue;
  794.           }
  795.           int xTile1 = (x + this.judgeMap.x + 12) / this.judgeMap.tileSize;
  796.           int xTile2 = (x + this.judgeMap.x + 20) / this.judgeMap.tileSize;
  797.           if (xTile2 > this.judgeMap.w - 1 || xTile1 < 0)
  798.           {
  799.             return false;
  800.           }
  801.           if ( ( (this.judgeMap.mapArray[i][xTile1] >> 8) & 0x02) == 0x02)
  802.           {
  803.             dy = (i - 2) * this.judgeMap.tileSize - (y + this.judgeMap.y);
  804.             allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
  805.             return true;
  806.           }
  807.           if ( ( (this.judgeMap.mapArray[i][xTile2] >> 8) & 0x02) == 0x02)
  808.           {
  809.             dy = (i - 2) * this.judgeMap.tileSize - (y + this.judgeMap.y);
  810.             allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
  811.             return true;
  812.           }
  813.         }
  814.       }
  815.       else if (dy < 0)
  816.       {
  817.         for (int i = (y + this.judgeMap.y + dy) / this.judgeMap.tileSize;
  818.              i <= (y + this.judgeMap.y ) / this.judgeMap.tileSize; i++)
  819.         {
  820.           if (i < 0 || i > judgeMap.h - 1)
  821.           {
  822.             continue;
  823.           }
  824.           int xTile1 = (x + this.judgeMap.x + 12) / this.judgeMap.tileSize;
  825.           int xTile2 = (x + this.judgeMap.x + 20) / this.judgeMap.tileSize;
  826.           if (xTile2 > this.judgeMap.w - 1 || xTile1 < 0)
  827.           {
  828.             return false;
  829.           }
  830.           if ( ( (this.judgeMap.mapArray[i][xTile1] >> 8) & 0x08) == 0x08)
  831.           {
  832.             dy = 0;
  833.             allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
  834.             if (isJumpOver)
  835.             {
  836.               judgeMap.mapArray[i][xTile1] = judgeMap.mapArray[0][0];
  837.               gm.createBrokenBrick(x + 10, y - 5, -5, -12);
  838.               gm.createBrokenBrick(x + 10, y - 5, 5, -12);
  839.               gm.createBrokenBrick(x + 10, y - 5, -5, -6);
  840.               gm.createBrokenBrick(x + 10, y - 5, 5, -6);
  841.               isJumpOver = false;
  842.             }
  843.             return true;
  844.           }
  845.           if ( ( (this.judgeMap.mapArray[i][xTile2] >> 8) & 0x08) == 0x08)
  846.           {
  847.             dy = 0;
  848.             allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
  849.             if (isJumpOver)
  850.             {
  851.               judgeMap.mapArray[i][xTile2] = judgeMap.mapArray[0][0];
  852.               gm.createBrokenBrick(x + 10, y - 5, -5, -12);
  853.               gm.createBrokenBrick(x + 10, y - 5, 5, -12);
  854.               gm.createBrokenBrick(x + 10, y - 5, -5, -6);
  855.               gm.createBrokenBrick(x + 10, y - 5, 5, -6);
  856.               isJumpOver = false;
  857.             }
  858.             return true;
  859.           }
  860.           if ( ( (this.judgeMap.mapArray[i][xTile1] >> 8) & 0x01) == 0x01)
  861.           {
  862.             dy = 0;
  863.             allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
  864.             return true;
  865.           }
  866.           if ( ( (this.judgeMap.mapArray[i][xTile2] >> 8) & 0x01) == 0x01)
  867.           {
  868.             dy = 0;
  869.             allAction &= ~LPKeyMask.MASK_KEY_UP_FLAG;
  870.             return true;
  871.           }
  872.         }
  873.       }
  874.       else
  875.       {
  876.         isJumpOver = true;
  877.       }
  878.     }
  879.     return false;
  880.   }
  881.   private boolean checkTileCollisionHorizon()
  882.   {
  883.     int i;
  884.     if (mainSpriteState == SMALL_SPRITE)
  885.     {
  886.       rect1.y = this.y + this.judgeMap.y;
  887.       rect1.dx = 16;
  888.       rect1.dy = 16;
  889.       rect2.dx = 16;
  890.       rect2.dy = 16;
  891.       rect1.x = x + judgeMap.x + dx;
  892.       if (dx<0)
  893.       {
  894.         i = (x + judgeMap.x + dx) / judgeMap.tileSize;
  895.       }
  896.       else
  897.       {
  898.         i = (x + judgeMap.x + dx) / judgeMap.tileSize + 1;
  899.       }
  900.       if (i < 0 || i > this.judgeMap.w - 1)
  901.         return false;
  902.       int yTile1 = (y + judgeMap.y) / judgeMap.tileSize;
  903.       int yTile2 = (y + judgeMap.y) / judgeMap.tileSize+1;
  904.       if (yTile1 < 0 || yTile2 > judgeMap.h - 1)
  905.         return false;
  906.       if(dx>0)
  907.       {
  908.         if(((this.judgeMap.mapArray[yTile1][i]>>8)&0x10)==0x10)
  909.         {
  910.           rect2.x=i*16;
  911.           rect2.y=yTile1*16;
  912.           if(LPRect.IntersectRect(rect1,rect2))
  913.           {
  914.             return true;
  915.           }
  916.         }
  917.       }
  918.       if(((this.judgeMap.mapArray[yTile1][i]>>8)&0x04)==0x04)
  919.       {
  920.         rect2.x = i * 16;
  921.         rect2.y = yTile1 * 16;
  922.         if (LPRect.IntersectRect(rect1, rect2))
  923.         {
  924.           return true;
  925.         }
  926.       }
  927.       if ( ( (this.judgeMap.mapArray[yTile2][i] >> 8) & 0x04) == 0x04)
  928.       {
  929.         rect2.x = i * 16;
  930.         rect2.y = yTile2 * 16;
  931.         if (LPRect.IntersectRect(rect1, rect2))
  932.         {
  933.           return true;
  934.         }
  935.       }
  936.     }
  937.     else
  938.     {
  939.       rect1.y = this.y + this.judgeMap.y+1;
  940.       rect1.dx = 16;
  941.       rect1.dy = 31;
  942.       rect2.dx = 16;
  943.       rect2.dy = 16;
  944.       if (dx<0)
  945.       {
  946.         rect1.x = x + judgeMap.x +6+dx;
  947.         i = (x + judgeMap.x +6+dx) / judgeMap.tileSize;
  948.       }
  949.       else
  950.       {
  951.         rect1.x = x + judgeMap.x +20+dx;
  952.         i = (x + judgeMap.x +20+dx) / judgeMap.tileSize ;
  953.       }
  954.       if (i < 0 || i > this.judgeMap.w - 1)
  955.         return false;
  956.       int yTile1 = (y + judgeMap.y) / judgeMap.tileSize;
  957.       int yTile2 = (y + judgeMap.y) / judgeMap.tileSize + 1;
  958.       int yTile3 = (y + judgeMap.y) / judgeMap.tileSize + 2;
  959.       if (yTile1 < 0 || yTile3 > judgeMap.h - 1)
  960.         return false;
  961.       if(dx>0)
  962.       {
  963.         boolean isCheck = false;;
  964.         if(((this.judgeMap.mapArray[yTile1][i]>>8)&0x10)==0x10)
  965.         {
  966.           rect2.x=i*16;
  967.           rect2.y=yTile1*16;
  968.           if(LPRect.IntersectRect(rect1,rect2))
  969.           {
  970.            isCheck = true;
  971.           }
  972.         }
  973.         if(isCheck)
  974.         {
  975.           if(((this.judgeMap.mapArray[yTile2][i]>>8)&0x10)==0x10)
  976.           {
  977.             rect2.x=i*16;
  978.             rect2.y=yTile2*16;
  979.             if(LPRect.IntersectRect(rect1,rect2))
  980.             {
  981.               return true;
  982.             }
  983.           }
  984.         }
  985.       }
  986.       if(((this.judgeMap.mapArray[yTile1][i]>>8)&0x04)==0x04)
  987.       {
  988.         rect2.x = i * 16;
  989.         rect2.y = yTile1 * 16;
  990.         if (LPRect.IntersectRect(rect1, rect2))
  991.         {
  992.           return true;
  993.         }
  994.       }
  995.       if ( ( (this.judgeMap.mapArray[yTile2][i] >> 8) & 0x04) == 0x04)
  996.       {
  997.         rect2.x = i * 16;
  998.         rect2.y = yTile2 * 16;
  999.         if (LPRect.IntersectRect(rect1, rect2))
  1000.         {
  1001.           return true;
  1002.         }
  1003.       }
  1004.       if ( ( (this.judgeMap.mapArray[yTile3][i] >> 8) & 0x04) == 0x04)
  1005.       {
  1006.         rect2.x = i * 16;
  1007.         rect2.y = yTile3 * 16;
  1008.         if (LPRect.IntersectRect(rect1, rect2))
  1009.         {
  1010.           return true;
  1011.         }
  1012.       }
  1013.     }
  1014.     return false;
  1015.   }
  1016.   private void fire()
  1017.   {
  1018.     if(isLeft)
  1019.     {
  1020.       gm.createBullet(x+16,y+16,-(MOVE_SPEED+4),0);
  1021.     }
  1022.     else
  1023.     {
  1024.       gm.createBullet(x+16,y+16,(MOVE_SPEED+4),0);
  1025.     }
  1026.   }
  1027.   private boolean checkSpriteCollisionVertical()
  1028.   {
  1029.     int i;
  1030.     if (mainSpriteState == SMALL_SPRITE)
  1031.     {
  1032.       if (dy > 0)
  1033.       {
  1034.         isJumpOver = true;
  1035.         switch(gm.gameState)
  1036.         {
  1037.           case MarioGameManage.GAMESTATE_GAMELOOP:
  1038.             for(i=gm.brick.length-1;i>=0;--i)
  1039.             {
  1040.               if(!gm.brick[i].isHidden)
  1041.               {
  1042.                 if(((y+16)<=gm.brick[i].y)&&
  1043.                    ((y+dy+16)>=gm.brick[i].y)
  1044.                    &&(x>=gm.brick[i].x-13)&&(x<=gm.brick[i].x+10))
  1045.                 {
  1046.                   dy=gm.brick[i].y-(y+16);
  1047.                   allAction&=~LPKeyMask.MASK_KEY_UP_FLAG;
  1048.                   return true;
  1049.                 }
  1050.               }
  1051.             }
  1052.             for(i=gm.stick.length-1;i>=0;--i)
  1053.             {
  1054.               if(!gm.stick[i].isHidden)
  1055.               {
  1056.                 if(((y+16)<=gm.stick[i].y)&&
  1057.                    ((y+dy+16)>=gm.stick[i].y)
  1058.                    &&(x>=gm.stick[i].x-13)&&(x<=gm.stick[i].x+42))
  1059.                 {
  1060.                   gm.stick[i].isMainSpriteMove=true;
  1061.                   gm.stick[i].isDown = true;
  1062.                   dy=gm.stick[i].y-(y+16);
  1063.                   this.allAction&=~LPKeyMask.MASK_KEY_UP_FLAG;
  1064.                   return true;
  1065.                 }
  1066.                 else
  1067.                 {
  1068.                   gm.stick[i].isMainSpriteMove=false;
  1069.                   gm.stick[i].isDown = false;
  1070.                 }
  1071.               }
  1072.             }
  1073.             for(i=gm.bridge.length-1;i>=0;--i)
  1074.             {
  1075.               if(!gm.bridge[i].isHidden)
  1076.               {
  1077.                 if(((y+16)<=gm.bridge[i].y)&&
  1078.                    ((y+dy+16)>=gm.bridge[i].y)
  1079.                    &&(x>=gm.bridge[i].x-13)&&(x<=gm.bridge[i].x+10))
  1080.                 {
  1081.                   gm.bridge[i].isDown=true;
  1082.                   dy=gm.bridge[i].y-(y+16);
  1083.                   allAction&=~LPKeyMask.MASK_KEY_UP_FLAG;
  1084.                   return true;
  1085.                 }
  1086.               }
  1087.             }
  1088.             break;
  1089.         }
  1090.       }
  1091.       else if(dy<0)
  1092.       {
  1093.         switch(gm.gameState)
  1094.         {
  1095.           case MarioGameManage.GAMESTATE_GAMELOOP:
  1096.             for(i=gm.brick.length-1;i>=0;--i)
  1097.             {
  1098.               if(((y)>=gm.brick[i].y+16)&&
  1099.                  ((y+dy)<=gm.brick[i].y+16)
  1100.                  &&(x>=gm.brick[i].x-13)&&(x<=gm.brick[i].x+10))
  1101.               {
  1102.                 dy=gm.brick[i].y+16-y;
  1103.                 if(isJumpOver)
  1104.                 {
  1105.                   if(gm.brick[i].frameCnt!=0)
  1106.                   {
  1107.                     changeUpSpriteState();
  1108.                   }
  1109.                   gm.brick[i].createGem(gm);
  1110.                   isJumpOver=false;
  1111.                 }
  1112.                 allAction&=~LPKeyMask.MASK_KEY_UP_FLAG;
  1113.                 return true;
  1114.               }
  1115.             }
  1116.             break;
  1117.         }
  1118.       }
  1119.       else
  1120.       {
  1121.         isJumpOver = true;
  1122.       }
  1123.     }
  1124.     else
  1125.     {
  1126.       if (dy > 0)
  1127.       {
  1128.         isJumpOver = true;
  1129.         switch(gm.gameState)
  1130.         {
  1131.           case MarioGameManage.GAMESTATE_GAMELOOP:
  1132.             for(i=gm.brick.length-1;i>=0;--i)
  1133.             {
  1134.               if(!gm.brick[i].isHidden)
  1135.               {
  1136.                 if(((y+32)<=gm.brick[i].y)&&
  1137.                    ((y+dy+32)>=gm.brick[i].y)
  1138.                    &&(x>=gm.brick[i].x-20)&&(x<=gm.brick[i].x+6))
  1139.                 {
  1140.                   dy=gm.brick[i].y-(y+32);
  1141.                   allAction&=~LPKeyMask.MASK_KEY_UP_FLAG;
  1142.                   return true;
  1143.                 }
  1144.               }
  1145.             }
  1146.             for(i=gm.stick.length-1;i>=0;--i)
  1147.             {
  1148.               if(!gm.stick[i].isHidden)
  1149.               {
  1150.                 if(((y+32)<=gm.stick[i].y)&&
  1151.                    ((y+dy+32)>=gm.stick[i].y)
  1152.                    &&(x>=gm.stick[i].x-20)&&(x<=gm.stick[i].x+38))
  1153.                 {
  1154.                   gm.stick[i].isMainSpriteMove=true;
  1155.                   dy=gm.stick[i].y-(y+32);
  1156.                   this.allAction&=~LPKeyMask.MASK_KEY_UP_FLAG;
  1157.                   return true;
  1158.                 }
  1159.                 else
  1160.                 {
  1161.                   gm.stick[i].isMainSpriteMove=false;
  1162.                 }
  1163.               }
  1164.             }
  1165.             for(i=gm.bridge.length-1;i>=0;--i)
  1166.             {
  1167.               if(!gm.bridge[i].isHidden)
  1168.               {
  1169.                 if(((y+32)<=gm.bridge[i].y)&&
  1170.                    ((y+dy+32)>=gm.bridge[i].y)
  1171.                    &&(x>=gm.bridge[i].x-20)&&(x<=gm.bridge[i].x+6))
  1172.                 {
  1173.                   gm.bridge[i].isDown = true;
  1174.                   dy=gm.bridge[i].y-(y+32);
  1175.                   allAction&=~LPKeyMask.MASK_KEY_UP_FLAG;
  1176.                   return true;
  1177.                 }
  1178.               }
  1179.             }
  1180.             break;
  1181.         }
  1182.       }
  1183.       else if(dy<0)
  1184.       {
  1185.         switch(gm.gameState)
  1186.         {
  1187.           case MarioGameManage.GAMESTATE_GAMELOOP:
  1188.             for(i=gm.brick.length-1;i>=0;--i)
  1189.             {
  1190.               if(((y)>=gm.brick[i].y+16)&&
  1191.                  ((y+dy)<=gm.brick[i].y+16)
  1192.                  &&(x>=gm.brick[i].x-20)&&(x<=gm.brick[i].x+6))
  1193.               {
  1194.                 dy=gm.brick[i].y+16-y;
  1195.                 if(isJumpOver)
  1196.                 {
  1197.                   gm.brick[i].createGem(gm);
  1198.                   isJumpOver=false;
  1199.                 }
  1200.                 allAction&=~LPKeyMask.MASK_KEY_UP_FLAG;
  1201.                 return true;
  1202.               }
  1203.             }
  1204.             break;
  1205.         }
  1206.       }
  1207.       else
  1208.       {
  1209.         isJumpOver = true;
  1210.       }
  1211.     }
  1212.     return false;
  1213.   }
  1214.   private boolean checkSpriteCollisionHorizon()
  1215.   {
  1216.     if(gm.gameState==MarioGameManage.GAMESTATE_GAMELOOP)
  1217.     {
  1218.       int i;
  1219.       if(mainSpriteState==SMALL_SPRITE)
  1220.       {
  1221.         rect1.x=x;
  1222.         rect1.y=y;
  1223.         rect1.dx=16;
  1224.         rect1.dy=16;
  1225.       }
  1226.       else
  1227.       {
  1228.         rect1.x=x+6;
  1229.         rect1.y=y;
  1230.         rect1.dx=16;
  1231.         rect1.dy=32;
  1232.       }
  1233.       for(i=gm.tortoise.length-1;i>=0;--i)
  1234.       {
  1235.         if(!gm.tortoise[i].isHidden)
  1236.         {
  1237.           if(gm.tortoise[i].isPushable)
  1238.           {
  1239.             rect2.x=gm.tortoise[i].x;
  1240.             rect2.y=gm.tortoise[i].y+8;
  1241.             rect2.dx=16;
  1242.             rect2.dy=16;
  1243.             if(LPRect.IntersectRect(rect1,rect2))
  1244.             {
  1245.               gm.tortoise[i].changeState();
  1246.             }
  1247.           }
  1248.         }
  1249.       }
  1250.       rect1.x+=dx;
  1251.       for(i=gm.brick.length-1;i>=0;--i)
  1252.       {
  1253.         if(!gm.brick[i].isHidden)
  1254.         {
  1255.           rect2.x=gm.brick[i].x;
  1256.           rect2.y=gm.brick[i].y;
  1257.           rect2.dx=16;
  1258.           rect2.dy=16;
  1259.           if(LPRect.IntersectRect(rect1,rect2))
  1260.           {
  1261.             return true;
  1262.           }
  1263.         }
  1264.       }
  1265.     }
  1266.     return false;
  1267.   }
  1268.   private void checkBulletDamage()
  1269.   {
  1270.     int i,j;
  1271.     rect1.dx = 8;
  1272.     rect1.dy = 8;
  1273.     rect2.dx = 16;
  1274.     rect2.dy = 16;
  1275.     for(i=gm.bullet.length-1;i>=0;--i)
  1276.     {
  1277.       label_1:
  1278.       if(!gm.bullet[i].isHidden)
  1279.       {
  1280.         rect1.x = gm.bullet[i].x;
  1281.         rect1.y = gm.bullet[i].y;
  1282.         for(j=gm.enemy.length-1;j>=0;--j)
  1283.         {
  1284.           if(!gm.enemy[j].isHidden)
  1285.           {
  1286.             if(gm.enemy[j].isCheck)
  1287.             {
  1288.               rect2.x=gm.enemy[j].x;
  1289.               rect2.y=gm.enemy[j].y;
  1290.               if(LPRect.IntersectRect(rect1,rect2))
  1291.               {
  1292.                 gm.enemy[j].changeDirection();
  1293.                 gm.bullet[i].isHidden = true;
  1294.                 break label_1;
  1295.               }
  1296.             }
  1297.           }
  1298.         }
  1299.         for(j=gm.tortoise.length-1;j>=0;--j)
  1300.         {
  1301.           if(!gm.tortoise[j].isHidden)
  1302.           {
  1303.             if(gm.tortoise[j].isCheck)
  1304.             {
  1305.               rect2.x = gm.tortoise[j].x;
  1306.               rect2.y = gm.tortoise[j].y+8;
  1307.               if(LPRect.IntersectRect(rect1,rect2))
  1308.               {
  1309.                 gm.tortoise[j].changeDirection();
  1310.                 gm.bullet[i].isHidden = true;
  1311.                 break label_1;
  1312.               }
  1313.             }
  1314.           }
  1315.         }
  1316.       }
  1317.     }
  1318.   }
  1319.   public void init()
  1320.   {
  1321.     x = 0;
  1322.     y = 0;
  1323.     dy = 0;
  1324.     dx = 0;
  1325.     bgdx = 0;
  1326.     bgdy = 0;
  1327.     isLeft = false;
  1328.     allAction = 0;
  1329.     mainSpriteState = SMALL_SPRITE;
  1330.     distance = 0;
  1331.     isJumpOver = true;
  1332.     isProtected = false;
  1333.     isHidden = false;
  1334.   }
  1335.   private void changeUpSpriteState()
  1336.   {
  1337.     int i;
  1338.     rect1.x = x;
  1339.     rect1.y = y-20;
  1340.     rect1.dx = 16;
  1341.     rect1.dy = 16;
  1342.     rect2.dx = 16;
  1343.     rect2.dy = 16;
  1344.     for(i=gm.mashRooms.length-1;i>=0;--i)
  1345.     {
  1346.       if(!gm.mashRooms[i].isHidden)
  1347.       {
  1348.         rect2.x = gm.mashRooms[i].x;
  1349.         rect2.y = gm.mashRooms[i].y;
  1350.         if(LPRect.IntersectRect(rect1,rect2))
  1351.         {
  1352.           gm.mashRooms[i].changeDirection();
  1353.         }
  1354.       }
  1355.     }
  1356.     for(i=gm.enemy.length-1;i>=0;--i)
  1357.     {
  1358.       if(!gm.enemy[i].isHidden)
  1359.       {
  1360.         if(gm.enemy[i].isCheck)
  1361.         {
  1362.           rect2.x=gm.enemy[i].x;
  1363.           rect2.y=gm.enemy[i].y;
  1364.           if(LPRect.IntersectRect(rect1,rect2))
  1365.           {
  1366.             gm.enemy[i].changeDirection();
  1367.           }
  1368.         }
  1369.       }
  1370.     }
  1371.     for(i=gm.tortoise.length-1;i>=0;--i)
  1372.     {
  1373.       if(!gm.tortoise[i].isHidden)
  1374.       {
  1375.         if(gm.tortoise[i].isCheck)
  1376.         {
  1377.           rect2.x=gm.tortoise[i].x;
  1378.           rect2.y=gm.tortoise[i].y;
  1379.           if(LPRect.IntersectRect(rect1,rect2))
  1380.           {
  1381.             gm.tortoise[i].changeDirection();
  1382.           }
  1383.         }
  1384.       }
  1385.     }
  1386.   }
  1387.   public void readData(DataInputStream dis)
  1388.     throws java.io.IOException
  1389.   {
  1390.     super.readData(dis);
  1391.     dx = dis.readInt();
  1392.     dy = dis.readInt();
  1393.     bgdx = dis.readInt();
  1394.     bgdy = dis.readInt();
  1395.     growCnt = dis.readInt();
  1396.     //allAction = dis.readInt();
  1397.     mainSpriteState = dis.readInt();
  1398.     becomeCnt = dis.readInt();
  1399.     protectInterval = dis.readInt();
  1400.     protectCnt = dis.readInt();
  1401.     isLeft = dis.readBoolean();
  1402.     isProtected = dis.readBoolean();
  1403.     deadCnt = dis.readInt();
  1404.     distance = dis.readInt();
  1405.   }
  1406.   public void writeData(DataOutputStream dos)
  1407.     throws java.io.IOException
  1408.   {
  1409.     super.writeData(dos);
  1410.     dos.writeInt(dx);
  1411.     dos.writeInt(dy);
  1412.     dos.writeInt(bgdx);
  1413.     dos.writeInt(bgdy);
  1414.     dos.writeInt(growCnt);
  1415.     dos.writeInt(mainSpriteState);
  1416.     dos.writeInt(becomeCnt);
  1417.     dos.writeInt(protectInterval);
  1418.     dos.writeInt(protectCnt);
  1419.     dos.writeBoolean(isLeft);
  1420.     dos.writeBoolean(isProtected);
  1421.     dos.writeInt(deadCnt);
  1422.     dos.writeInt(distance);
  1423.   }
  1424. // property
  1425. //pubilc
  1426.   public int dx;
  1427.   public int dy;
  1428.   public int bgdx;
  1429.   public int bgdy;
  1430.   public LPMaps judgeMap;
  1431.   public int growCnt;
  1432.   public int allAction;
  1433.   public int mainSpriteState;
  1434.   public int becomeCnt;
  1435. //private
  1436.   private LPRect rect1 = new LPRect();
  1437.   private LPRect rect2 = new LPRect();
  1438.   private boolean isJumpOver;
  1439.   private int protectInterval;
  1440.   private int protectCnt;
  1441.   private MarioGameManage gm;
  1442.   private boolean isLeft;
  1443.   private boolean isProtected;
  1444.   private int deadCnt;
  1445.   private int distance;
  1446.   //final
  1447.   private static final int MOVE_SPEED = 6;
  1448.   // main sprite's state
  1449.   public static final int SMALL_SPRITE = 0x01;
  1450.   public static final int NORMAL_SPRITE = 0x02;
  1451.   public static final int FIRE_SPRITE = 0x04;
  1452.   public static final int GROW_SPRITE = 0x08;
  1453.   public static final int BECOME_FIRE = 0x10;
  1454.   public static final int DEAD_SPRITE = 0x20;
  1455.   public static final int BECOME_SMALL = 0x40;
  1456. }