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

📄 enemy.java

📁 一个很不错的炸弹人J2ME游戏源码.画面及音效质量都不错,可供新手学习使用.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            anim = new int[5][];
            anim[0] = (new int[] {
                0, 0, 1, 1, 2, 2, 3, 3
            });
            anim[1] = (new int[] {
                0, 0, 1, 1, 2, 2, 3, 3
            });
            anim[2] = (new int[] {
                0, 0, 1, 1, 2, 2, 3, 3
            });
            anim[4] = (new int[] {
                0, 0, 1, 1, 2, 2, 3, 3
            });
            anim[3] = (new int[] {
                0, 0, 1, 1, 2, 2, 3, 3
            });
            direction = 1;
            mode = 5;
            speedX = 200;
            speedY = -200;
        } else
        if(byte0 == 16)
        {
            width = 13;
            height = 8;
            anim = new int[5][];
            anim[0] = (new int[] {
                0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 
                5, 5
            });
            anim[1] = (new int[] {
                0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 
                5, 5
            });
            anim[2] = (new int[] {
                0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 
                5, 5
            });
            anim[4] = (new int[] {
                0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 
                5, 5
            });
            anim[3] = (new int[] {
                0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 
                5, 5
            });
            direction = 0;
            mode = 5;
            speedX = -20;
            speedY = -2;
        } else
        if(byte0 == 11)
        {
            width = 12;
            height = 10;
            anim = new int[5][];
            anim[0] = (new int[] {
                6, 6, 7, 7, 8, 8
            });
            anim[1] = (new int[] {
                3, 3, 4, 4, 5, 5
            });
            anim[2] = (new int[] {
                0, 0, 1, 1, 2, 2
            });
            anim[4] = (new int[] {
                0, 0, 1, 1, 2, 2
            });
            anim[3] = (new int[] {
                0, 0, 1, 1, 2, 2
            });
            direction = 2;
            mode = 5;
        } else
        if(byte0 == 97)
        {
            width = 10;
            height = 10;
            speedX = 200;
            speedY = -200;
            direction = 1;
            mode = 5;
            powertype = 0;
        } else
        if(byte0 == 98)
        {
            width = 11;
            height = 11;
            speedX = 100;
            speedY = 0;
            direction = 1;
            mode = 0;
        } else
        if(byte0 == 99)
        {
            width = 11;
            height = 11;
            speedX = 100;
            speedY = 0;
            direction = 1;
            mode = 0;
        }
    }

    public void appear()
    {
        if(animCount++ >= 6)
        {
            if(type == 10)
                mode = 0;
            else
                mode = 5;
            animCount = 0;
        }
    }

    public void changePowertype()
    {
        powertype = (byte)((powertype + 1) % POWERPOINTS.length);
    }

    public void move(int i, int j)
    {
        if(active && mode != 7)
        {
            calcX += i;
            calcY += j;
            x = calcX / 100;
            y = calcY / 100;
            byte byte0 = direction;
            if(i < 0)
                direction = 0;
            else
            if(i > 0)
                direction = 1;
            else
            if(type != 12)
                direction = 2;
            if(type != 12)
                if(j < 0)
                    direction = 3;
                else
                if(j > 0)
                    direction = 4;
            if(byte0 != direction)
                animCount = 0;
            try
            {
                if(type == 10 && (i != 0 || j != 0))
                    animate();
            }
            catch(Exception exception) { }
        }
    }

    public void draw(Graphics g)
    {
        draw(g, x, y);
    }

    public void draw(Graphics g, int i, int j)
    {
        j += 2;
        if(type == 97)
        {
            g.setClip(i - 1, j - 2, width, height);
            g.clipRect(3, 0, 170, 182);
            g.drawImage(animImage, i - 1 - powertype * width, j - 2, 20);
            ox = i - 1;
            oy = j - 2;
            owidth = width;
            oheight = height;
            return;
        }
        if(type == 98)
        {
            g.setClip(i - 1, j, width, height);
            g.clipRect(3, 0, 170, 182);
            g.drawImage(animImage, i - 1, j - 10, 20);
            ox = i - 1;
            oy = j;
            owidth = width;
            oheight = height;
            return;
        }
        if(type == 99)
        {
            g.setClip(i - 1, j, width, height);
            g.clipRect(3, 0, 170, 182);
            g.drawImage(animImage, i - 1 - width, j - 10, 20);
            ox = i - 1;
            oy = j;
            owidth = width;
            oheight = height;
            return;
        }
        if(Player.player.powerMode || mode == 7)
        {
            if(Player.player.powerTime >= 60 || Player.player.powerTime % 6 >= 2)
            {
                animCount = (animCount + 1) % 5;
                int k = -(10 - height) / 2;
                int i1 = -(10 - width) / 2;
                g.setClip(i + i1, j + k, 10, 10);
                g.clipRect(3, 0, 170, 182);
                g.drawImage(smileyImage, (i + i1) - animCount * 10, j + k, 20);
                ox = i + i1;
                oy = j + k;
                owidth = 10;
                oheight = 10;
            }
            return;
        }
        if(mode == 6)
        {
            int l = -(25 - height) / 2;
            int j1 = -(25 - width) / 2;
            g.setClip(i + j1, j + l, 25, 25);
            g.clipRect(3, 0, 170, 182);
            g.drawImage(appearImage, (i + j1) - animCount * 25, j + l, 20);
            ox = i + j1;
            oy = j + l;
            owidth = 25;
            oheight = 25;
            return;
        }
        if(active)
        {
            byte byte0 = -2;
            int k1 = 0;
            if(type == 12)
                byte0 = -3;
            animCount = animCount % anim[direction].length;
            g.setClip((i - 1) + k1, j + byte0, width, height);
            g.clipRect(3, 0, 170, 182);
            g.drawImage(animImage, ((i - 1) + k1) - anim[direction][animCount] * width, j + byte0, 20);
            ox = (i - 1) + k1;
            oy = j + byte0;
            owidth = width;
            oheight = height;
            if(type != 10)
                animate();
        }
    }

    public int getPoints()
    {
        if(type == 97)
            return POWERPOINTS[powertype];
        if(Player.player.powerMode)
            return POWERPOINTS[Player.player.enemyCollect];
        else
            return 100;
    }

    public boolean isDestroyable()
    {
        return mode == 7;
    }

    public void animate()
    {
        animCount = (animCount + 1) % anim[direction].length;
    }

    public int[][] getGridPos(int i, int j)
    {
        int k = (x + i) / 5;
        int l = (y + j) / 7;
        return (new int[][] {
            new int[] {
                k, l
            }, new int[] {
                k + 1, l
            }, new int[] {
                k, l + 1
            }, new int[] {
                k + 1, l + 1
            }
        });
    }

    static 
    {
        allEnemies = new Enemy[12];
        for(int i = 0; i < allEnemies.length; i++)
        {
            allEnemies[i] = new Enemy();
            allEnemies[i].active = false;
        }

    }
}

⌨️ 快捷键说明

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