Esempio n. 1
0
        /// <summary>
        /// The method to launch extra balls.
        /// </summary>
        /// <param name="location">Transform giving the position,
        /// you can use an empty gameobject linked to launching object.</param>
        /// <param name="impulse">You can give the ball a "kick" when launching. Use null or Vector3.zero if not needed.</param>
        public void ExtraBall(Transform location, Vector3 impulse)
        {
            // Use a deactivated ball if possible.
            Pinball ball = RecycleBall();

            // If not create a new ball from prefab.
            if (!ball)
            {
                ball = CreateNewBall();
            }
            // If it was found activate it.
            else
            {
                ball.gameObject.SetActive(true);
            }

            // Update active ball counter and set ball location.
            AdjustActiveBallCounter(true);
            ball.transform.position = location.position;

            // If given a valid impulse vector apply it.
            if (impulse != null && !impulse.Equals(Vector3.zero))
            {
                ball.AddImpulseForce(impulse);
            }
        }
        /// <summary>
        /// The method to launch extra balls.
        /// </summary>
        public void LaunchExtraBall()
        {
            if (_location == null)
            {
                Debug.LogError("No extra ball launch location set.");
                return;
            }

            // Use a deactivated ball if possible.
            Pinball ball = PinballManager.Instance.RecycleBall();

            // If not create a new ball from prefab.
            if (!ball)
            {
                ball = PinballManager.Instance.CreateNewBall();
            }
            // If it was found activate it.
            else
            {
                ball.gameObject.SetActive(true);
            }

            LaunchExtraBall(ball);

            //Debug.Log("Extra balls left to spawn: " + _ballsLeftToSpawn);
        }
Esempio n. 3
0
 protected virtual void KickOut()
 {
     _ball.IsInKickoutHole = false;
     _ball.SetPhysicsEnabled(true);
     _startTime = -1;
     _ball      = null;
 }
Esempio n. 4
0
        public Pinball CreateNewBall()
        {
            Pinball ball = Instantiate(_pinballPrefab);

            ball.Init(true);
            _pinballs.Add(ball);
            return(ball);
        }
