Beispiel #1
0
        internal bool Collide(Vector2 position)
        {
            var collided = false;

            if (Scene == null)
            {
                return(false);
            }

            foreach (var actor in Scene.GetActors().Where(a => a.Collidable && ((a.CollisionGroup & CollidesWith) > 0) && a != this))
            {
                var diff     = actor.Position - position;
                var dist2    = diff.LengthSquared();
                var radiiSum = (actor.Size * 0.5f) + (Size * 0.5f);
                if (dist2 > radiiSum * radiiSum)
                {
                    continue;
                }
                var dist           = MathF.Sqrt(dist2);
                var distanceToMove = radiiSum - dist;
                diff.Normalize();
                position -= diff * distanceToMove;
                //Speed.X *= -1f;
                //Speed.Y *= -1f;
                CollidedWith = actor;
                collided     = true;
            }
            if (collided)
            {
                Position = position;
            }

            return(collided);
        }