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

📄 bnb_popo.java

📁 手机版本的泡泡堂 用j2me写的 大家可以参考下
💻 JAVA
字号:
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.game.TiledLayer;

public final class BnB_Popo extends Sprite
{
    public int cols; //行号
    public int rows;//列号
    public int time;//爆炸时间
    public int length;//爆炸长度;
    public boolean isCollide;//是否设定泡泡和玩家碰撞检测的标志;
    public boolean isDetonate;//是否爆炸的标志;
    public boolean isShow;//是否显示的标志;
    public static final int WIDTH = 16;// 图片长和宽
    private long lastTime, intervalTime;
    public static int popo;//泡泡记数器;
    public boolean isL, isR, isD, isU;

    public BnB_Popo(Image img, int w, int h)
    {
        super(img, w, h);
    }

    public final void setPopo(int cols, int rows, int length)
    {
        this.isL = true;
        this.isR = true;
        this.isD = true;
        this.isU = true;
        this.isDetonate = false;
        this.isCollide = false;
        this.cols = cols;
        this.rows = rows;
        this.length = length;
        this.setPosition(Tools.toCoordinate(cols), Tools.toCoordinate(rows));
        this.isShow = true;
        this.time = 4000;
        this.setVisible(true);
    }

    /**
     * @方法说明:是否连爆的检测;
     */
    public final void detectCannonry(BnB_Popo other)
    {
        if (this.isVisible() && other.isVisible())
        {
            if (this.cols == other.cols)
            {
                int temprows = this.rows > other.rows ? (this.rows - other.rows)
                        : (other.rows - this.rows);
                if ((this.length + other.length) >= temprows)
                {
                    if (this.time > other.time)
                    {
                        this.setTime(other.time);
                    }
                    else
                    {
                        other.setTime(this.time);
                    }
                }
            }
            else if (this.rows == other.rows)
            {
                int tempcols = this.cols > other.cols ? (this.cols - other.cols)
                        : (other.cols - this.cols);
                if ((this.length + other.length) >= tempcols)
                {
                    if (this.time > other.time)
                    {
                        this.setTime(other.time);
                    }
                    else
                    {
                        other.setTime(this.time);
                    }
                }
            }
        }
    }

    /***
     * @方法说明:检测两个泡泡之间是否有障碍
     * @return true 为没有障碍
     */
    public final boolean isExpedite(TiledLayer tl, int cols, int rows)
    {
        if (this.cols == cols)
        {
            if (this.rows > rows)
            {
                if (this.rows - rows == 1)
                {
                    return true;
                }
                for (int i = rows + 1; i < this.rows; i++)
                {
                    if (tl.getCell(this.cols, i) > 10)
                    {
                        return false;
                    }
                }
                return true;
            }
            if (this.rows < rows)
            {
                if (rows - this.rows == 1)
                {
                    return true;
                }
                for (int i = this.rows - 1; i < rows; i++)
                {
                    if (tl.getCell(this.cols, i) > 10)
                    {
                        return false;
                    }
                }
                return true;
            }
        }
        else if (this.rows == rows)
        {
            if (this.cols > cols)
            {
                if (this.cols - cols == 1)
                {
                    return true;
                }
                for (int i = cols + 1; i < this.cols; i++)
                {
                    if (tl.getCell(i, this.rows) > 10)
                    {
                        return false;
                    }
                }
                return true;
            }
            if (this.cols < cols)
            {
                if (cols - this.cols == 1)
                {
                    return true;
                }
                for (int i = this.cols + 1; i < cols; i++)
                {
                    if (tl.getCell(i, this.rows) > 10)
                    {
                        return false;
                    }
                }
                return true;
            }
        }
        return false;
    }

    private final void setTime(int time)
    {
        this.time = time;
    }

    /***
     * @方法说明:水柱和障碍层的碰撞检测,有几率出现道具卡片和坐骑;
     */
    private final void collidesWith(TiledLayer tl, int cols, int rows, int face)
    {
        switch (tl.getCell(cols, rows))
        {
            case 0:
                break;
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
                tl.setCell(cols, rows, 0);
                break;
            case 11:
            case 12:
            case 13:
            case 14:
                switch (face)
                {
                    case 1:
                        isU = false;
                        break;
                    case 2:
                        isD = false;
                        break;
                    case 3:
                        isL = false;
                        break;
                    case 4:
                        isR = false;
                        break;
                }
                break;
            case 15:
            case 16:
            case 17:
            case 18:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
                switch (Tools.getRandom(20))
                //道具出现几率
                {
                    case 1:
                        tl.setCell(cols, rows, 1);
                        break;
                    case 2:
                        tl.setCell(cols, rows, 2);
                        break;
                    case 3:
                        tl.setCell(cols, rows, 3);
                        break;
                    case 4:
                        tl.setCell(cols, rows, 4);
                        break;
                    case 5:
                        tl.setCell(cols, rows, 5);
                        break;
                    case 6:
                        tl.setCell(cols, rows, 6);
                        break;
                    case 7:
                        tl.setCell(cols, rows, 7);
                        break;
                    case 8:
                        tl.setCell(cols, rows, 8);
                        break;
                    case 9:
                        tl.setCell(cols, rows, 9);
                        break;
                    case 10:
                        tl.setCell(cols, rows, 10);
                        break;
                    case 11:
                        tl.setCell(cols, rows, 1);
                        break;
                    case 12:
                        tl.setCell(cols, rows, 2);
                        break;
                    case 13:
                        tl.setCell(cols, rows, 3);
                        break;
                    default:
                        tl.setCell(cols, rows, 0);
                        break;
                }
                switch (face)
                {
                    case 1:
                        isU = false;
                        break;
                    case 2:
                        isD = false;
                        break;
                    case 3:
                        isL = false;
                        break;
                    case 4:
                        isR = false;
                        break;
                }
                break;
        }
    }

