示例#1
0
    private void HandleLaunchAiming()
    {
        Vector2 mousePosition = GetMousePosition();

        AimingEndPos = mousePosition;

        // Draw some kind of aiming arrow?

        if (Input.GetMouseButtonUp(0))
        {
            // Enable physics
            puckBody.bodyType = RigidbodyType2D.Dynamic;

            // Calculate launch vector and apply it to the Puck
            Vector2 launchVector = AimingEndPos - AimingStartPos;
            Vector2 launchDir    = launchVector / launchVector.magnitude;
            float   launchPower  = launchVector.magnitude > gameSettings.maxLaunchPower ? gameSettings.maxLaunchPower : launchVector.magnitude;
            puckBody.AddForce(launchDir * launchPower, ForceMode2D.Impulse);

            // Notify everyone we launched the Puck
            PuckLaunchEvent puckLaunchEvent = new PuckLaunchEvent()
            {
                aimingEndPos = mousePosition,
                launchPower  = launchPower,
                launchDir    = launchDir
            };
            EventManager.Instance.NotifyListeners(puckLaunchEvent);
        }
    }
示例#2
0
 public void OnPuckLaunch(PuckLaunchEvent puckLaunchEvent)
 {
     Debug.Log($"GameStateManager handling PuckLaunchEvent. CurrentState={State}, Event={puckLaunchEvent}");
     if (State != MainGameState.LAUNCH_AIMING)
     {
         throw new InvalidOperationException("PuckLaunchEvent should only occur during LAUNCH_AIMING state");
     }
     State = MainGameState.PUCK_DROPPING;
 }