碰撞问题

时间:2017-11-10 12:16:13

标签: c# xna monogame

正如您在this picture中所看到的,我的角色正在飞翔。

碰撞盒在左侧和右侧扩展了3个区块,但碰撞盒的高度不会扩大。

这是我的碰撞检测代码:

    public bool Intersects(Vector2 texture1, Vector2 textureSize1, Vector2 texture2, Vector2 textureSize2)
    {
        if (texture1.X < texture2.X + textureSize2.X && texture1.X + textureSize1.X > texture2.X && texture1.Y < texture2.Y + textureSize2.Y && textureSize1.Y + texture1.Y > texture2.Y) return true;
        return false;
    }

    public Block IsColliding(Vector2 position, float width, float height)
    {

        if (currentWorld == null) return null;
        foreach (Block block in currentWorld.blocks)
        {
            if (Intersects(position, new Vector2(width, height), block.position, new Vector2(block.texture.Bounds.Width, block.texture.Bounds.Height)))
            {
                ScreenManager.Instance.Draw(ContentManager.Instance.content.Load<Texture2D>("barrier"), position, new Vector2(width, height));
                return block;
            }
        }
        return null;
    }

0 个答案:

没有答案