Esempio n. 5
0
        private void OnCollisionEnter(Collision collision)
        {
            Pinball ball = collision.gameObject.GetComponent <Pinball>();

            if (ball != null && !Launcher.Instance.BallOnLauncher)
            {
                Launcher.Instance.StartLaunch(ball);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Shoot again, autosave or remove ball?
        /// </summary>
        /// <param name="pinball">A drained pinball</param>
        /// <returns>Is the ball removed</returns>
        public bool RemoveOrSaveBall(Pinball pinball)
        {
            bool ballRemoved = false;

            // Multiball
            if (_activeBalls > 1)
            {
                AdjustActiveBallCounter(false);
                pinball.gameObject.SetActive(false);

                // Shoot again does not matter; if it's active, it stays active

                // Spawn a new ball
                if (Autosave)
                {
                    _extraBallSpawner.Activate(1, true);
                    ballRemoved = false;
                }
                // Just remove the ball
                else
                {
                    ballRemoved = true;

                    if (_activeBalls == 1)
                    {
                        Debug.Log("All extra balls are drained");
                    }
                }
            }
            // Only one ball
            else
            {
                Tilt = false;

                // Autosave can't be active without multiball

                // Save the ball and put it next to the launcher
                if (ShootAgain || debug_freeBalls)
                {
                    SFXPlayer.Instance.Play(Sound.BallLost);
                    SFXPlayer.Instance.Play(Sound.BallSaved);
                    InstanceNextBall(pinball);
                    ShootAgain  = false;
                    ballRemoved = false;
                }
                // Remove the ball and put it next to the launcher
                else
                {
                    SFXPlayer.Instance.Play(Sound.BallLost);
                    RemoveBall(pinball);
                    ballRemoved = true;
                }
            }

            return(ballRemoved);
        }
Esempio n. 7
0
 public bool BallIncoming(Pinball ball, RampEntrance myEntrance)
 {
     _myEntrance = myEntrance;
     if (_ball != null)
     {
         return(false);
     }
     _ball              = ball;
     _ball.ExitingRamp += BallInsideHole;
     return(true);
 }
Esempio n. 8
0
 protected virtual void OnTriggerEnter(Collider other)
 {
     if (State == CollectableState.Idle)
     {
         Pinball pinball = other.GetComponent <Pinball>();
         if (pinball != null)
         {
             Activate();
         }
     }
 }
 protected virtual void OnTriggerEnter(Collider other)
 {
     if (!resting)
     {
         Pinball pinball = other.GetComponent <Pinball>();
         if (pinball != null)
         {
             resting = true;
             Activate();
         }
     }
 }
Esempio n. 10
0
        public void InstanceNextBall(Pinball pinball)
        {
            pinball.SetPhysicsEnabled(false);

            if (!Launcher.Instance.BallOnLauncher)
            {
                StartCoroutine(BallLaunchArrivalRoutine(pinball));
            }
            else
            {
                pinball.transform.position = _ballLaunchPoint;
                //Debug.LogWarning("A ball may already be in the launch area");
            }

            pinball.SetPhysicsEnabled(true);
            Launcher.Instance.StartLaunch(pinball);
        }
Esempio n. 11
0
        /// <summary>
        /// Takes passing objects velocity and starts rotating the object based on that.
        /// </summary>
        /// <param name="other">Passing object, should always be pinball</param>
        private void OnTriggerEnter(Collider other)
        {
            Pinball pinball = other.GetComponent <Pinball>();
            int     sign    = 1;

            if (pinball != null)
            {
                _rb.angularVelocity = Vector3.zero;
                if (pinball.PhysicsVelocity.z < 0)
                {
                    sign = -1;
                }
                _rb.AddTorque(transform.right * (pinball.Speed * sign) * _spinSpeedMultiplier, ForceMode.Impulse);
                _checkRotation = true;
                _timer         = 0.1f;
                _stabilize     = false;
            }
        }
        private void OnTriggerStay(Collider other)
        {
            Pinball ball = other.GetComponent <Pinball>();

            if (ball != null)
            {
                if (ball.GetComponent <Rigidbody>().velocity.z < 0 && !_skillshotSuccesful)
                {
                    _skillshotSuccesful = true;
                    PathActivate();
                    if (GameManager.Instance.GameMode.State != GameModeStateType.Sampo)
                    {
                        Launcher.Instance.SkillShotSuccesful = true;
                        Scorekeeper.Instance.AddScore(Scorekeeper.ScoreType.Skillshot);
                    }
                }
            }
        }
Esempio n. 13
0
        public void StartLaunch(Pinball pinball)
        {
            BallOnLauncher = true;
            _hitParticles.SetActive(false);
            _pinball = pinball;
            _returnAxeToStartPosition = true;
            _hingejoint.useLimits     = true;
            _gatesClosed = false;
            if (_handler != null)
            {
                _handler.PathDeactivate();
            }

            foreach (SkillShotGate gate in _gates)
            {
                gate.OpenGate();
            }

            Viewscreen.StartLaunch();
        }
Esempio n. 14
0
        private void RemoveBall(Pinball pinball)
        {
            if (!OutOfBalls)
            {
                // Returns the ball next to the launcher
                // and gets whether the ball is lost
                InstanceNextBall(pinball);

                _currentBallCount--;

                if (_currentBallCount == 1)
                {
                    if (GameManager.Instance.GameMode.State ==
                        GameModeStateType.Sampo)
                    {
                        GameManager.Instance.GameMode.
                        Owner.PerformTransition(GameModeStateType.Normal);

                        // TODO: Reset collectable chances
                    }
                }
                else if (OutOfBalls)
                {
                    Viewscreen.OutOfBalls();
                    Debug.Log("Out of balls - game over");
                    //GameManager.Instance.SaveOrRevertHighscores(true);

                    // The game is ended by ScreenState_Play
                }
                else
                {
                    Viewscreen.BallCount(CurrentBallNumber);
                    Debug.Log("Balls left: " +
                              _currentBallCount.ToString());
                }
            }
            else
            {
                Debug.Log("Out of balls");
            }
        }
Esempio n. 15
0
        public bool CheckIfBallIsLost(Pinball pinball)
        {
            if (PositionIsInDrain(pinball.transform.position))
            {
                RemoveOrSaveBall(pinball);

                // If balls are free, a ball in drain is moved
                // back to the launcher without consuming "lives"
                //if (freeBalls)
                //{
                //    InstanceNextBall(pinball);
                //}
                //else
                //{
                //    RemoveBall(pinball);
                //}

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Launches a given ball as an extra ball.
        /// </summary>
        public void LaunchExtraBall(Pinball ball)
        {
            if (_location == null)
            {
                Debug.LogError("No extra ball launch location set.");
                return;
            }

            ball.gameObject.SetActive(true);

            // Update active ball counter and set ball location.
            PinballManager.Instance.AdjustActiveBallCounter(true);
            ball.transform.position = _location.position;

            // If given a valid impulse vector apply it.
            if (_impulse != null && !_impulse.Equals(Vector3.zero))
            {
                ball.AddImpulseForce(_impulse);
            }

            _ballsLeftToSpawn--;
            _mostRecentExtraBall = ball;
        }
Esempio n. 17
0
        private IEnumerator BallLaunchArrivalRoutine(Pinball pinball)
        {
            float ratio = 0;

            _elapsedBallLaunchArrivalTime = 0;

            Vector3 startPosition = _ballLaunchArrivalPoint;

            while (ratio < 1f)
            {
                _elapsedBallLaunchArrivalTime += Time.deltaTime;

                ratio = _elapsedBallLaunchArrivalTime /
                        _ballLaunchArrivalTime;

                pinball.transform.position =
                    Vector3.Lerp(startPosition, _ballLaunchPoint, ratio);

                yield return(0);
            }

            pinball.transform.position = _ballLaunchPoint;
        }
Esempio n. 18
0
 public void InstanceBallToWorkshopKOH(Pinball pinball)
 {
     pinball.transform.position = _workshopLocation.position;
     pinball.StopMotion();
     //pinball.SetPhysicsEnabled(false);
 }
 public void Deactivate()
 {
     _active              = false;
     _elapsedSpawnTime    = 0f;
     _mostRecentExtraBall = null;
 }