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

📄 tom.java

📁 java 小程序 使用j2me 开发的一个小的游戏软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            if (y <= TomAdventureCanvas.maph)
            {
                y = y + fallstep;
            }
            if (TomAdventureCanvas.mapy + fallstep <=
                TomAdventureCanvas.maph - TomAdventureCanvas.viewh)
            {
                if (y >= 0 + TomAdventureCanvas.viewh / 2)
                {
                    TomAdventureCanvas.mapy = TomAdventureCanvas.mapy + fallstep;
                }
            }
            if(direct == 1)
            {
                status = FALL_LEFT;
                if (x > -11)
                {
                    if (!TomAdventureCanvas.isBlock(x, y, 11, 15, -2))
                    {
                        x = x - 2;
                    }
                }
                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;
                    }
                }
            }
            else if(direct == 2)
            {
                status = FALL_RIGHT;
                if(x+2<TomAdventureCanvas.mapw)
                {
                    if(!TomAdventureCanvas.isBlock(x,y,11,15,2))
                    {
                        x = x + 2;
                    }
                }
                else
                {
                    x = 0;
                    ret = 2;
                }
                if(TomAdventureCanvas.mapx<TomAdventureCanvas.mapw-TomAdventureCanvas.vieww
                    && !TomAdventureCanvas.isBlock(x,y,11,15,2))
                {
                    if(x>=0+TomAdventureCanvas.vieww/2)
                    {
                        TomAdventureCanvas.mapx = TomAdventureCanvas.mapx + 1;
                    }
                }
            }
        }
        return ret;
    }

    public void hit_left()
    {
        if(hitcount<3)
        {
            hitcount++;
            if(TomAdventureCanvas.isBlock(x,y,11,15,-5))
            {
                grid = TomAdventureCanvas.whichGrid(x,y,11,15);
                if(grid[0]==0)
                {
                    grid[0]=TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][2]-1;
                }
                else
                {
                    grid[0]=grid[0]-1;
                }
                canvas.changeItemStatus(grid[0],grid[1],1);
            }
        }
        else
        {
            hitcount = 1;
            status = LEFT;
        }
    }

    public void hit_right()
    {
        if(hitcount<3)
        {
            hitcount++;
            if(TomAdventureCanvas.isBlock(x,y,11,15,5))
            {
                grid = TomAdventureCanvas.whichGrid(x,y,11,15);
                if(grid[0]==TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][2]-1)
                {
                    grid[0]=0;
                }
                else
                {
                    grid[0]=grid[0]+1;
                }
                canvas.changeItemStatus(grid[0],grid[1],2);
            }
        }
        else
        {
            hitcount = 1;
            status = RIGHT;
        }
    }

    public void drill()
    {
        drillcount++;
        grid = TomAdventureCanvas.whichGrid(x,y,11,15);
        canvas.changeItemStatus(grid[0],grid[1]+1,2);
        if(drillcount>3)
        {
            if (status == DRILL_LEFT)
            {
                status = FALL_LEFT;
            }
            else if (status == DRILL_RIGHT)
            {
                status = FALL_RIGHT;
            }
            drillcount = 1;
        }
    }

    public void jumphit_left()
    {
        frame = 1;
        if(jumpcount>=0 && jumpcount<=2)
        {
                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 if(jumpcount>=3 && jumpcount<=5)
        {
            if(TomAdventureCanvas.isBlock(x,y,11,15,-5))
            {
                grid = TomAdventureCanvas.whichGrid(x,y,11,15);
                if(grid[0]==0)
                {
                    grid[0]=TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][2]-1;
                }
                else
                {
                    grid[0]=grid[0]-1;
                }
                canvas.changeItemStatus(grid[0],grid[1],1);
            }
        }
        else if(jumpcount == 6)
        {
            jumpcount = 0;
            status = FALL_LEFT;
        }

        if(jumpcount<6)
        {
            jumpcount++;
        }
    }

    public void jumphit_right()
    {
        frame = 1;
        if(jumpcount>=0 && jumpcount<=2)
        {
                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 if(jumpcount>=3 && jumpcount<=5)
        {
            if(TomAdventureCanvas.isBlock(x,y,11,15,5))
            {
                grid = TomAdventureCanvas.whichGrid(x,y,11,15);
                if(grid[0]==TomAdventureCanvas.mapstage[TomAdventureCanvas.stage-1][0][2]-1)
                {
                    grid[0]=0;
                }
                else
                {
                    grid[0]=grid[0]+1;
                }
                canvas.changeItemStatus(grid[0],grid[1],2);
            }
        }
        else if(jumpcount == 6)
        {
            jumpcount = 0;
            status = FALL_RIGHT;
        }

        if(jumpcount<6)
        {
            jumpcount++;
        }
    }

    public void paint(Graphics g)
    {
        isdraw = false;

        switch(status)
        {
            case LEFT:
                break;
            case RIGHT:
                break;
            case GO_LEFT:
                if(left_move()==1)
                {
                    TomAdventureCanvas.status = TomAdventureCanvas.LEFT_MOVE;
                }
                break;
            case GO_RIGHT:
                if(right_move()==1)
                {
                    TomAdventureCanvas.status = TomAdventureCanvas.RIGHT_MOVE;
                }
                break;
            case JUMP_LEFT:
                if(jump_left()==1)
                {
                    TomAdventureCanvas.status = TomAdventureCanvas.LEFT_MOVE;
                }
                break;
            case JUMP_RIGHT:
                if(jump_right()==1)
                {
                    TomAdventureCanvas.status = TomAdventureCanvas.RIGHT_MOVE;
                }
                break;
            case FALL_LEFT:
            case FALL_RIGHT:
                int ret;
                ret = fall();
                if(ret==1)
                {
                    TomAdventureCanvas.status = TomAdventureCanvas.LEFT_MOVE;
                }
                else if(ret==2)
                {
                    TomAdventureCanvas.status = TomAdventureCanvas.RIGHT_MOVE;
                }
                break;
            case HIT_LEFT:
                hit_left();
                break;
            case HIT_RIGHT:
                hit_right();
                break;
            case DRILL_LEFT:
            case DRILL_RIGHT:
                drill();
                break;
            case JUMPHIT_LEFT:
                jumphit_left();
                break;
            case JUMPHIT_RIGHT:
                jumphit_right();
                break;
        }

        if(y>TomAdventureCanvas.maph)
        {
            canvas.lose();
        }

        if(TomAdventureCanvas.mapx<=x && x<=TomAdventureCanvas.mapx+TomAdventureCanvas.vieww
            && TomAdventureCanvas.mapy<=y && y<=TomAdventureCanvas.mapy+TomAdventureCanvas.viewh)
        {
            isdraw = true;
        }
        else if(TomAdventureCanvas.mapx<=x+11 && x+11<=TomAdventureCanvas.mapx+TomAdventureCanvas.vieww
            && TomAdventureCanvas.mapy<=y && y<=TomAdventureCanvas.mapy+TomAdventureCanvas.viewh)
        {
            isdraw = true;
        }
        else if(TomAdventureCanvas.mapx<=x && x<=TomAdventureCanvas.mapx+TomAdventureCanvas.vieww
            && TomAdventureCanvas.mapy<=y+15 && y+15<=TomAdventureCanvas.mapy+TomAdventureCanvas.viewh)
        {
            isdraw = true;
        }
        else if(TomAdventureCanvas.mapx<=x+11 && x+11<=TomAdventureCanvas.mapx+TomAdventureCanvas.vieww
            && TomAdventureCanvas.mapy<=y+15 && y+15<=TomAdventureCanvas.mapy+TomAdventureCanvas.viewh)
        {
            isdraw = true;
        }
        if(isdraw == true)
        {
            //画拳击套
            if(status == HIT_LEFT || status == JUMPHIT_LEFT)
            {
                TomAdventureCanvas.drawClipImage(g,
                    x - TomAdventureCanvas.mapx-15,
                    y - TomAdventureCanvas.mapy+7,
                    TomAdventureCanvas.imgitem[9], 0, 0,
                    21, 7);
                frame = 1;
            }
            else if(status == HIT_RIGHT || status == JUMPHIT_RIGHT)
            {
                TomAdventureCanvas.drawClipImage(g,
                    x - TomAdventureCanvas.mapx+5,
                    y - TomAdventureCanvas.mapy+7,
                    TomAdventureCanvas.imgitem[9], 24, 0,
                    21, 7);
                frame = 3;
            }
            //画主角
            if (status == LEFT || status == GO_LEFT || status == FALL_LEFT || status == JUMP_LEFT || status == HIT_LEFT || status == JUMPHIT_LEFT || status == DRILL_LEFT)
            {
                TomAdventureCanvas.drawClipImage(g,
                    x - TomAdventureCanvas.mapx,
                    y - TomAdventureCanvas.mapy,
                    TomAdventureCanvas.imgitem[0], 0 + (frame - 1) * 11, 0, 11, 15);
            }
            else
            {
                TomAdventureCanvas.drawClipImage(g,
                    x - TomAdventureCanvas.mapx,
                    y - TomAdventureCanvas.mapy,
                    TomAdventureCanvas.imgitem[0], 34 + (frame - 1) * 11, 0, 11, 15);
            }
        }

        if(TomAdventureCanvas.status == TomAdventureCanvas.RUNNING)
        {
            if (timecount > 10)
            {
                if(time>0)
                {
                    time = time - 1;
                }
                else
                {
                    canvas.lose();
                }
                timecount = 1;
            }
            else
            {
                timecount++;
            }
        }

        TomAdventureCanvas.drawClipImage(g,14,3,TomAdventureCanvas.imgitem[8],90,0,8,9);
        TomAdventureCanvas.drawClipImage(g,25,6,TomAdventureCanvas.imgitem[8],99,4,5,5);
        int nowlife = life;
        int num[] = new int[2];
        if(nowlife>99)
        {
            nowlife = 99;
        }
        num[0] = nowlife / 10;
        nowlife = nowlife % 10;
        num[1] = nowlife;
        for(int i=0;i<2;i++)
        {
            TomAdventureCanvas.drawClipImage(g,35+i*7,4,TomAdventureCanvas.imgitem[8],26+num[i]*6,1,6,8);
        }
        TomAdventureCanvas.drawClipImage(g,87,4,TomAdventureCanvas.imgitem[8],0,2,26,7);
        g.setColor(255,25,12);
        g.fillRect(90,6,time/(maxtime/22+1),3);
    }
}

⌨️ 快捷键说明

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