Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (!Game.Instance.IsGameGoing())
        {
            return;
        }

        Vector3 inputVector = Vector3.zero;

        if (docked)
        {
            if (Input.GetKey(KeyCode.Space))
            {
                _currentStation.Deactivate();
                docked          = false;
                _currentStation = null;
            }
        }

        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            inputVector       += Vector3.Lerp(previousInputVector, Vector3.left * HorizontalMovementSpeed, HorizontalAcceleration * Time.deltaTime);
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.AngleAxis(RotationAmount, Vector3.forward), RotationSpeed * Time.deltaTime);
        }
        else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            inputVector       += Vector3.Lerp(previousInputVector, Vector3.right * HorizontalMovementSpeed, HorizontalAcceleration * Time.deltaTime);
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.AngleAxis(-RotationAmount, Vector3.forward), RotationSpeed * Time.deltaTime);
        }
        else
        {
            inputVector       += Vector3.Lerp(previousInputVector, Vector3.zero, HorizontalDeceleration * Time.deltaTime);
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.AngleAxis(0, Vector3.forward), RotationCorrectionSpeed * Time.deltaTime);
        }

        TryToMove(inputVector * Time.deltaTime, inputVector * Time.deltaTime);

        timeSinceLastCollision += Time.deltaTime;
        if (colliding || timeSinceLastCollision < .5f)
        {
            DefaultVelocity = Vector3.MoveTowards(DefaultVelocity, OppositeVelocity, 10f * Time.deltaTime);
        }
        else
        {
            DefaultVelocity = Vector3.MoveTowards(DefaultVelocity, GoalVelocity, 10f * Time.deltaTime);
        }

        if (!docked)
        {
            TryToMove(DefaultVelocity * Time.deltaTime, DefaultVelocity * Time.deltaTime);
        }

        previousInputVector = inputVector;
    }
Example #2
0
    void GenerateObstaclesUpTo(float height)
    {
        if (_nextObstacleHeight > height)
        {
            return;
        }

        if (_obstaclesUntilStation == 0)
        {
            Vector3 sellingPosition = new Vector3(0, _nextObstacleHeight, 0);
            sellingPosition.x = Random.Range(LeftWall.GetObstacleX() + Obstacle.MinSize, RightWall.GetObstacleX() - Obstacle.MinSize);
            var proportion = (sellingPosition.x - LeftWall.GetObstacleX() - Obstacle.MinSize) / (RightWall.GetObstacleX() - LeftWall.GetObstacleX() - 2f * Obstacle.MinSize);

            _latestSellingStation = Game.Instance.CreateSellingStation(sellingPosition, transform);

            //Generate obstacles on either side of the selling station
            Vector3 leftObstaclePosition  = sellingPosition;
            Vector3 rightObstaclePosition = sellingPosition;
            leftObstaclePosition.x  = LeftWall.GetObstacleX();
            rightObstaclePosition.x = RightWall.GetObstacleX();

            //TODO: there's a good chance this introduced a scale change, but revisit after the art is done.
            var leftObstacle  = Game.Instance.CreateObstacle(leftObstaclePosition, null);
            var rightObstacle = Game.Instance.CreateObstacle(rightObstaclePosition, null);

            leftObstacle.DontSpawnBalls();
            rightObstacle.DontSpawnBalls();

            leftObstacle.SetSize(proportion, false);
            rightObstacle.SetSize(1f - proportion, true);

            _lastObstacleCreatedAt = sellingPosition.y;
            _nextObstacleHeight    = _lastObstacleCreatedAt + ObstacleSpacing + Random.value * ObstacleSpacing + InitialObstacleHeight;

            _obstaclesUntilStation = (int)Mathf.Min(InitialObstaclesUntilStation + (Random.value * ((Game.Instance.TimeSinceGameStart() / 20f))) + 1, 20);
        }
        else
        {
            float side = (Random.value > .5) ? -1f : 1f;

            Vector3 obstaclePosition = new Vector3(0, _nextObstacleHeight, 0);
            obstaclePosition.x = (side == -1) ? LeftWall.GetObstacleX() : RightWall.GetObstacleX();

            var newObstacle = Game.Instance.CreateObstacle(obstaclePosition, transform);

            newObstacle.SetSize(Random.value, side == 1);

            _lastObstacleCreatedAt = obstaclePosition.y;
            _nextObstacleHeight    = _lastObstacleCreatedAt + ObstacleSpacing + Random.value * ObstacleSpacing;

            //Debug.Break();
            _obstaclesUntilStation--;
        }
    }
Example #3
0
 // Use this for initialization
 void Start()
 {
     sellingStation = transform.parent.GetComponent <SellingStation>();
 }
Example #4
0
 public void DockAtStation(SellingStation station)
 {
     //TODO: Probably smoothly animate you to a "resting" position.
     docked          = true;
     _currentStation = station;
 }