private async void GameManagerViewModelOnCatchEscape(object sender, EventArgs eventArgs) { //CatchEscape.Begin(); //CatchSuccess.SkipToFill(); CatchSuccess.AutoReverse = true; PokeballCatchAnimationStartingTranslateX.Value = PokeballTransform.TranslateX; PokeballCatchAnimationStartingTranslateY.Value = PokeballTransform.TranslateY; PokeballCatchAnimationStartingScaleX.Value = PokeballTransform.ScaleX; PokeballCatchAnimationStartingScaleY.Value = PokeballTransform.ScaleY; await Task.Delay(TimeSpan.FromSeconds(new Random().Next(1, 5))); CatchSuccess.Begin(); CatchEscape.Begin(); //TODO (from advancedrei): This storyboard needs to delay 3 seconds, then reverse the animation so the user can try again. }
private async void PokeballUpdateLoop(ThreadPoolTimer timer) { if (UpdateLoopMutex.WaitOne(0)) { DateTime curTime = DateTime.Now; // timeDelta is the seconds since last update float timeDelta = (curTime - prevTime).Milliseconds / 1000f; Vector3 gravity = new Vector3(0, 300f, 0); // Apply basic Kinematics ThrowItemPosition += (ThrowItemVelocity * timeDelta) + (.5f * gravity * timeDelta * timeDelta); ThrowItemVelocity += (gravity * timeDelta); /* * Logger.Write("Position" + ThrowItemPosition.X + ", " + ThrowItemPosition.Y + ", " + ThrowItemPosition.Z); * Logger.Write("Velocity" + ThrowItemVelocity.X + ", " + ThrowItemVelocity.Y + ", " + ThrowItemVelocity.Z); */ prevTime = curTime; // Shotty attempt at converting from world space to screen space without a matrix var translateX = ThrowItemPosition.X * Math.Max(1.0f - (ThrowItemPosition.Z / 400.0f), 0.0f); var translateY = ThrowItemPosition.Y - (ThrowItemPosition.Z); var scaleX = Math.Max(1.0f - (ThrowItemPosition.Z / 200.0f), 0.0f); var scaleY = scaleX; var pokeballStopped = false; var pokemonHit = false; if (Vector3.DistanceSquared(PokemonPosition, ThrowItemPosition) < PokemonRadiusSq) { // We hit the pokemon! pokeballStopped = true; pokemonHit = true; timer.Cancel(); Logger.Write("Hit Pokemon! " + ThrowItemPosition.X + ", " + ThrowItemPosition.Y + ", " + ThrowItemPosition.Z); } else if (ThrowItemPosition.Y > 50) { // We missed the pokemon... timer.Cancel(); pokeballStopped = true; Logger.Write("Missed Pokemon! " + ThrowItemPosition.X + ", " + ThrowItemPosition.Y + ", " + ThrowItemPosition.Z); // TODO: We need to use up a pokeball on the missed throw } UpdateLoopMutex.ReleaseMutex(); await PokeballTransform.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { PokeballTransform.TranslateX = PokeballCatchAnimationStartingTranslateX.Value = translateX; PokeballTransform.TranslateY = PokeballCatchAnimationStartingTranslateY.Value = translateY; PokeballTransform.ScaleX = PokeballCatchAnimationStartingScaleX.Value = scaleX; PokeballTransform.ScaleY = PokeballCatchAnimationStartingScaleY.Value = scaleY; if (pokeballStopped) { if (pokemonHit) { CatchSuccess.Begin(); ViewModel.UseSelectedCaptureItem.Execute(true); } else { // TODO: move the missed command if you want ViewModel.UseSelectedCaptureItem.Execute(false); PokeballTransform.TranslateX = InitItemX; PokeballTransform.TranslateY = InitItemY; PokeballTransform.ScaleX = 1; PokeballTransform.ScaleY = 1; LaunchPokeballButton.IsEnabled = true; } } }); } }