コード例 #1
0
        public bool ApplyOverheadCheck(IBoundingBox entity, IEnumerable <IBoundingBox> entities, Func <IBoundingBox, bool> ground, float yGravity, bool bounce)
        {
            var entityExtended = new BoundingBox
            {
                LocalMatrix = entity.GetFinalMatrix() * Matrix.CreateTranslation(0, -1, 0),
                Width       = entity.Width,
                Height      = entity.Height,
                XSpeed      = 0,
                YSpeed      = 0
            };
            var collidableEntities = entities.Where(ground).Where(x => x != entity).ToArray();

            foreach (var collidableEntity in collidableEntities)
            {
                if (this.m_BoundingBoxUtilities.Overlaps(entityExtended, collidableEntity))
                {
                    if (bounce)
                    {
                        if (yGravity > 0)
                        {
                            entity.YSpeed = Math.Abs(entity.YSpeed);
                        }
                        else
                        {
                            entity.YSpeed = -Math.Abs(entity.YSpeed);
                        }
                    }
                    else
                    {
                        entity.YSpeed = 1;
                    }
                    return(true);
                }
            }

            return(false);
        }