예제 #1
0
        private static void BoundFrom(MovableEntity mov, Entity ent)
        {
            int       replay = 0;
            FloatRect rect   = mov.GetFloatRect();

            while (CollisionDetector.IsSticking(rect, ent.GetFloatRect()))
            {
                float angle = (float)(Math.PI - Math.Atan2(mov.PreviousVelocity.Y, mov.PreviousVelocity.X) * 2);
                if (mov.GetType() == Entities.EntitiesContainer.Ball.GetType() && ent.GetType() == Entities.EntitiesContainer.Player1.GetType())
                {
                    angle = GetValidAngleForBallAndPlayer(mov, ent);
                    Entities.EntitiesContainer.Ball.WasHitWith(Entities.EntitiesContainer.GetPlayer(ent.ID));
                    AudioSystem.AudioController.PlaySound("HIT");
                }
                mov.Velocity = GetBoundVector(mov, angle, replay > 0 ? true : false);
                rect.Left    = mov.GetFloatRect().Left + mov.Velocity.X;
                rect.Top     = mov.GetFloatRect().Top + mov.Velocity.Y;
                replay++;

                if (replay > 3)
                {
                    mov.ResetPosition();
                }
            }
        }