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

📄 collisionrect.java

📁 一个java的免费游戏引擎,里面有文档,和例子
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

package com.golden.gamedev.object.collision;


// Referenced classes of package com.golden.gamedev.object.collision:
//            CollisionShape

public class CollisionRect
    implements CollisionShape
{

    public double x;
    public double y;
    public int width;
    public int height;
    private int e;
    private int f;

    public CollisionRect()
    {
        x = 0.0D;
        y = 0.0D;
        width = 0;
        height = 0;
    }

    public void grow(int i, int j)
    {
        if(i >= 0)
        {
            width += i;
        } else
        {
            x += i;
            width -= i;
        }
        if(j >= 0)
        {
            height += j;
            return;
        } else
        {
            y += j;
            height -= j;
            return;
        }
    }

    public void shrink(int i, int j)
    {
        if(i >= 0)
        {
            width -= i;
        } else
        {
            x -= i;
            width += i;
        }
        if(j >= 0)
        {
            height -= j;
            return;
        } else
        {
            y -= j;
            height += j;
            return;
        }
    }

    public boolean intersects(CollisionShape collisionshape)
    {
        if(x < collisionshape.getX())
        {
            e = (int)x;
            f = (int)Math.ceil(collisionshape.getX());
        } else
        {
            e = (int)Math.ceil(x);
            f = (int)collisionshape.getX();
        }
        return e + width > f && e < f + collisionshape.getWidth() && y + (double)height > collisionshape.getY() && y < collisionshape.getY() + (double)collisionshape.getHeight();
    }

    public void setBounds(double d, double d1, int i, int j)
    {
        x = d;
        y = d1;
        width = i;
        height = j;
    }

    public void setBounds(CollisionRect collisionrect)
    {
        setBounds(collisionrect.x, collisionrect.y, collisionrect.width, collisionrect.height);
    }

    public void setLocation(double d, double d1)
    {
        x = d;
        y = d1;
    }

    public void move(double d, double d1)
    {
        x += d;
        y += d1;
    }

    public double getX()
    {
        return x;
    }

    public double getY()
    {
        return y;
    }

    public int getWidth()
    {
        return width;
    }

    public int getHeight()
    {
        return height;
    }

    public String toString()
    {
        return super.toString() + " " + "[x=" + x + ", y=" + y + ", width=" + width + ", height=" + height + "]";
    }
}

⌨️ 快捷键说明

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