private DispatcherTimer timer; // the game timer. #endregion Fields #region Constructors public MainWindow() { InitializeComponent(); pinata = new Pinata(); bat = new Bat(); highestPlayers = new ThePlayer[10]; mediaPlayer = new MediaPlayer(); mediaPlayer.Open(new Uri("../../sounds/Epic Star Wars Music Compilation - Star Wars.mp3", UriKind.Relative)); mediaPlayer.Play(); startedGame = false; ToggleMainMenu(true); }
// generates the algorithm for collision between the bat and pinata. public bool IsCollision(Pinata pinata) { if (batState == BatState.Forwards && collided == false) { RotateTransform rotation = eLine.RenderTransform as RotateTransform; double radius = pinata.MyEllipse.Width / 2; Point p2 = rotation.Transform(new Point(eLine.X2, eLine.Y2)); if (p2.X <= pinata.MyEllipseCenterPoint.X + (radius) && p2.Y <= pinata.MyEllipseCenterPoint.Y + (radius)) { collided = true; swung = false; return true; } } return false; }