/// <summary> /// *magic* Makes the game work. Creates, refreshes and deletes the arrows. /// </summary> void mainLoop() { double commonValue = SystemParameters.PrimaryScreenHeight / (double)reactiontime; long lastElapsed = 0; try { while (true) { long elapsed = GameStateManager.CurrentTime; //Console.WriteLine("Let's Lag!"); if (lastElapsed < elapsed) { lastElapsed = elapsed; if (accuracyDisplayRemaining >= 1) { if (elapsed % 30 == 0) { accuracyDisplayRemaining--; if (accuracyDisplayRemaining == 1) { Application.Current.Dispatcher.Invoke(new Action((() => { lastAccuracyLabel.Visibility = Visibility.Hidden; }))); } } } ArrowMover[] l = new ArrowMover[arrowMovers.Count]; arrowMovers.CopyTo(l); foreach (ArrowMover currentArrowMover in l) { if (currentArrowMover.MovingState == 0 && Now2ms() - startTime >= (currentSong.Notes[lastNoteStarted].Position() - reactiontime)) { Console.WriteLine("Started note"); currentArrowMover.MovingState = 1; lastNoteStarted++; } if (currentArrowMover.MovingState == 1) { Application.Current.Dispatcher.Invoke(new Action(() => { try { Canvas.SetTop(currentArrowMover.Arrow, (currentArrowMover.note.StartTime() * commonValue + yOffset) - (elapsed * commonValue)); } catch { Console.WriteLine("ERROR in dispatch"); } })); } } if (dealtNotes == currentSong.Notes.Count) { Console.WriteLine("dealtNotes: {0}, count: {1}", dealtNotes, currentSong.Notes.Count); Console.WriteLine("Game Over!"); gameoverClock.Start(); break; } if (!arrowMovers.Any()) { break; } } } } catch { Console.WriteLine("ERROR"); } Console.WriteLine("Out of loop"); }
/// <summary> /// Implements the Countdown... nothing else, really! /// </summary> async void countdownTimer_Tick(object sender, EventArgs e) { countdownTimer.Stop(); switch (--secondsBeforeGameStarts) { case 4: { CountdownDisplayer5.Visibility = Visibility.Hidden; CountdownDisplayer4.Visibility = Visibility.Visible; Console.Write("Info: Game starts in 4... "); await Task.Factory.StartNew(() => { arrowMovers = new List <ArrowMover>(); foreach (Note n in currentSong.Notes) { ArrowMover newAM = new ArrowMover(n, reactiontime, arrowTravelLayer); Canvas.SetTop(newAM.Arrow, (SystemParameters.PrimaryScreenHeight * (n.StartTime() / (double)reactiontime)) + yOffset); Console.WriteLine("Setting top to: {0}", (SystemParameters.PrimaryScreenHeight * (n.StartTime() / (double)reactiontime)) + yOffset); if (reactiontime > n.StartTime()) { newAM.MovingState = 1; } arrowMovers.Add(newAM); } arrowTravelLayer.InvalidateVisual(); KinectStreamDisplay.Source = colorBitmap; }, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.FromCurrentSynchronizationContext()); break; } case 3: { CountdownDisplayer4.Visibility = Visibility.Hidden; CountdownDisplayer3.Visibility = Visibility.Visible; Console.Write("3... "); break; } case 2: { CountdownDisplayer3.Visibility = Visibility.Hidden; CountdownDisplayer2.Visibility = Visibility.Visible; Console.Write("2... "); break; } case 1: { CountdownDisplayer2.Visibility = Visibility.Hidden; CountdownDisplayer1.Visibility = Visibility.Visible; Console.WriteLine("1... "); break; } case 0: { await Task.Factory.StartNew(() => { CountdownDisplayer1.Visibility = Visibility.Hidden; }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); ingameClock.Start(); App.Gms.Start(); break; } } if (secondsBeforeGameStarts > 0) { countdownTimer.Interval = new TimeSpan(0, 0, 1); countdownTimer.Start(); } }