Beispiel #1
0
 void Revive()
 {
     ballState = BallStates.STICKING;
     trail.Play();
     circle.Play();
     sr.enabled = true;
 }
        public IBallState OnExitTo(BallStates nextState)
        {
            // Do cleanup here

            // get the next state and return it to provide
            // fluent configuration
            return(ballScript.States[nextState]);;
        }
Beispiel #3
0
        public BallState BallSpawned()
        {
            var ballState = new BallState();

            BallStates.Add(ballState);

            return(ballState);
        }
Beispiel #4
0
 /// <summary>
 /// Awake is called when the script instance is being loaded.
 /// </summary>
 void Awake()
 {
     levelManager  = GameObject.FindGameObjectWithTag("LevelManager");
     ballManager   = levelManager.GetComponent <BallManager>();
     ballState     = GetComponent <BallStates>();
     ballRigidbody = GetComponent <Rigidbody>();
     ballCollider  = GetComponent <Collider>();
 }
Beispiel #5
0
 void EndGame()
 {
     transform.position = new Vector3(0, 0, 0);
     rb.velocity        = new Vector2(0, 0);
     sr.enabled         = false;
     trail.Stop();
     circle.Stop();
     ballState = BallStates.STICKING;
 }
Beispiel #6
0
 /// <summary>
 /// Creates an instance of a ball object and gives it an initial velocity
 /// </summary>
 void CreateBall()
 {
     if ((currentNumberOfBalls < maxNumberOfBalls) && (isPlayerWithinRange == true) && (playerHealth.currentHealth > 0))
     {
         Rigidbody newBallInstance = ballManager.CreateNewBall(fireTransform.position, fireTransform.rotation);
         newBallInstance.velocity = ballSpeed * fireTransform.forward;
         BallStates ballStateInstance = newBallInstance.gameObject.GetComponent <BallStates>();
         ballStateInstance.ChangeBallState(2);
     }
 }
Beispiel #7
0
 /// <summary>
 /// Calculate and apply a new velocity to all balls in the bat swing area + change the state to not hurt the player.
 /// </summary>
 private void ApplyNewVelocity()
 {
     if (Input.GetButtonDown("Fire1") && !animator.GetBool("IsGuard"))
     {
         foreach (Rigidbody ballInstance in ballColliders)
         {
             ballInstance.velocity = newballSpeed * BatArea.forward;
             BallStates ballStateInstance = ballInstance.gameObject.GetComponent <BallStates>();
             ballStateInstance.ChangeBallState(1);
         }
     }
 }
Beispiel #8
0
        public static IBallState CreateState(BallStates state, GameObject ball)
        {
            switch (state)
            {
            case BallStates.Moving:
                return(new StateMoving(ball));

            case BallStates.outOfBounds:
                return(new StateOutOfBounds(ball));

            default:
                return(null);
            }
        }
        public IBallState OnExitTo(BallStates nextState)
        {
            // do any cleanup here

            // unsubscribe form former subscribtions to particular events
            if (nvp_EventManager_scr.INSTANCE != null)
            {
                nvp_EventManager_scr.INSTANCE.UnsubscribeFromEvent(GameEvents.onBallHitsPlayer, OnBallHitsPlayer);
                nvp_EventManager_scr.INSTANCE.UnsubscribeFromEvent(GameEvents.onChangeDirectionInStartScreen, OnChangeDirectionByEvent);
            }
            // get the next state and return it to provide
            // fluent configuration
            return(ballScript.States[nextState]);
        }
Beispiel #10
0
        public void BallDropped(BallState state)
        {
            BallStates.Remove(state);

            HudState.SetLivesChanged(--Lives);

            if (Lives > 0)
            {
                PaddleState.SpawnNewBall();
            }
            else
            {
                GameManager.Instance.Defeat();
            }
        }
Beispiel #11
0
    void Update()
    {
        if (ballState == BallStates.Idle)
        {
            currentSpeed       = baseSpeed;
            transform.position = myPaddleTrans.position + new Vector3(0, myPaddleTrans.localScale.y / 2 + transform.localScale.y / 2, 0);

            if (cube.transform.localScale.x < 3)
            {
                ballState      = BallStates.Active;
                movementVector = new Vector3(currentSpeed, currentSpeed, 0);
            }
        }

        if (ballState == BallStates.Active)
        {
            transform.position += movementVector * Time.deltaTime;
        }
    }
Beispiel #12
0
    // Update is called once per frame
    void Update()
    {
        switch (m_BallState)
        {
        case BallStates.Idle:
            this.transform.position = m_Paddle.transform.position + paddleToBallVector;

            if (Input.GetMouseButton(0))
            {
                Rigidbody2D myRigidBody = this.GetComponent <Rigidbody2D>();
                myRigidBody.velocity = new Vector2(2.0f, 10.0f);
                m_BallState          = BallStates.Launched;
            }
            break;

        case BallStates.Launched:
            break;

        default:
            break;
        }
    }
Beispiel #13
0
 public static void SetBallState(BallStates state)
 {
     if (!init)
         Init();
     //No duplicate states
     if (ballStates.Count == 0 || ballStates.Last.Value != state)
         ballStates.AddLast(state);
 }
Beispiel #14
0
 void DeathBeforeAd()
 {
     transform.position = new Vector3(0, 0, 0);
     rb.velocity        = new Vector2(0, 0);
     ballState          = BallStates.STICKING;
 }
Beispiel #15
0
 public void PushBall()
 {
     speed       = ballControl.GetBallSpeed();
     ballState   = BallStates.PLAYING;
     rb.velocity = -rb.position.normalized * speed;
 }
Beispiel #16
0
 public void Play()
 {
     ballState = BallStates.STICKING;
 }