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

📄 bnb_player.java

📁 手机版本的泡泡堂 用j2me写的 大家可以参考下
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        {
            case -3://左
            case 52:
                isL = false;
                break;
            case -4://右
            case 54:
                isR = false;
                break;
            case -1://上
            case 50:
                isU = false;
                break;
            case -2://下
            case 56:
                isD = false;
                break;
        }
    }

    /***
     * @方法说明:玩家和泡泡的碰撞检测 
     */
    public final void collideesWith(BnB_Popo p, int key)
    {
        //      玩家和泡泡的碰撞检测
        if (p.isVisible())
        {
            if (this.isHaveVehicle)
            {
                if ((vehicle.getRefPixelX() < pao[index].getX()
                        || pao[index].getX() + pao[index].getWidth() < vehicle
                                .getRefPixelX()
                        || vehicle.getRefPixelY() < pao[index].getY() || pao[index]
                        .getY()
                        + pao[index].getHeight() < vehicle.getRefPixelY())
                        && !vehicle.collidesWith(p, false))
                {
                    p.isCollide = true;
                }
                if (p.isCollide && vehicle.collidesWith(p, false))
                {
                    reviseXY(p, key);
                }
            }
            else
            {
                if ((getRefPixelX() < pao[index].getX()
                        || pao[index].getX() + pao[index].getWidth() < getRefPixelX()
                        || getRefPixelY() < pao[index].getY() || pao[index]
                        .getY()
                        + pao[index].getHeight() < getRefPixelY())
                        && !this.collidesWith(p, false))
                {
                    p.isCollide = true;
                }
                if (p.isCollide && this.collidesWith(p, false))
                {
                    reviseXY(p, key);
                }
            }
        }
    }

    /***
     * @方法说明: 玩家和水柱的碰撞检测。
     */
    public final void collidesWith(BnB_Popo p, TiledLayer tl)
    {
        if (!this.isDie)
        {
            if (p.isDetonate)
            {
                ////////////玩家和水柱的碰撞检测;
                int cols;
                int rows;
                if (!this.isHaveVehicle)
                //                  没有坐骑
                {
                    cols = Tools.toRange(getRefPixelX());
                    rows = Tools.toRange(getRefPixelY());
                    if (!isProtect && p.cols == cols && p.rows == rows)
                    {
                        setImage(3);
                        life--;
                        return;
                    }
                    if (!isProtect && p.isExpedite(tl, cols, rows))
                    {
                        if (rows == p.rows)
                        {
                            if (cols < p.cols)
                            {
                                if (cols >= p.cols - p.length)
                                {
                                    setImage(3);
                                    life--;
                                    return;
                                }
                            }
                            else if (cols > p.cols)
                            {
                                if (cols <= p.cols + p.length)
                                {
                                    setImage(3);
                                    life--;
                                    return;
                                }
                            }
                        }
                        if (cols == p.cols)
                        {
                            if (rows < p.rows)
                            {
                                if (rows >= p.rows - p.length)
                                {
                                    setImage(3);
                                    life--;
                                    return;
                                }
                            }
                            else if (rows > p.rows)
                            {
                                if (rows <= p.rows + p.length)
                                {
                                    setImage(3);
                                    life--;
                                    return;
                                }
                            }
                        }
                    }
                }
                else
                //有坐骑
                {
                    cols = Tools.toRange(vehicle.getRefPixelX());
                    rows = Tools.toRange(vehicle.getRefPixelY());
                    if (p.cols == cols && p.rows == rows)
                    {
                        isKeyPress = false;
                        setPosition(vehicle.getX(), vehicle.getY() - 4);
                        isKeyPress = true;
                        vehicle.setVisible(false);
                        vehicleimage = null;
                        vehicle = null;
                        isHaveVehicle = false;
                        isProtect = false;
                    }
                    if (p.isExpedite(tl, cols, rows))
                    {
                        if (cols == p.cols)
                        {
                            if (rows < p.rows)
                            {
                                if (rows >= p.rows - p.length)
                                {
                                    isKeyPress = false;
                                    setPosition(vehicle.getX(),
                                            vehicle.getY() - 4);
                                    isKeyPress = true;
                                    vehicle.setVisible(false);
                                    vehicleimage = null;
                                    vehicle = null;
                                    isHaveVehicle = false;
                                    isProtect = false;
                                }
                            }
                            else if (rows > p.rows)
                            {
                                if (rows <= p.rows + p.length)
                                {
                                    isKeyPress = false;
                                    setPosition(vehicle.getX(),
                                            vehicle.getY() - 4);
                                    isKeyPress = true;
                                    vehicle.setVisible(false);
                                    vehicleimage = null;
                                    vehicle = null;
                                    isHaveVehicle = false;
                                    isProtect = false;
                                }
                            }
                        }
                        if (rows == p.rows)
                        {
                            if (cols < p.cols)
                            {
                                if (cols >= p.cols - p.length)
                                {
                                    isKeyPress = false;
                                    setPosition(vehicle.getX(),
                                            vehicle.getY() - 4);
                                    isKeyPress = true;
                                    vehicle.setVisible(false);
                                    vehicleimage = null;
                                    vehicle = null;
                                    isHaveVehicle = false;
                                    isProtect = false;
                                }
                            }
                            else if (cols > p.cols)
                            {
                                if (cols <= p.cols + p.length)
                                {
                                    isKeyPress = false;
                                    setPosition(vehicle.getX(),
                                            vehicle.getY() - 4);
                                    isKeyPress = true;
                                    vehicle.setVisible(false);
                                    vehicleimage = null;
                                    vehicle = null;
                                    isHaveVehicle = false;
                                    isProtect = false;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    /***
     * 
     * @方法说明: 玩家骑坐骑 或行走时 和障碍层地图的碰撞检测  
     */
    public final void collidesWith(TiledLayer tl, int key)
    {
        if (this.isVisible() || tl.isVisible())
        {
            int px1;
            int px2;
            int py1;
            int py2;
            int prows1;
            int pcols1;
            int prows2;
            int pcols2;
            int tx;
            int ty;
            int rows;
            int cols;
            if (isHaveVehicle)
            {
                if (vehicle.isVisible())
                {
                    switch (key)
                    {
                        case -3://左
                        case 52:
                            tx = vehicle.getX();
                            ty = vehicle.getY() + (vehicle.getHeight() >>> 1);
                            rows = Tools.toRange(ty);
                            cols = Tools.toRange(tx);
                            if (cols < 0 || cols > 7)
                            {
                                cols = 0;
                            }
                            if (tl.getCell(cols, rows) > 10)
                            {
                                vehicle.setPosition((cols << 4) + 16, vehicle
                                        .getY());
                            }
                            //坐标修正处理;///////////////////////////////////////
                            px1 = vehicle.getX() + 2;
                            py1 = vehicle.getY() + 2;
                            pcols1 = Tools.toRange(px1);
                            prows1 = Tools.toRange(py1);
                            if (pcols1 < 0 || pcols1 > 7)
                            {
                                pcols1 = 0;
                            }
                            if (tl.getCell(pcols1, prows1) > 10)
                            {
                                vehicle.move(1, 2);
                            }
                            px2 = vehicle.getX() + 2;
                            py2 = vehicle.getY() + vehicle.getHeight() - 2;
                            pcols2 = Tools.toRange(px2);
                            prows2 = Tools.toRange(py2);
                            if (pcols2 < 0 || pcols2 > 7)
                            {
                                pcols2 = 0;
                            }
                            if (tl.getCell(pcols2, prows2) > 10)
                            {
                                vehicle.move(1, -2);
                            }
                            break;
                        case -4://右
                        case 54:
                            tx = vehicle.getX() + vehicle.getWidth();
                            ty = vehicle.getY() + (vehicle.getHeight() >>> 1);
                            rows = Tools.toRange(ty);
                            cols = Tools.toRange(tx);
                            if (cols > 7 || cols < 0)
                            {
                                cols = 7;
                            }
                            if (tl.getCell(cols, rows) > 10)
                            {
                                vehicle.setPosition((cols << 4) - 16, vehicle
                                        .getY());
                            }
                            //坐标修正处理;///////////////////////////////////////////
                            px1 = vehicle.getX() + vehicle.getWidth() - 2;
                            py1 = vehicle.getY() + 2;
                            pcols1 = Tools.toRange(px1);
                            prows1 = Tools.toRange(py1);
                            if (pcols1 < 0 || pcols1 > 7)
                            {
                                pcols1 = 0;
                            }
                            if (tl.getCell(pcols1, prows1) > 10)
                            {
                                vehicle.move(-1, 2);
                            }
                            px2 = vehicle.getX() + vehicle.getWidth() - 2;
                            py2 = vehicle.getY() + vehicle.getHeight() - 2;
                            pcols2 = Tools.toRange(px2);
                            prows2 = Tools.toRange(py2);
                            if (pcols2 < 0 || pcols2 > 7)
                            {
                                pcols2 = 0;
                            }
                            if (tl.getCell(pcols2, prows2) > 10)
                            {
                                vehicle.move(-1, -2);
                            }
                            break;
                        case -1://上
                        case 50:
                            tx = vehicle.getX() + (vehicle.getWidth() >>> 1);
                            ty = vehicle.getY();
                            rows = Tools.toRange(ty);
                            cols = Tools.toRange(tx);
                            if (rows > 9 || rows < 2)
                            {
                                rows = 2;
                            }
                            if (tl.getCell(cols, rows) > 10)
                            {
                                vehicle.setPosition(vehicle.getX(),
                                        (rows << 4) + 12);
                            }
                            //坐标修正处理;//////////////////////////////////////////
                            px1 = vehicle.getX() + 2;
                            py1 = vehicle.getY() + 2;

⌨️ 快捷键说明

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