/// <summary> /// Allows this instance to execute custom logic during its <c>Update</c>. /// </summary> /// <param name="gameTime">The game time.</param> /// <remarks> /// This method will not be executed if it are not <c>Active</c>. /// </remarks> protected override void Update(TimeSpan gameTime) { Input input = WaveServices.Input; if (this.gamePlayScene.CurrentState == GamePlayScene.States.TapToStart) { if (input.TouchPanelState.Count > 0) { this.gamePlayScene.CurrentState = GamePlayScene.States.HurryUp; SoundsManager.Instance.PlaySound(SoundsManager.SOUNDS.Button); } } else if (this.gamePlayScene.CurrentState == GamePlayScene.States.Ready) { if (this.lastState != GamePlayScene.States.Ready) { this.ResetMatch(); } } else if (this.gamePlayScene.CurrentState == GamePlayScene.States.GamePlay) { if (this.lastState != GamePlayScene.States.GamePlay) { this.scoreboardPanel.Reset(); this.CreateBall(); } else { Vector2 ballPosition = new Vector2(ballTransform.X, ballTransform.Y); // Update time this.scoreboardPanel.Time -= gameTime; if (this.scoreboardPanel.Time < TimeSpan.FromSeconds(10) && this.lastTime.Seconds > this.scoreboardPanel.Time.Seconds) { SoundsManager.Instance.PlaySound(SoundsManager.SOUNDS.Digit); } else if (this.scoreboardPanel.Time < TimeSpan.Zero) { this.scoreboardPanel.Time = TimeSpan.Zero; this.gamePlayScene.CurrentState = GamePlayScene.States.TimeOut; } this.lastTime = this.scoreboardPanel.Time; // Launch ball if (input.TouchPanelState.Count > 0 && input.TouchPanelState[0].Position.Y > 80) { // Target this.touchPosition = input.TouchPanelState[0].Position; WaveServices.ViewportManager.RecoverPosition(ref this.touchPosition); this.targetTransform.X = this.touchPosition.X; this.targetTransform.Y = this.touchPosition.Y; this.target.IsVisible = true; this.launch = true; } else { this.target.IsVisible = false; if (this.launch) { this.launch = false; // launch ball this.rigidBodyBall.CollidesWith = Physic2DCategory.All; this.rigidBodyBall.PhysicBodyType = PhysicBodyType.Dynamic; this.ballSprite.TintColor = Color.White; Vector2 direction = (this.touchPosition - ballPosition) / FORCE; this.rigidBodyBall.ApplyLinearImpulse(direction - Vector2.UnitY * 1f); this.rigidBodyBall.ApplyAngularImpulse((float)(WaveServices.Random.NextDouble() - 0.5f) * 0.4f); this.gamePlayScene.scoreboardPanel.NumLaunches++; // Create new ball this.CreateBall(); } } } } this.lastState = this.gamePlayScene.CurrentState; }