예제 #1
0
    // Update is called once per frame
    void Update()
    {
        ScrollingController scrollingController = ScrollingController.GetInstance();

        if (player.isActive && player.IsAlive)
        {
            distance += scrollingController.scrollingSpeed * Time.deltaTime;
            distance  = Mathf.Max(0.0f, distance);
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        var scrollingController = ScrollingController.GetInstance();

        var position = transform.position;

        position.x -= scrollingController.scrollingSpeed * Time.deltaTime;
        if (position.x < minX)
        {
            position.x += moveRight;
        }
        transform.position = position;
    }
예제 #3
0
    private void FixedUpdate()
    {
        var scrollingController = ScrollingController.GetInstance();
        var rb = GetComponent <Rigidbody2D>();

        if (rb != null)
        {
            var oldPosition = rb.position;
            oldPosition.x -= scrollingController.scrollingSpeed * scrollingScaling * Time.fixedDeltaTime;
            rb.MovePosition(oldPosition);
            rb.velocity = new Vector2();
        }
        else
        {
            var oldPosition = transform.position;
            oldPosition.x     -= scrollingController.scrollingSpeed * scrollingScaling * Time.fixedDeltaTime;
            transform.position = oldPosition;
        }
    }
예제 #4
0
    private void Update()
    {
        var scrollingController = ScrollingController.GetInstance();
        var delta         = transform.position.x - oldPosition.x + scrollingController.scrollingSpeed * Time.deltaTime;
        var wheelRotation = Quaternion.Euler(0.0f, 0.0f, -delta * wheelRotationScaling);

        wheel.rotation = (wheel.rotation * wheelRotation).normalized;

        var audio = GetComponent <AudioSource>();

        audio.panStereo = transform.position.x / 10.0f;
        oldPosition     = transform.position;

        var alive = IsAlive;

        if (!alive)
        {
            // Enable the animator. This also switches the player to the wrecked state.
            GetComponentInChildren <SpriteAnimationController>().enabled = true;
        }
        else
        {
            var health = GetComponent <HealthController>();
            var state  = Mathf.Max(0, Mathf.Min((int)health.health - 1, states.Length - 1));
            sprite.sprite = states[state];
        }

        if (alive && isActive)
        {
            int alivePlayers = 0;
            foreach (var playerObject in GameObject.FindGameObjectsWithTag(Tags.Player))
            {
                var player = playerObject.GetComponent <PlayerController>();
                if (player.IsAlive && player.isActive)
                {
                    alivePlayers++;
                }
            }
            isLastPlayer = alivePlayers == 1;
        }
    }
예제 #5
0
    void FixedUpdate()
    {
        var scrollingController = ScrollingController.GetInstance();

        var rb = GetComponent <Rigidbody2D>();

        targetPlayer = FindClosestPlayer();
        var playerRb       = targetPlayer.GetComponent <Rigidbody2D>();
        var direction      = playerRb.position - rb.position;
        var targetRotation = Vector2.SignedAngle(Vector2.right, direction);
        // Allow arbitrary rotations when the missile is off the screen. Once it enters the screen
        // apply the rotation limits.
        var rotation = warning != null ?
                       targetRotation : Mathf.MoveTowardsAngle(rb.rotation, targetRotation, maxTurnPerFrame);

        var rotationRad = Mathf.Deg2Rad * rotation;

        direction   = new Vector2(Mathf.Cos(rotationRad), Mathf.Sin(rotationRad));
        rb.velocity = direction * velocity - new Vector2(scrollingController.scrollingSpeed, 0.0f);
        rb.MoveRotation(rotation);
    }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        while (Time.time > lastFrameTime + frameTime)
        {
            currentFrame++;
            lastFrameTime += frameTime;
        }
        if (currentFrame < sprites.Length)
        {
            GetComponent <SpriteRenderer>().sprite = sprites[currentFrame];
        }
        else
        {
            Destroy(gameObject);
        }
        var scrollingController = ScrollingController.GetInstance();
        var position            = transform.position;

        position.x        -= scrollingController.scrollingSpeed * Time.deltaTime;
        transform.position = position;
    }
