当前位置: 首页>>代码示例>>C#>>正文


C# ICollidable.GetVelocityVector方法代码示例

本文整理汇总了C#中ICollidable.GetVelocityVector方法的典型用法代码示例。如果您正苦于以下问题:C# ICollidable.GetVelocityVector方法的具体用法?C# ICollidable.GetVelocityVector怎么用?C# ICollidable.GetVelocityVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICollidable的用法示例。


在下文中一共展示了ICollidable.GetVelocityVector方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnLadder

        public bool OnLadder(ICollidable obj, out int x, out int y)
        {
            floatRectangle objRect = obj.GetBoundingBox();
            Vector2 objVel = obj.GetVelocityVector();

            x = 0;
            y = 0;

            if (objRect.Top() > m_tileHeight * m_height || objRect.Bottom() < 0
                || objRect.Left() > m_tileWidth * m_width || objRect.Right() < 0)
                return false;

            Rectangle tileRect = new Rectangle();
            tileRect.X = (int)objRect.X / m_tileWidth;
            tileRect.Y = (int)objRect.Y / m_tileHeight;
            tileRect.Width = (int)objRect.Width / m_tileWidth;
            tileRect.Height = (int)objRect.Height / m_tileHeight;

            if (tileRect.X < 0) tileRect.X = 0;
            if (tileRect.Y < 0) tileRect.Y = 0;
            if (tileRect.Right >= m_width)
                tileRect.Width = m_width - tileRect.X - 1;
            if (tileRect.Bottom >= m_height)
                tileRect.Height = m_height - tileRect.Y - 1;

            for (int j = tileRect.Top; j <= tileRect.Bottom; ++j)
            {
                for (int i = tileRect.Left; i <= tileRect.Right; ++i)
                {
                    if (m_tiles[m_map[i, j]].m_type == Tile.TileType.LADDER)
                    {
                        x = i * m_tileWidth;
                        y = j * m_tileHeight;
                        return true;
                    }
                }
            }
            return false;
        }
开发者ID:aplusbi,项目名称:ggj2010,代码行数:39,代码来源:TileMap.cs

示例2: Collide

        public Vector2 Collide(ICollidable obj, out bool hit)
        {
            hit = false;
            floatRectangle objInitRect = obj.GetBoundingBox();
            Vector2 objVel = obj.GetVelocityVector();
            floatRectangle objRect = new floatRectangle(objInitRect.X + objVel.X,
                objInitRect.Y + objVel.Y, objInitRect.Width, objInitRect.Height);

            if (objRect.Top() > m_tileHeight * m_height || objRect.Bottom() < 0
                || objRect.Left() > m_tileWidth * m_width || objRect.Right() < 0)
                return objVel;

            Rectangle tileRect = new Rectangle();
            tileRect.X = (int)objRect.X / m_tileWidth;
            tileRect.Y = (int)objRect.Y / m_tileHeight;
            tileRect.Width = (int)objRect.Width / m_tileWidth;
            tileRect.Height = (int)objRect.Height / m_tileHeight;

            floatRectangle objRectX = new floatRectangle(objInitRect.X + objVel.X, objInitRect.Y + 1,
                objInitRect.Width, objInitRect.Height - 1);
            floatRectangle objRectY = new floatRectangle(objInitRect.X + 1, objInitRect.Y + objVel.Y,
                objInitRect.Width - 1, objInitRect.Height);

            if (tileRect.X < 0) tileRect.X = 0;
            if (tileRect.Y < 0) tileRect.Y = 0;
            if (tileRect.Right >= m_width)
                tileRect.Width = m_width - tileRect.X - 1;
            if (tileRect.Bottom >= m_height)
                tileRect.Height = m_height - tileRect.Y - 1;

            for (int j = tileRect.Top; j <= tileRect.Bottom; ++j)
            {
                for (int i = tileRect.Left; i <= tileRect.Right; ++i)
                {
                    if (m_tiles[m_map[i, j]].m_type == Tile.TileType.NONE
                        || m_tiles[m_map[i, j]].m_type == Tile.TileType.LADDER)
                        continue;

                    floatRectangle currRect = new floatRectangle(i * m_tileWidth, j * m_tileHeight,
                        m_tileWidth, m_tileHeight);

                    if (objVel.X > 0)
                    {
                        if (objRectX.Right() > currRect.Left()
                            && objRectX.Top() < currRect.Bottom() && objRectX.Bottom() > currRect.Top())
                        {
                            hit = true;
                            objVel.X = currRect.Left() - objInitRect.Right();
                            if (objVel.X < 0)
                                objVel.X = 0;
                        }
                    }
                    else
                    {
                        if (objRectX.Left() < currRect.Right()
                            && objRectX.Top() < currRect.Bottom() && objRectX.Bottom() > currRect.Top())
                        {
                            hit = true;
                            objVel.X = currRect.Right() - objInitRect.Left();
                            if (objVel.X > 0)
                                objVel.X = 0;
                        }
                    }
                    if (objVel.Y > 0)
                    {
                        if (objRectY.Bottom() > currRect.Top()
                            && objRectY.Left() < currRect.Right() && objRectY.Right() > currRect.Left())
                        {
                            hit = true;
                            objVel.Y = currRect.Top() - objInitRect.Bottom();
                            if (objVel.Y < 0)
                                objVel.Y = 0;
                        }
                    }
                    //else
                    //{
                    //    hit = true;
                    //    if (objRectY.Top() < currRect.Bottom()
                    //        && objRectY.Left() < currRect.Right() && objRectY.Right() > currRect.Left())
                    //    {
                    //        objVel.Y = currRect.Bottom() - objInitRect.Top();
                    //        if (objVel.Y > 0)
                    //            objVel.Y = 0;
                    //    }
                    //}
                }
            }
            return objVel;
        }
开发者ID:aplusbi,项目名称:ggj2010,代码行数:89,代码来源:TileMap.cs

示例3: WillCollide

        public bool WillCollide(ICollidable other)
        {
            floatRectangle theirs = other.GetBoundingBox();
            Vector2 vel = other.GetVelocityVector();

            floatRectangle mine = new floatRectangle(m_rect.X + m_vec.X,
                m_rect.Y + m_vec.X, m_rect.Width, m_rect.Height);

            theirs.X += vel.X;
            theirs.Y += vel.Y;

            if (mine.Right() > theirs.Left() && mine.Left() < theirs.Right()
                && mine.Bottom() > theirs.Top() && mine.Top() < theirs.Bottom())
            {
                return true;
            }
            return false;
        }
开发者ID:aplusbi,项目名称:ggj2010,代码行数:18,代码来源:ICollidable.cs


注:本文中的ICollidable.GetVelocityVector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。