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

📄 tom.java

📁 java 小程序 使用j2me 开发的一个小的游戏软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import javax.microedition.lcdui.*;

public class Tom
{
    public static int life=3;
    public int time;
    public int baby;

    public int x,y,frame;
    private int[] grid = new int[2];
    private static final int maxtime = 100;
    private boolean isdraw;
    private int timecount = 1;
    private int jumpcount = 1;
    private int hitcount = 1;
    private int drillcount = 1;
    private int pushcount = 1;
    private int fallstep = 5;
    private TomAdventureCanvas canvas;

    public int direct;
    public int status;
    public static final byte LEFT = 1;
    public static final byte RIGHT = 2;
    public static final byte GO_LEFT = 3;
    public static final byte GO_RIGHT = 4;
    public static final byte FALL_LEFT = 5;
    public static final byte FALL_RIGHT = 6;
    public static final byte JUMP_LEFT = 7;
    public static final byte JUMP_RIGHT = 8;
    public static final byte HIT_LEFT = 9;
    public static final byte HIT_RIGHT = 10;
    public static final byte JUMPHIT_LEFT = 11;
    public static final byte JUMPHIT_RIGHT = 12;
    public static final byte DRILL_LEFT = 13;
    public static final byte DRILL_RIGHT = 14;

    public Tom(TomAdventureCanvas cs,int startx,int starty)
    {
        canvas = cs;
        baby = 0;
        time = 100;
        frame = 2;
        direct = 0;
        status = LEFT;
        x = startx;
        y = starty;
    }

