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

📄 movingobject.java

📁 又是一款j2me 游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                if(minX < rightBound && maxX > leftBound || minX > leftBound && maxX < rightBound || minX < leftBound && maxX > leftBound || minX < rightBound && maxX > rightBound)
                                    return curPosY < leftDisY || moveTo > leftDisY ? moveOffset : curPosY - leftDisY;
                            }
                        }
                    }
                break;
            }

            case 1: // '\001'
            {
                int minX = curPosX - widthOffset;
                int maxX = curPosX + widthOffset;
                int leftPosX = minX / 30;
                int rightPosX = maxX / 30;
                int posY1 = curPosY / 30;
                int leftRoomData = Room.GetObjectId(leftPosX, posY1);
                int rightRoomData = Room.GetObjectId(rightPosX, posY1);
                int objPosY = posY1 * 30;
                int leftDisY = objPosY + Room.GetObstructionDistance(leftRoomData, direct);
                int rightDisY = objPosY + Room.GetObstructionDistance(rightRoomData, direct);
                int moveTo = curPosY + moveOffset;
                if(rightRoomData != -1)
                {
                    int objPosX = Room.GetObstructionDistance(rightRoomData, 3);
                    int lWidth = 30 - Room.GetObstructionDistance(rightRoomData, 2);
                    int rWidth = objPosX;
                    int width = lWidth - rWidth;
                    if(width > 0)
                    {
                        objPosX += rightPosX * 30;
                        int leftBound = objPosX;
                        int rightBound = objPosX + width;
                        if(minX < rightBound && maxX > leftBound || minX > leftBound && maxX < rightBound || minX < leftBound && maxX > leftBound || minX < rightBound && maxX > rightBound)
                            if(moveTo >= rightDisY)
                                return rightDisY - curPosY - 1;
                            else
                                return moveOffset;
                    }
                }
                if(leftPosX != rightPosX && leftRoomData != -1)
                {
                    int objPosX = Room.GetObstructionDistance(leftRoomData, 3);
                    int lWidth = Room.GetObstructionDistance(leftRoomData, 2);
                    int rWidth = 30 - objPosX;
                    int width = rWidth - lWidth;
                    if(width > 0)
                    {
                        objPosX += leftPosX * 30;
                        int leftBound = objPosX;
                        int rightBound = objPosX + width;
                        if(minX < rightBound && maxX > leftBound || minX > leftBound && maxX < rightBound || minX < leftBound && maxX > leftBound || minX < rightBound && maxX > rightBound)
                            if(moveTo >= leftDisY)
                                return leftDisY - curPosY - 1;
                            else
                                return moveOffset;
                    }
                }
                int posY2 = moveTo / 30;
                if(posY1 == posY2)
                    break;
                while(++posY1 <= posY2)
                {
                    leftRoomData = Room.GetObjectId(leftPosX, posY1);
                    rightRoomData = Room.GetObjectId(rightPosX, posY1);
                    leftDisY = (objPosY += 30) + Room.GetObstructionDistance(leftRoomData, direct);
                    rightDisY = objPosY + Room.GetObstructionDistance(rightRoomData, direct);
                    if(rightRoomData != -1)
                    {
                        int objPosX = Room.GetObstructionDistance(rightRoomData, 3);
                        int lWidth = 30 - Room.GetObstructionDistance(rightRoomData, 2);
                        int rWidth = objPosX;
                        int width = lWidth - rWidth;
                        if(width > 0)
                        {
                            objPosX += rightPosX * 30;
                            int leftBound = objPosX;
                            int rightBound = objPosX + width;
                            if(minX < rightBound && maxX > leftBound || minX > leftBound && maxX < rightBound || minX < leftBound && maxX > leftBound || minX < rightBound && maxX > rightBound)
                                return moveTo < rightDisY ? moveOffset : rightDisY - curPosY - 1;
                        }
                    }
                    if(leftPosX != rightPosX && leftRoomData != -1)
                    {
                        int objPosX = Room.GetObstructionDistance(leftRoomData, 3);
                        int lWidth = Room.GetObstructionDistance(leftRoomData, 2);
                        int rWidth = 30 - objPosX;
                        int width = rWidth - lWidth;
                        if(width > 0)
                        {
                            objPosX += leftPosX * 30;
                            int leftBound = objPosX;
                            int rightBound = objPosX + width;
                            if(minX < rightBound && maxX > leftBound || minX > leftBound && maxX < rightBound || minX < leftBound && maxX > leftBound || minX < rightBound && maxX > rightBound)
                                return moveTo < leftDisY ? moveOffset : leftDisY - curPosY - 1;
                        }
                    }
                }
                break;
            }

            case 2: // '\002'
            {
                int minX = curPosX - widthOffset;
                int leftPosX1 = minX / 30;
                int posY = curPosY / 30;
                int leftRoomData = Room.GetObjectId(leftPosX1, posY);
                int objPosX = (leftPosX1 + 1) * 30;
                int leftDisX = objPosX - Room.GetObstructionDistance(leftRoomData, direct);
                int moveTo = minX - moveOffset;
                if(leftRoomData != -1 && leftDisX <= minX)
                {
                    int objPosY;
                    int upDisY;
                    int downDisY;
                    if(leftDisX >= moveTo)
                    {
                        if(!Room.IsCornerWallId(leftRoomData))
                        {
                            objPosY = posY * 30;
                            int objDis = Room.GetObstructionDistance(leftRoomData, 0);
                            if(objDis < 30)
                            {
                                upDisY = (objPosY + 30) - objDis;
                                if(curPosY > upDisY)
                                    return moveOffset;
                            }
                            objDis = Room.GetObstructionDistance(leftRoomData, 1);
                            if(objDis < 30)
                            {
                                downDisY = objPosY + Room.GetObstructionDistance(leftRoomData, 1);
                                if(curPosY < downDisY)
                                    return moveOffset;
                            }
                        }
                        return minX - leftDisX;
                    }
                    objPosY = posY * 30;
                    upDisY = (objPosY + 30) - Room.GetObstructionDistance(leftRoomData, 0);
                    downDisY = objPosY + Room.GetObstructionDistance(leftRoomData, 1);
                    if(curPosY < upDisY && curPosY > downDisY)
                        return minX - leftDisX <= moveOffset ? minX - leftDisX : moveOffset;
                }
                int leftPosX2 = moveTo / 30;
                if(leftPosX1 == leftPosX2)
                    break;
                while(--leftPosX1 >= leftPosX2)
                {
                    leftRoomData = Room.GetObjectId(leftPosX1, posY);
                    leftDisX = (objPosX -= 30) - Room.GetObstructionDistance(leftRoomData, direct);
                    if(leftRoomData != -1 && leftDisX <= minX)
                    {
                        int objPosY;
                        int upDisY;
                        int downDisY;
                        if(leftDisX >= moveTo)
                        {
                            if(!Room.IsCornerWallId(leftRoomData))
                            {
                                objPosY = posY * 30;
                                int objDis = Room.GetObstructionDistance(leftRoomData, 0);
                                if(objDis < 30)
                                {
                                    upDisY = (objPosY + 30) - objDis;
                                    if(curPosY > upDisY)
                                        return moveOffset;
                                }
                                objDis = Room.GetObstructionDistance(leftRoomData, 1);
                                if(objDis < 30)
                                {
                                    downDisY = objPosY + Room.GetObstructionDistance(leftRoomData, 1);
                                    if(curPosY < downDisY)
                                        return moveOffset;
                                }
                            }
                            return minX - leftDisX;
                        }
                        objPosY = posY * 30;
                        upDisY = (objPosY + 30) - Room.GetObstructionDistance(leftRoomData, 0);
                        downDisY = objPosY + Room.GetObstructionDistance(leftRoomData, 1);
                        if(curPosY < upDisY && curPosY > downDisY)
                            return minX - leftDisX <= moveOffset ? minX - leftDisX : moveOffset;
                    }
                }
                break;
            }

            case 3: // '\003'
            {
                int maxX = curPosX + widthOffset;
                int rightPosX1 = maxX / 30;
                int posY = curPosY / 30;
                int rightRoomData = Room.GetObjectId(rightPosX1, posY);
                int objPosX = rightPosX1 * 30;
                int rightDisX = objPosX + Room.GetObstructionDistance(rightRoomData, direct);
                int moveTo = maxX + moveOffset;
                if(rightRoomData != -1 && rightDisX >= maxX)
                {
                    int objPosY;
                    int upDisY;
                    int downDisY;
                    if(rightDisX <= moveTo)
                    {
                        if(!Room.IsCornerWallId(rightRoomData))
                        {
                            objPosY = posY * 30;
                            int objDis = Room.GetObstructionDistance(rightRoomData, 0);
                            if(objDis < 30)
                            {
                                upDisY = (objPosY + 30) - objDis;
                                if(curPosY > upDisY)
                                    return moveOffset;
                            }
                            objDis = Room.GetObstructionDistance(rightRoomData, 1);
                            if(objDis < 30)
                            {
                                downDisY = objPosY + Room.GetObstructionDistance(rightRoomData, 1);
                                if(curPosY < downDisY)
                                    return moveOffset;
                            }
                        }
                        return rightDisX - maxX - 1;
                    }
                    objPosY = posY * 30;
                    upDisY = (objPosY + 30) - Room.GetObstructionDistance(rightRoomData, 0);
                    downDisY = objPosY + Room.GetObstructionDistance(rightRoomData, 1);
                    if(curPosY < upDisY && curPosY > downDisY)
                        return rightDisX - maxX - 1 <= moveOffset ? rightDisX - maxX - 1 : moveOffset;
                }
                int rightPosX2 = moveTo / 30;
                if(rightPosX1 == rightPosX2)
                    break;
                while(++rightPosX1 <= rightPosX2)
                {
                    rightRoomData = Room.GetObjectId(rightPosX1, posY);
                    rightDisX = (objPosX += 30) + Room.GetObstructionDistance(rightRoomData, direct);
                    if(rightRoomData != -1 && rightDisX >= maxX)
                    {
                        int objPosY;
                        int upDisY;
                        int downDisY;
                        if(rightDisX <= moveTo)
                        {
                            if(!Room.IsCornerWallId(rightRoomData))
                            {
                                objPosY = posY * 30;
                                int objDis = Room.GetObstructionDistance(rightRoomData, 0);
                                if(objDis < 30)
                                {
                                    upDisY = (objPosY + 30) - objDis;
                                    if(curPosY > upDisY)
                                        return moveOffset;
                                }
                                objDis = Room.GetObstructionDistance(rightRoomData, 1);
                                if(objDis < 30)
                                {
                                    downDisY = objPosY + Room.GetObstructionDistance(rightRoomData, 1);
                                    if(curPosY < downDisY)
                                        return moveOffset;
                                }
                            }
                            return rightDisX - maxX - 1;
                        }
                        objPosY = posY * 30;
                        upDisY = (objPosY + 30) - Room.GetObstructionDistance(rightRoomData, 0);
                        downDisY = objPosY + Room.GetObstructionDistance(rightRoomData, 1);
                        if(curPosY < upDisY && curPosY > downDisY)
                            return rightDisX - maxX - 1 <= moveOffset ? rightDisX - maxX - 1 : moveOffset;
                    }
                }
                break;
            }
            }
        }
        catch(Exception e) { }
        return moveOffset;
    }

    public void Draw(Graphics g, int xOffset, int yOffset)
    {
        int width = curLoc.GetWidth();
        int height = curLoc.GetHeight();
        int posX = xOffset + curLoc.GetX();
        int posY = yOffset + curLoc.GetY();
        g.setClip(posX, posY, width, height);
        switch(GetType())
        {
        case 30: // '\036'
            g.drawImage(weaponImg, posX - stage * 25 - 114, posY - 318, 20);
            break;

        case 50: // '2'
            switch(direction)
            {
            case 0: // '\0'
                g.drawImage(weaponImg, posX - 114, posY - 228, 20);
                break;

            case 1: // '\001'
                g.drawImage(weaponImg, posX - 134, posY - 228, 20);
                break;

            case 2: // '\002'
                g.drawImage(weaponImg, posX - 154, posY - 228, 20);
                break;

            case 3: // '\003'
                DirectGraphics dg = DirectUtils.getDirectGraphics(g);
                dg.drawImage(weaponImg, posX - 16, posY - 228, 20, 8192);
                break;
            }
            break;

        case 60: // '<'
            g.drawImage(weaponImg, posX - stage * 20 - 114, posY - 248, 20);
            break;
        }
        if(stage < 2)
            stage++;
        else
        if(stage >= 2)
        {
            if(GetType() == 60)
                stage = 0;
            else
                stage--;
            canAttack = true;
        }
    }

    static Image weaponImg = null;
    protected int DEFAULT_HIT_POWER;
    protected int hitPower;
    protected int speedX;
    protected int speedY;
    protected int stage;
    protected int direction;
    protected int moveDis;
    protected boolean destroy;
    protected boolean canAttack;
    protected int type;
    protected Rectangle curLoc;

}

⌨️ 快捷键说明

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