예제 #7
0
    // Update is called once per frame
    void FixedUpdate()
    {
        var scrollingController = ScrollingController.GetInstance();
        var delta = scrollSpeedFactor * scrollingController.scrollingSpeed * Time.fixedDeltaTime;

        foreach (var child in GetComponentsInChildren <Transform>())
        {
            if (child == transform)
            {
                continue;
            }
            var position = child.position;
            position.x    -= delta;
            child.position = position;

            if (position.x < leftOffset)
            {
                var overlap = position.x - leftOffset;
                Destroy(child.gameObject);
                GenerateNewTile(overlap);
            }
        }
    }
예제 #8
0
    void FixedUpdate()
    {
        Rigidbody2D rb = GetComponentInChildren <Rigidbody2D>();
        var         scrollingController = ScrollingController.GetInstance();

        var scrollVelocity = new Vector2(-scrollingController.scrollingSpeed, 0.0f);

        bool  alive                 = IsAlive;
        float horizontalAxis        = alive ? Input.GetAxis(horizontalAxisName) : 0.0f;
        float verticalAxis          = alive ? Input.GetAxis(verticalAxisName) : 0.0f;
        var   accelerationMagnitude = Mathf.Sqrt(horizontalAxis * horizontalAxis + verticalAxis * verticalAxis);

        bool turbo = Input.GetAxis(turboButtonName) > 0.75f &&
                     turboCapacity > 0.0f &&
                     scrollingController.scrollingSpeed > 0.0f &&
                     isActive &&
                     IsAlive;

        if (turbo && !turboIsActive)
        {
            if (turboCapacity > minTurboCapacity)
            {
                scrollingController.numPlayersWithActiveTurbo++;
            }
            else
            {
                // Do not allow activating turbo if the capacity is too low.
                turbo = false;
            }
        }
        else if (!turbo && turboIsActive)
        {
            scrollingController.numPlayersWithActiveTurbo--;
        }
        turboIsActive = turbo;

        // Update turbo capacity.
        if (turboIsActive)
        {
            turboCapacity -= Time.fixedDeltaTime;
        }
        else if (isActive && IsAlive && scrollingController.scrollingSpeed > 0.0f)
        {
            turboCapacity += turboRechargeRatio * Time.fixedDeltaTime;
        }
        turboCapacity = Mathf.Max(turboCapacity, 0.0f);
        turboCapacity = Mathf.Min(turboCapacity, maxTurboCapacity);

        // Tilt the player according to the velocity in the previous frame.
        var angle = turboIsActive ? turboTilt :
                    Mathf.Max(minTilt, Mathf.Min(maxTilt, baseTilt - tiltScaling * horizontalAxis));

        rb.rotation = Mathf.LerpAngle(rb.rotation, angle, 0.1f);

        var playerVelocity = Vector2.zero;

        if (alive)
        {
            var velocityX = velocityScaling * horizontalAxis;
            var velocityY = velocityScaling * verticalAxis;
            if (turbo)
            {
                velocityY *= turboVelocityYScaling;
                // Move player towards the left side of the screen; in multiplayer, we do this
                // only when both players activated turbo.
                if (scrollingController.numPlayersWithActiveTurbo == NumPlayersAlive)
                {
                    velocityX -= turboSlowdown;
                }
            }
            if (isActive)
            {
                velocityX += scrollingController.scrollingSpeed;
            }

            playerVelocity = velocityModifier * new Vector2(velocityX, velocityY);
        }
        var targetVelocity = playerVelocity + scrollVelocity;

        rb.velocity = Vector2.Lerp(rb.velocity, targetVelocity, 0.3f);

        var position = rb.position;

        if (position.y < minY)
        {
            position.y = minY;
        }
        if (position.y > maxY)
        {
            position.y = maxY;
        }

        if (position.x > MaxX)
        {
            position.x = MaxX;
        }
        if (isActive && (alive || isLastPlayer) && position.x < MinX)
        {
            position.x = MinX;
        }
        rb.position = position;

        transform.position = new Vector3(position.x, position.y, transform.position.z);

        // At the beginning of the game, allow activating the second player before they
        // get out of the screen.
        if (position.x >= MinX)
        {
            if (accelerationMagnitude > 0.0f && !isActive)
            {
                isActive = true;
                missileCollider.enabled = true;
            }
        }

        // Update the pitch.
        var audio       = GetComponent <AudioSource>();
        var targetPitch = basePitch + accelerationMagnitude * pitchRatio;

        audio.pitch = Mathf.Lerp(audio.pitch, targetPitch, 0.1f);
    }