private async void PokeballUpdateLoop(ThreadPoolTimer timer) { if (UpdateLoopMutex.WaitOne(0)) { var curTime = DateTime.Now; // timeDelta is the seconds since last update var timeDelta = (curTime - prevTime).Milliseconds / 1000f; var 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(); GameClient.CurrentSession.Logger.Info("Hit Pokemon! " + ThrowItemPosition.X + ", " + ThrowItemPosition.Y + ", " + ThrowItemPosition.Z); } else if (ThrowItemPosition.Y > 50) { // We missed the pokemon... timer.Cancel(); pokeballStopped = true; GameClient.CurrentSession.Logger.Info("Missed Pokemon! " + ThrowItemPosition.X + ", " + ThrowItemPosition.Y + ", " + ThrowItemPosition.Z); } UpdateLoopMutex.ReleaseMutex(); await PokeballTransform.Dispatcher.RunAsync(CoreDispatcherPriority.High, () => { PokeballTransform.TranslateX = translateX; PokeballTransform.TranslateY = translateY; PokeballTransform.ScaleX = scaleX; PokeballTransform.ScaleY = scaleY; if (pokeballStopped) { if (pokemonHit) { // TODO: il casino è qua, se parte l'animazione poi non funziona più il movimento ViewModel.UseSelectedCaptureItem.Execute(true); var last = ViewModel.LastItemUsed; if (last != null) { if (last == ItemId.ItemRazzBerry || last == ItemId.ItemBlukBerry || last == ItemId.ItemNanabBerry || last == ItemId.ItemPinapBerry || last == ItemId.ItemWeparBerry) { ReInitItemLocation(); return; } } CatchStarted.Begin(); ViewModel.PokeballButtonEnabled = false; } else { // TODO: move the missed command if you want ViewModel.UseSelectedCaptureItem.Execute(false); ReInitItemLocation(); } } }); } }
private async void PokeballUpdateLoop(ThreadPoolTimer timer) { if (UpdateLoopMutex.WaitOne(0)) { var curTime = DateTime.Now; // timeDelta is the seconds since last update var timeDelta = (curTime - prevTime).Milliseconds / 1000f; var 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); } UpdateLoopMutex.ReleaseMutex(); await PokeballTransform.Dispatcher.RunAsync(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; } } }); } }