    public int left_move()
    {
        int ret = 0;
        grid = TomAdventureCanvas.whichGrid(x,y,11,15);
        if(!TomAdventureCanvas.onGround(grid[0],grid[1]))
        {
            x = x - 5;
            status = FALL_LEFT;
        }
        else
        {
            //判断是否走在云上,是则改变云的状态
            if(TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -1][grid[1]+2][grid[0]]==10 ||
               TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -1][grid[1]+2][grid[0]]==11)
            {
                canvas.map[(grid[1]+1) *
                    TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -
                    1][0][2] + grid[0]].status = 1;
            }
        }

        if(x>-11)
        {
            if(!TomAdventureCanvas.isBlock(x,y,11,15,-2))
            {
                x = x - 2;
                pushcount = 1;
            }
            else //判断是否遇到石头
            {
                if(grid[0]==0)
                {
                    if(TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][grid[1]+1][TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][2]-1]==18 ||
                       TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][grid[1]+1][TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][2]-1]==19)
                    {
                        if(pushcount<10)
                        {
                            pushcount++;
                        }
                        else
                        {
                            canvas.map[TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -1][0][2]*(grid[1]+1)-1].status = 3;
                            pushcount = 1;
                        }
                    }
                }
                else
                {
                    if(TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][grid[1]+1][grid[0]-1]==18 ||
                       TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][grid[1]+1][grid[0]-1]==19)
                    {
                        if(pushcount<10)
                        {
                            pushcount++;
                        }
                        else
                        {
                            canvas.map[TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -1][0][2]*grid[1]+grid[0]-1].status = 3;
                            pushcount = 1;
                        }
                    }
                }
            }
        }
        else
        {
            x = TomAdventureCanvas.mapw - 11;
            ret = 1;
        }
        if(TomAdventureCanvas.mapx-2>=0 && !TomAdventureCanvas.isBlock(x,y,11,15,-2))
        {
            if(x<TomAdventureCanvas.mapw-TomAdventureCanvas.vieww/2)
            {
                TomAdventureCanvas.mapx = TomAdventureCanvas.mapx - 2;
            }
        }
        if (frame < 3)
        {
            frame++;
        }
        else
        {
            frame = 1;
        }

        return ret;
    }

    public int right_move()
    {
        int ret = 0;
        grid = TomAdventureCanvas.whichGrid(x,y,11,15);
        if(!TomAdventureCanvas.onGround(grid[0],grid[1]))
        {
            x = x + 5;
            status = FALL_RIGHT;
        }
        else
        {
            if(TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -1][grid[1]+2][grid[0]]==10 ||
               TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -1][grid[1]+2][grid[0]]==11)
            {
                //判断是否走在云上,是则改变云的状态
                canvas.map[(grid[1]+1) *
                    TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -
                    1][0][2] + grid[0]].status = 1;
            }
        }

        if(x+2<TomAdventureCanvas.mapw)
        {
            if(!TomAdventureCanvas.isBlock(x,y,11,15,2))
            {
                x = x + 2;
                pushcount = 1;
            }
            else //判断是否遇到石头
            {
                if(grid[0]==TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][2]-1)
                {
                    if(TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][grid[1]+1][0]==18 ||
                       TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][grid[1]+1][0]==19)
                    {
                        if(pushcount<10)
                        {
                            pushcount++;
                        }
                        else
                        {
                            canvas.map[TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -1][0][2]*grid[1]].status = 4;
                            pushcount = 1;
                        }
                    }
                }
                else
                {
                    if(TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][grid[1]+1][grid[0]+1]==18 ||
                       TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][grid[1]+1][grid[0]+1]==19)
                    {
                        if(pushcount<10)
                        {
                            pushcount++;
                        }
                        else
                        {
                            canvas.map[TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -1][0][2]*grid[1]+grid[0]+1].status = 4;
                            pushcount = 1;
                        }
                    }
                }
            }
        }
        else
        {
            x = 0;
            ret = 1;
        }
        if(TomAdventureCanvas.mapx<TomAdventureCanvas.mapw-TomAdventureCanvas.vieww
            && !TomAdventureCanvas.isBlock(x,y,11,15,2))
        {
            if(x>=0+TomAdventureCanvas.vieww/2)
            {
                TomAdventureCanvas.mapx = TomAdventureCanvas.mapx + 2;
            }
        }
        if (frame < 3)
        {
            frame++;
        }
        else
        {
            frame = 1;
        }

        return ret;
    }

    public int jump_left()
    {
        int ret = 0;
        frame = 1;
        if(jumpcount>=0 && jumpcount<=2)
        {
            if (x > -5)
            {
                if(!TomAdventureCanvas.isBlock(x,y,11,15,-3))
                {
                    x = x - 3;
                }
                if(jumpcount != 2)
                {
                    y = y - 8;
                }
                else
                {
                    y = y - 7;
                }
                if(TomAdventureCanvas.mapy-8>=0)
                {
                    if(y<TomAdventureCanvas.maph-TomAdventureCanvas.viewh/2)
                    {
                        TomAdventureCanvas.mapy = TomAdventureCanvas.mapy - 8;
                    }
                }
                else
                {
                    TomAdventureCanvas.mapy = 0;
                }
            }
            else
            {
                x = TomAdventureCanvas.mapw - 5;
                ret = 1;
            }
        }
        else if(jumpcount>=3 && jumpcount<=7)
        {
            if (x > -5)
            {
                if(!TomAdventureCanvas.isBlock(x,y,11,15,-3))
                {
                    x = x - 3;
                }
            }
            else
            {
                x = TomAdventureCanvas.mapw - 5;
                ret = 1;
            }
        }
        else if(jumpcount == 8)
        {
            jumpcount = 0;
            status = FALL_LEFT;
        }

        if(TomAdventureCanvas.mapx-3>=0 && !TomAdventureCanvas.isBlock(x,y,11,15,-3))
        {
            if(x<TomAdventureCanvas.mapw-TomAdventureCanvas.vieww/2)
            {
                TomAdventureCanvas.mapx = TomAdventureCanvas.mapx - 3;
            }
        }
        if(jumpcount<8)
        {
            jumpcount++;
        }
        return ret;
    }

    public int jump_right()
    {
        int ret = 0;
        frame = 3;
        if(jumpcount>=0 && jumpcount<=2)
        {
            if(x+5<TomAdventureCanvas.mapw)
            {
                if(!TomAdventureCanvas.isBlock(x,y,11,15,3))
                {
                    x = x + 3;
                }
                if(jumpcount != 2)
                {
                    y = y - 8;
                }
                else
                {
                    y = y - 7;
                }
                if(TomAdventureCanvas.mapy-8>=0)
                {
                    if(y<TomAdventureCanvas.maph-TomAdventureCanvas.viewh/2)
                    {
                        TomAdventureCanvas.mapy = TomAdventureCanvas.mapy - 8;
                    }
                }
                else
                {
                    TomAdventureCanvas.mapy = 0;
                }
            }
            else
            {
                x = -5;
                ret = 1;
            }
        }
        else if(jumpcount>=3 && jumpcount<=7)
        {
            if(x+5<TomAdventureCanvas.mapw)
            {
                if(!TomAdventureCanvas.isBlock(x,y,11,15,3))
                {
                    x = x + 3;
                }
            }
            else
            {
                x = -5;
                ret = 1;
            }
        }
        else if(jumpcount == 8)
        {
            jumpcount = 0;
            status = FALL_RIGHT;
        }

        if(TomAdventureCanvas.mapx<TomAdventureCanvas.mapw-TomAdventureCanvas.vieww
           && !TomAdventureCanvas.isBlock(x,y,11,15,3))
        {
            if(x>=0+TomAdventureCanvas.vieww/2)
            {
                TomAdventureCanvas.mapx = TomAdventureCanvas.mapx + 3;
            }
        }

        if(jumpcount<8)
        {
            jumpcount++;
        }
        return ret;
    }

    public int fall()
    {
        int ret = 0;
        grid = TomAdventureCanvas.whichGrid(x,y,11,15);
        if(TomAdventureCanvas.onGround(grid[0],grid[1]) &&
           y>=TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][1]+TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][5]*grid[1]-fallstep)
          // y<=TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][1]+TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][5]*grid[1]+3)
        {
            fallstep = 2;
        }

        if(TomAdventureCanvas.onGround(grid[0],grid[1]) &&
           y>=TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][1]+TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][5]*grid[1]-1 &&
           y<=TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][1]+TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][5]*grid[1]+1)
        {
            y = TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][1]+TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][5]*grid[1];

            if(TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -1][grid[1]+2][grid[0]]==10 ||
               TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -1][grid[1]+2][grid[0]]==11)
            {
                canvas.map[(grid[1]+1) *
                    TomAdventureCanvas.mapstage[TomAdventureCanvas.stage -
                    1][0][2] + grid[0]].status = 1;
            }

            if(status == FALL_LEFT)
            {
                status = LEFT;
            }
            else
            {
                status = RIGHT;
            }
            direct = 0;
            fallstep = 5;
        }
        else
        {

⌨️ 快捷键说明

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