public virtual void TouchWall(Wall pWall) { //float rotTmp = _parent.RotationInDegrees; Vector2 AP = _parent.Position - pWall.Position; Vector2 AB = pWall.Direction; float ab2 = AB.X * AB.X + AB.Y * AB.Y; float ap_ab = AP.X * AB.X + AP.Y * AB.Y; float t = ap_ab / ab2; if (true) { if (t < 0.0f) { t = 0.0f; } else if (t > 1.0f) { t = 1.0f; } } Vector2 Closest = pWall.Position + AB * t; AB = Closest - _parent.Position; AP = pWall.Direction; AP.Normalize(); if (Math.Abs(AB.Length()) < _parent.Sprite.Width * _parent.scale / 2) { if (!_wallsTouched.Contains(pWall)) { AB.Normalize(); _parent.Speed = 2 * (Vector2.Dot(_parent.Speed, AP)) * AP - _parent.Speed; if (typeof(EnnemyShip).IsAssignableFrom(_parent.GetType())) { _parent.RotationInRadians = (float)Math.Atan2((double)_parent.Speed.Y, (double)_parent.Speed.X); } _wallsTouched.Add(pWall); if (_weapon) { _parent.Die(); } } } else if (_wallsTouched.Contains(pWall)) { _wallsTouched.Remove(pWall); } //_parent.RotationInDegrees = rotTmp; }