Esempio n. 1
0
    /// <summary>
    /// Transfers the starting segment into the active segments list, which kickstarts the segment movement process
    /// </summary>
    public void EnablePlatforms()
    {
        startingSegment.transform.position = startingSegmentPos;
        startingSegment.GenerateCoins();
        startingSegment.GenerateObstacles();
        startingSegment.gameObject.SetActive(true);

        TransferSegmentToActive(startingSegment);
    }
Esempio n. 2
0
    /// <summary>
    /// Updates gameplay logic any time a new frame is displayed to the screen
    /// </summary>
    void Update()
    {
        if (activeSegments.Count > 0)
        {
            foreach (PlatformSegment segment in activeSegments)
            {
                // If the segment has just been deactivated, don't bother processing it
                if (!segment.isActiveAndEnabled)
                {
                    break;
                }

                // Move the segment towards the left side of screen to give the illusion of the player running over it
                segment.transform.position = Vector3.Lerp(segment.transform.position, segment.transform.position - (Vector3.right * movementSpeed), Time.smoothDeltaTime);
            }

            // If the end of a segment has gone off the left side of screen
            if (activeSegments[0].segmentEnd.position.x < -screenRightBound.x)
            {
                // Deactivate the segment and transfer it into the pile of available segments
                PlatformSegment removedSegment = activeSegments[0];
                removedSegment.gameObject.SetActive(false);
                TransferSegmentToAvailable(removedSegment);
            }

            // If the end of the segment is just about to travel past the right side of the screen and a new segment can be spawned
            if ((activeSegments[activeSegments.Count - 1].segmentStart.position.x < screenRightBound.x))
            {
                if (availableSegments.Count > 0)
                {
                    // Pick an available segment at random and place it immediately behind the segment above
                    int             newSegmentIndex = Random.Range(0, availableSegments.Count);
                    PlatformSegment newSegment      = availableSegments[newSegmentIndex];
                    newSegment.transform.position = new Vector3(activeSegments[activeSegments.Count - 1].segmentEnd.position.x + gapBetweenPlatforms, newSegment.transform.position.y, 0.0f);

                    // Enable a random assortment of coins and obstacles on the segment
                    newSegment.GenerateCoins();
                    newSegment.GenerateObstacles();

                    // Activate the segment
                    newSegment.gameObject.SetActive(true);

                    // Transfer the segment into the list of active segments
                    TransferSegmentToActive(newSegment);
                }
            }
        }
    }