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

📄 enemy.java

📁 j2me游戏都市骑士的代码,是一款横版格斗的游戏.可以学习参考.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        }

        if((ebackAttack || ehit && System.currentTimeMillis() % 5L == 0L) && eweaponPicked && isWeapon)
        {
            if(x > 50 && x <= 400)
                if(face == 26)
                    game.RoadArms.addElement(new Arms(weapon, (short)(x - 5), (short)192));
                else
                    game.RoadArms.addElement(new Arms(weapon, (short)(x + 5), (short)192));
            eweaponPicked = false;
            isWeapon = false;
            game.weapon2 = weapon;
            action = 13;
            weapon = 35;
            fr = 0;
        }
        if(game.enemyMan.size() == 1)
        {
            if(!isWeapon)
            {
                if((Dist > 60 || Dist >= 35) && action != 19)
                {
                    if(System.currentTimeMillis() % 7L == 0L)
                        action = 16;
                    else
                        action = 14;
                } else
                if(Dist <= 35 && Dist >= 20 && action != 15 && action != 19)
                    action = 13;
                if((action == 13 || action == 16) && enemyCtr % 5 == 0 && !game.me.backAttack)
                    action = 15;
                if(jpCtr > 0 && y < emaxY && action != 19 && System.currentTimeMillis() % 3L == 0L)
                {
                    action = 19;
                    fr = 0;
                }
                if(Dist < 11 && y >= emaxY && game.me.y == game.me.maxY)
                    if(face == 26)
                        x -= 30;
                    else
                        x += 30;
            } else
            if(weapon == 41 || weapon == 39)
            {
                if(Dist > 20 && !ebackAttack)
                    if(x - game.me.x < 0)
                        face = 27;
                    else
                        face = 26;
                if(y >= emaxY)
                {
                    echainJumpCtr = 0;
                    eaxeJumpCtr = 0;
                }
                if(delayCtr == 0 && !ehit && !ebackAttack)
                {
                    if((Dist > 60 || Dist >= 35) && System.currentTimeMillis() % 2L == 0L)
                        action = 16;
                    if(Dist >= 20 && Dist <= 35)
                        action = 14;
                    if(Dist < 20)
                        if(game.me.action == 15 && System.currentTimeMillis() % 3L == 0L)
                            action = 17;
                        else
                        if(game.me.y >= emaxY && !game.me.backAttack)
                            action = 15;
                }
                if(action == 13)
                    delayCtr++;
                if(Dist < 11 && y >= emaxY && game.me.y >= game.me.maxY)
                    if(face == 26)
                        x -= 40;
                    else
                        x += 40;
                if(delayCtr == 12)
                    delayCtr = 0;
            }
        } else
        if(!isWeapon)
        {
            if((Dist > 60 || Dist >= 35) && action != 19)
            {
                if(System.currentTimeMillis() % 7L == 0L)
                    action = 16;
                else
                    action = 14;
            } else
            if(Dist <= 35 && Dist >= 20 && action != 15 && action != 19)
                action = 13;
            if((action == 13 || action == 16) && action != 15 && enemyCtr % 7 == 0 && !game.me.backAttack)
                action = 15;
            if(jpCtr > 0 && y < emaxY && action != 19 && System.currentTimeMillis() % 3L == 0L)
            {
                action = 19;
                fr = 0;
            }
            if(Dist < 11 && y >= emaxY && game.me.y == game.me.maxY)
                if(face == 26)
                    x -= 30;
                else
                    x += 30;
        } else
        {
            if(Dist > 20 && !ebackAttack)
                if(x - game.me.x < 0)
                    face = 27;
                else
                    face = 26;
            if(y >= emaxY)
            {
                echainJumpCtr = 0;
                eaxeJumpCtr = 0;
            }
            if(delayCtr == 0 && !ehit && !ebackAttack)
            {
                if((Dist > 60 || Dist >= 35) && System.currentTimeMillis() % 2L == 0L)
                    action = 16;
                if(Dist >= 20 && Dist <= 35)
                    action = 14;
                if(Dist < 20)
                    if(game.me.action == 15 && System.currentTimeMillis() % 3L == 0L)
                        action = 17;
                    else
                    if(game.me.y >= emaxY && !game.me.backAttack && action != 15)
                        action = 15;
            }
            if(action == 13)
                delayCtr++;
            if(Dist < 11 && y >= emaxY && game.me.y >= game.me.maxY)
                if(face == 26)
                    x -= 40;
                else
                    x += 40;
            if(delayCtr == 12)
                delayCtr = 0;
        }
        if(face != game.me.face)
            if(Dist <= 35 && game.enemyMan.size() == 1 || Dist <= 35 && game.enemyMan.size() > 1 && game.index == game.enemyMan.indexOf(this))
            {
                if(game.me.weapon == 35 && game.me.action == 15 && y == game.me.y)
                {
                    if(!isWeapon && action != 17)
                    {
                        health -= 2;
                        ehit = true;
                        game.gameEffects("punch");
                        game.score += 20;
                    }
                } else
                if(game.me.weapon == 34 && game.me.action == 15 && game.me.fr == 1 && Math.abs(game.me.y - y) <= 5)
                {
                    health -= 4;
                    ehit = true;
                    game.gameEffects("hit");
                    game.score += 40;
                } else
                if(game.me.weapon == 41 && game.me.action == 15 && game.me.fr == 1 && y >= game.me.y - 5 && action != 17)
                {
                    health -= 4;
                    ehit = true;
                    game.gameEffects("hit");
                    if(face == game.me.face)
                        ebackAttack = true;
                    game.score += 30;
                } else
                if(game.me.weapon == 39 && game.me.action == 15 && game.me.fr == 1 && y >= game.me.y - 5 && action != 17)
                {
                    health -= 5;
                    ehit = true;
                    game.gameEffects("hit");
                    if(face == game.me.face)
                        ebackAttack = true;
                    game.score += 50;
                }
            } else
            if(Dist <= 26 && game.me.weapon == 33 && y >= game.me.y - 5 && face != game.me.face)
            {
                ehit = true;
                game.gameEffects("hit");
            }
        if(ehit && !ebackAttack)
            ehitCtr++;
        else
            ehitCtr = 0;
        if(ehitCtr != 0)
            if(face == 26)
            {
                x += 10;
                if(x > 400)
                    ehit = false;
            } else
            {
                x -= 10;
                if(x < 50)
                    ehit = false;
            }
        checkBound();
    }

    public void checkBound()
    {
        if(x < 50)
        {
            x = 50;
            face = 27;
        } else
        if(x > 400)
        {
            x = 400;
            face = 26;
        }
    }

    public void drawEnemy(Graphics g)
    {
        if(!ehit)
            switch(action)
            {
            case 18: // '\022'
            default:
                break;

            case 13: // '\r'
                drawEnemyStand(g);
                break;

            case 14: // '\016'
                if(weapon == 41)
                {
                    enemyChainWalk(g);
                    break;
                }
                if(weapon == 39)
                    enemyAxeWalk(g);
                else
                    drawEnemyWalk(g);
                break;

            case 16: // '\020'
                if(weapon == 41)
                {
                    enemyChainJump(g);
                    break;
                }
                if(weapon == 39)
                    enemyAxeJump(g);
                else
                    drawEnemyJump(g);
                break;

            case 15: // '\017'
                switch(weapon)
                {
                case 34: // '"'
                    drawEnemyKick(g);
                    break;

                case 35: // '#'
                    drawEnemyPunch(g);
                    break;

                case 33: // '!'
                    drawEnemyKick(g);
                    break;

                case 39: // '\''
                    drawAxeFight(g);
                    break;

                case 41: // ')'
                    drawChainFight(g);
                    break;
                }
                break;

            case 17: // '\021'
                switch(weapon)
                {
                case 41: // ')'
                    drawChainFight(g);
                    break;

                case 39: // '\''
                    drawAxeFight(g);
                    break;
                }
                break;

            case 19: // '\023'
                drawEnemySumersalt(g);
                break;
            }
        if(game.me.health <= 0)
            action = 13;
        else
            updateAI();
    }

    public void eattackedAnimation(Graphics g)
    {
        int i = y - 10;
        if(ehit)
        {
            g.setClip((x - 11) + game.x1, i - 9, 22, 19);
            g.clipRect((x - 11) + game.x1, i - 9, 22, 19);
            g.drawImage(game.fighterHit, (((x + game.x1) - 11) + game.fighterHit.getWidth() / 2) - 22, (i - 9) + game.fighterHit.getHeight() / 2, 1 | 2);
        }
        g.setClip(0, 0, game.WIDTH, game.HEIGHT);
    }

    public void drawEnemySumersalt(Graphics g)
    {
        switch(face)
        {
        default:
            break;

        case 26: // '\032'
            switch(fr)
            {
            case 4: // '\004'
            case 5: // '\005'
                g.setClip((x - 31) + game.x1, y - 31, 62, 62);
                g.clipRect((x - 31) + game.x1, y - 31, 62, 62);
                g.drawRegion(game.playerIm, 120, 60, 60, 60, 5, (x - 31) + game.x1, y - 31, 0x10 | 4);
                action = 13;
                break;

            case 2: // '\002'
            case 3: // '\003'
                g.setClip((x - 31) + game.x1, y - 31, 62, 62);
                g.clipRect((x - 31) + game.x1, y - 31, 62, 62);
                g.drawRegion(game.playerIm, 120, 60, 60, 60, 3, (x - 31) + game.x1, y - 31, 0x10 | 4);
                x -= 10;
                break;

            case 0: // '\0'
            case 1: // '\001'
                g.setClip((x - 31) + game.x1, y - 31, 62, 62);
                g.clipRect((x - 31) + game.x1, y - 31, 62, 62);
                g.drawRegion(game.playerIm, 120, 60, 60, 60, 6, (x - 31) + game.x1, y - 31, 0x10 | 4);
                x -= 10;
                break;
            }
            break;

        case 27: // '\033'
            switch(fr)
            {
            case 0: // '\0'
            case 1: // '\001'
                g.setClip((x - 31) + game.x1, y - 31, 62, 62);
                g.clipRect((x - 31) + game.x1, y - 31, 62, 62);
                g.drawRegion(game.playerIm, 120, 60, 60, 60, 5, (x - 31) + game.x1, y - 31, 0x10 | 4);
                x += 10;
                break;

            case 2: // '\002'
            case 3: // '\003'
                g.setClip((x - 31) + game.x1, y - 31, 62, 62);
                g.clipRect((x - 31) + game.x1, y - 31, 62, 62);
                g.drawRegion(game.playerIm, 120, 60, 60, 60, 3, (x - 31) + game.x1, y - 31, 0x10 | 4);
                x += 10;
                break;

            case 4: // '\004'
            case 5: // '\005'
                g.setClip((x - 31) + game.x1, y - 31, 62, 62);
                g.clipRect((x - 31) + game.x1, y - 31, 62, 62);
                g.drawRegion(game.playerIm, 120, 60, 60, 60, 6, (x - 31) + game.x1, y - 31, 0x10 | 4);
                action = 13;
                break;
            }
            break;
        }
        checkBound();
        g.setClip(0, 0, game.WIDTH, game.HEIGHT);
    }

    public void drawEnemyPunch(Graphics g)
    {
        switch(face)
        {
        case 26: // '\032'
            g.setClip((x - 30) + game.x1, y - 30, 60, 60);
            g.clipRect((x - 30) + game.x1, y - 30, 60, 60);
            g.drawImage(game.playerIm, (x + game.x1 + game.playerIm.getWidth() / 2) - 30 - 180, (y + game.playerIm.getHeight() / 2) - 30 - 60, 1 | 2);
            break;

        case 27: // '\033'
            g.setClip((x - 30) + game.x1, y - 30, 60, 60);
            g.clipRect((x - 30) + game.x1, y - 30, 60, 60);
            g.drawRegion(game.playerIm, 180, 60, 60, 60, 2, (x - 30) + game.x1, y - 30, 0x10 | 4);
            break;
        }
        g.setClip(0, 0, game.WIDTH, game.HEIGHT);
    }

    public void drawEnemyKick(Graphics g)
    {
        if(weapon == 34)
            switch(face)
            {
            case 26: // '\032'
                switch(fr)
                {
                case 0: // '\0'
                    g.setClip((x - 30) + game.x1, y - 30, 60, 60);
                    g.clipRect((x - 30) + game.x1, y - 30, 60, 60);
                    g.drawImage(game.playerIm, (x + game.x1 + game.playerIm.getWidth() / 2) - 30 - 240, (y + game.playerIm.getHeight() / 2) - 30 - 60, 1 | 2);
                    break;

                case 1: // '\001'
                    g.setClip((x - 30) + game.x1, y - 30, 60, 60);
                    g.clipRect((x - 30) + game.x1, y - 30, 60, 60);
                    g.drawImage(game.playerIm, (x + game.x1 + game.playerIm.getWidth() / 2) - 30 - 300, (y + game.playerIm.getHeight() / 2) - 30 - 60, 1 | 2);
                    break;
                }
                g.setClip(0, 0, game.WIDTH, game.HEIGHT);

⌨️ 快捷键说明

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