    /**
     * @方法说明:画出水柱,从四个方向;
     */
    public final void paintPopo(Graphics g, Image img, TiledLayer tt)
    {
        if (this.time > 0)
        {
            this.time -= 100;
            if (time <= 0)
            {
                this.isDetonate = true;
                this.setVisible(false);
            }
            if (isNextFrame(300))
            {
                this.nextFrame();
            }
            this.paint(g);
        }
        else
        {
            int uprows = rows - 1;
            int downrows = rows + 1;
            int leftcols = cols - 1;
            int rightcols = cols + 1;
            Tools.paintClip(g, img, Tools.toCoordinate(cols), Tools
                    .toCoordinate(rows), 128, 0, WIDTH, WIDTH);
            for (int i = 0; uprows >= 2 && isU && i < length; i++)
            {
                collidesWith(tt, cols, uprows, 1);
                if (isU)
                {//向上////////////////////////////////////////
                    if (i < length - 1)
                    {
                        Tools.paintClip(g, img, Tools.toCoordinate(cols), Tools
                                .toCoordinate(uprows), 16, 0, WIDTH, WIDTH);
                    }
                    else
                    {
                        Tools.paintClip(g, img, Tools.toCoordinate(cols), Tools
                                .toCoordinate(uprows), 0, 0, WIDTH, WIDTH);
                    }
                    uprows--;
                }
            }
            for (int i = 0; downrows <= 9 && isD && i < length; i++)
            {
                collidesWith(tt, cols, downrows, 2);
                if (isD)
                {//向下/////////////////////////////////////
                    if (i < length - 1)
                    {
                        Tools.paintClip(g, img, Tools.toCoordinate(cols), Tools
                                .toCoordinate(downrows), 48, 0, WIDTH, WIDTH);
                    }
                    else
                    {
                        Tools.paintClip(g, img, Tools.toCoordinate(cols), Tools
                                .toCoordinate(downrows), 32, 0, WIDTH, WIDTH);
                    }
                    downrows++;
                }
            }
            for (int i = 0; leftcols >= 0 && isL && i < length; i++)
            {
                collidesWith(tt, leftcols, rows, 3);
                if (isL)
                {//向左///////////////////////////////////////////////
                    if (i < length - 1)
                    {
                        Tools.paintClip(g, img, Tools.toCoordinate(leftcols),
                                Tools.toCoordinate(rows), 80, 0, WIDTH, WIDTH);
                    }
                    else
                    {
                        Tools.paintClip(g, img, Tools.toCoordinate(leftcols),
                                Tools.toCoordinate(rows), 64, 0, WIDTH, WIDTH);
                    }
                    leftcols--;
                }
            }
            for (int i = 0; rightcols <= 7 && isR && i < length; i++)
            {
                collidesWith(tt, rightcols, rows, 4);
                if (isR)
                {//向右///////////////////////////////////////
                    if (i < length - 1)
                    {
                        Tools.paintClip(g, img, Tools.toCoordinate(rightcols),
                                Tools.toCoordinate(rows), 112, 0, WIDTH, WIDTH);
                    }
                    else
                    {
                        Tools.paintClip(g, img, Tools.toCoordinate(rightcols),
                                Tools.toCoordinate(rows), 96, 0, WIDTH, WIDTH);
                    }
                    rightcols++;
                }
            }
            this.isShow = false;
            this.isDetonate = false;
            if (popo < BnB_Player.MAX_POPO)
            {
                popo++;
            }
        }
    }

    private final boolean isNextFrame(int nextFrameTime)
    {
        intervalTime = System.currentTimeMillis() - lastTime;
        if (intervalTime >= nextFrameTime)
        {
            lastTime = System.currentTimeMillis();
            return true;
        }
        return false;
    }
}

⌨️ 快捷键说明

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