<repo_name>Oscar16A/STC3<file_sep>/Assets/Scripts/Christian/Obstacle.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class Obstacle : MonoBehaviour
{
    // Obstacle movement
    public float xScroll;
    public bool dependent = true; // false = movement independent of xScroll

    // Obstacle health/damage
    public int health = -1, damage = 1;
    
    // Technical stuffs
    private Vector2 screenBounds;
    private float xSize; // Half the size of the obstacle for offscreen object destruction purposes


    // Initializes the obstacle's fields
    protected abstract void StartObstacle();

    // Updates the obstacle's movement
    protected abstract void MoveObstacle(bool dependent); 


    void Start()
    {
        // Set obstacle fields
        StartObstacle();

        // Get boundaries for off camera game object despawning
        screenBounds = new Vector2(-Camera.main.aspect * Camera.main.orthographicSize, Camera.main.orthographicSize);

        // Edge offset of object
        xSize = GetComponent<SpriteRenderer>().bounds.size.x / 2;
    }

    void FixedUpdate()
    {
        // Update obstacles movement (velocity/acceleration)
        MoveObstacle(dependent);

        // Object gets uninstantiated once off the camera (dependent of x axis position)
        if (xScroll > 0 && transform.position.x > -screenBounds.x + xSize)
        {
            Destroy(this.gameObject);
        }
        if (xScroll < 0 && transform.position.x < screenBounds.x - xSize)
        {
            Destroy(this.gameObject);
        }
    }
}
<file_sep>/Assets/Scripts/Jason/SceneManager.cs
﻿using UnityEngine;

public class SceneManager : MonoBehaviour
{

    void Start()
    {
        
    }

    private void ShowScene (string sceneName)
    {
        UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName);
    }

    public void ShowMainMenuScene()
    {
        // ShowScene("MainMenu");
    }

    public void ShowGameScene()
    {
        // ShowScene("MainMenu");
    }

    public void ShowCreditsScene()
    {
        // ShowScene("MainMenu");
    }

    public void ShowOptionsScene()
    {
        // ShowScene("MainMenu");
    }

}
<file_sep>/Assets/Scripts/Christian/PauseAccelObstacle.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PauseAccelObstacle : PauseObstacle
{
    // Default inital and final accelerations
    public float xAccelInit = 0f, yAccelInit = 0f;
    public float xAccelFinal = 0f, yAccelFinal = 0f;

    // Private modifiable velocities
    protected float xAccel, yAccel;

    // State tracking variable
    private bool completed = false;

    protected override void StartObstacle()
    {
        base.StartObstacle();

        // Adjust accelerations in direction of xScroll
        xAccelInit *= direction;
        xAccelFinal *= direction;

        // Set accelerations
        xAccel = xAccelInit;
        yAccel = yAccelInit;
    }

    protected override void MoveObstacle(bool dependent)
    {
        AdjustAccelerations();

        xVel += xAccel;
        yVel += yAccel;

        base.MoveObstacle(dependent);
    }


    // Adjusts the accelerations according to the time stamps
    protected void AdjustAccelerations()
    {
        if (!completed && timeElapsed < unpause && timeElapsed >= waitSeconds)
        {
            xAccel = 0;
            yAccel = 0;
        }
        else if (!completed && timeElapsed >= unpause)
        {
            xAccel = xAccelFinal;
            yAccel = yAccelFinal;
            completed = true;
        }
    }
}
<file_sep>/Assets/Scripts/Christian/StaticObstacle.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StaticObstacle : Obstacle
{
    // Default velocities
    private readonly float xVel = 0f, yVel = 0f;

    // Velocity vectors
    private Vector2 velocityRelative; // Does not include the xScroll
    private Vector2 velocityTrue; // Includes the xScroll


    protected override void StartObstacle()
    {
        velocityRelative = new Vector2(xVel, yVel);
        velocityTrue = new Vector2(xScroll + xVel, yVel);
    }

    protected override void MoveObstacle(bool dependent)
    {
        transform.Translate((dependent) ? velocityTrue : velocityRelative);
    }
}
<file_sep>/README.md
# STC3
VGDC  Quarter Project Fall 2019
<file_sep>/Assets/Scripts/Christian/SegmentSpawner.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;

public class SegmentSpawner : MonoBehaviour
{
    public float xScroll;

    // Variables regarding to the segment prefabs
    public Segment[] segments;
    private Vector2 screenBounds;

    private Segment currentSegment, nextSegment;
    private float prevSpawnPos;

    private int prevIndex1, prevIndex2;

    void Start()
    {
        screenBounds = new Vector2(-Camera.main.aspect * Camera.main.orthographicSize, Camera.main.orthographicSize);
        //Debug.Log("+x bound: " + screenBounds.x + " -x bound: " + -screenBounds.x);

        segments = LoadSegments();

        int index = Random.Range(0, segments.Length);
        prevIndex2 = prevIndex1;
        prevIndex1 = index;

        currentSegment = InstantiateSegment(segments[index]);
        if (xScroll < 0)
        {
            prevSpawnPos = currentSegment.GetXMin();
        }
        else if (xScroll > 0)
        {
            prevSpawnPos = currentSegment.GetXMax();
        }

    }

    void FixedUpdate()
    {
        if (xScroll < 0 && currentSegment.GetXMax() < prevSpawnPos)
        {
            int index = UniqueIndex(segments.Length, new int[] {prevIndex1, prevIndex2});

            currentSegment = InstantiateSegment(segments[index]);
            prevSpawnPos = currentSegment.GetXMin();
            Debug.Log(index + " " + prevIndex1 + " " + prevIndex2);

            prevIndex2 = prevIndex1;
            prevIndex1 = index;
        }
        else if (xScroll > 0 && currentSegment.GetXMin() > prevSpawnPos)
        {
            int index = UniqueIndex(segments.Length, new int[] { prevIndex1, prevIndex2 });

            currentSegment = InstantiateSegment(segments[index]);
            prevSpawnPos = currentSegment.GetXMax();

            prevIndex2 = prevIndex1;
            prevIndex1 = index;
        }
    }


    // Changes the scroll speed of all instantiated segments
    public void UpdateScroll(float x)
    {
        xScroll = x;
        foreach (Segment segment in segments)
        {
            segment.xScroll = xScroll;
        }
    }

    // Initializes segment values and instantiates it into the scene
    private Segment InstantiateSegment(Segment segment)
    {
        segment.xScroll = xScroll;
        float x = segment.transform.position.x;

        // If xScroll is negative, load segment prefab on left side of screen
        if (xScroll < 0)
        {
            x = -screenBounds.x + (segment.transform.position.x - segment.GetXMin());
        }

        // If xScroll is positive, load segment prefab on right side of screen
        if (xScroll > 0)
        {
            x = screenBounds.x - (segment.GetXMax() - segment.transform.position.x);
        }

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

        // Instantiates the segment prefab into the scene
        return Instantiate(segment).GetComponent<Segment>();
    }

    // Generates a random index that is not in the excluded indices
    private int UniqueIndex(int range, int[] exclude)
    {
        int index = -1;
        bool contains = false;
        do
        {
            index = Random.Range(0, range);

            // Check if the new index is inside the exluded indices
            contains = false;
            foreach (int num in exclude)
            {
                if (index == num)
                {
                    contains = true;
                    break;
                }
            }
        } while (contains);

        return index;
    }

    // Takes in a the directory path for the prefabs and returns an array of only segment game objects
    private Segment[] LoadSegments()
    {
        // Get all prefab file paths from the directory
        // string directoryPath = Application.dataPath + "/" + directory;
        // string[] filePaths = Directory.GetFileSystemEntries(directoryPath, "*.prefab");

        // Load all segments from the Resources folder
        GameObject[] prefabs = Resources.LoadAll<GameObject>("");
        List<Segment> segments = new List<Segment>();

        foreach (GameObject prefab in prefabs)
        {
            if (prefab.GetComponent<Segment>())
            {
                segments.Add(prefab.GetComponent<Segment>());
            }
        }

        // Return array version of the list
        return segments.ToArray();
    }
}
<file_sep>/Assets/Scripts/Lillian/testParallax.cs
﻿using System.Collections;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;

public class testParallax : MonoBehaviour
{
	// scrolling speed
	public Vector2 speed = new Vector2(2, 2);
	// direction 
	public Vector2 direction = new Vector2(-1, 0);
	public bool isLinkedToCamera = false;
	// check if bg is infinite
	public bool bgLoop = false;
	//public bool mgLoop = false; 

	private List<SpriteRenderer> backgroundPart;


    // Start is called before the first frame update
    void Start()
    {
    	if (bgLoop)
    	{
    		backgroundPart = new List<SpriteRenderer>();

    		for ( int i = 0; i < transform.childCount;i++)
    		{
    			Transform child = transform.GetChild(i);
    			SpriteRenderer r = child.GetComponent<SpriteRenderer>();

    			if ( r != null )
    			{
    				backgroundPart.Add(r);
    			}
    		}

    		// Sort
    		backgroundPart = backgroundPart.OrderBy(t => t.transform.position.x).ToList();


    	}
    }

    // Update is called once per frame
    void Update()
    {
    	// start moving the bg
    	Vector3 movement = new Vector3( speed.x * direction.x, speed.y * direction.y, 0);
    	movement *= Time.deltaTime;

    	transform.Translate(movement);

    	// now move cam
    	if ( isLinkedToCamera)
    	{
    		Camera.main.transform.Translate(movement);
    	}

    	if ( bgLoop)
    	{
    		SpriteRenderer firstChild = backgroundPart.FirstOrDefault();

    		if (firstChild != null )
    		{
    			if ( firstChild.transform.position.x < Camera.main.transform.position.x)
    			{
    				if (firstChild.IsVisibleFrom(Camera.main) == false)
    				{
    					SpriteRenderer lastChild = backgroundPart.LastOrDefault();

    					Vector3 lastPos = lastChild.transform.position;
    					Vector3 lastSize = (lastChild.bounds.max - lastChild.bounds.min);

    					firstChild.transform.position = new Vector3( lastPos.x + lastSize.x, 
    							firstChild.transform.position.y, firstChild.transform.position.z);

    					backgroundPart.Remove(firstChild);
    					backgroundPart.Add(firstChild);
    				}
    			}
    		}
    	}
    }
}<file_sep>/Assets/Scripts/Christian/Segment.cs
﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Segment : MonoBehaviour
{
    public int difficulty = 1; // Segment difficulty tag: 1 = easiest ... infinite = hardest
    public float xScroll;


    void Start()
    {
        foreach(Obstacle obstacle in GetComponentsInChildren<Obstacle>())
        {
            obstacle.xScroll = xScroll;
        }
    }

    void FixedUpdate()
    {
        // If the segment has no more children components, destory the segment
        if (GetComponentsInChildren<Obstacle>().Length == 0)
        {
            Destroy(this.gameObject);
        }
    }


    // Returns the x position of the leftmost edge relative to the x position of the segment
    public float GetXMin()
    {
        Obstacle[] obstacles = GetComponentsInChildren<Obstacle>();

        // Return a zero early if there is less than one obstacles in the segment
        if (obstacles.Length < 1)
        {
            return 0;
        }

        float minXPos = obstacles[0].transform.position.x;
        float minXScale = obstacles[0].GetComponent<SpriteRenderer>().bounds.size.x / 2;

        // Compare each child obstacle of the segment game object to determine min and max
        for (int i = 0; i < obstacles.Length; i++)
        {
            float currentXPos = obstacles[i].transform.position.x;
            float currentXScale = obstacles[i].GetComponent<SpriteRenderer>().bounds.size.x / 2;

            // Compare for minimum x position
            if (currentXPos - currentXScale < minXPos - minXScale)
            {
                minXPos = currentXPos;
                minXScale = currentXScale;
            }

        }

        return minXPos - minXScale;
    }

    // Returns the x position of the rightmost edge relative to the x position of the segment
    public float GetXMax()
    {
        Obstacle[] obstacles = GetComponentsInChildren<Obstacle>();

        // Return a zero early if there is less than one obstacles in the segment
        if (obstacles.Length < 1)
        {
            return 0;
        }

        float maxXPos = obstacles[0].transform.position.x;
        float maxXScale = obstacles[0].GetComponent<SpriteRenderer>().bounds.size.x / 2;

        // Compare each child obstacle of the segment game object to determine min and max
        for (int i = 1; i < obstacles.Length; i++)
        {
            float currentXPos = obstacles[i].transform.position.x;
            float currentXScale = obstacles[i].GetComponent<SpriteRenderer>().bounds.size.x / 2;

            // Compare for maximum x position
            if (currentXPos + currentXScale > maxXPos + maxXScale)
            {
                maxXPos = currentXPos;
                maxXScale = currentXScale;
            }
        }

        return maxXPos + maxXScale;
    }

    // Returns the width of the segment from the lowest x-axis edge to the highest x-axis edge
    public float GetXSize()
    {
        return GetXMax() - GetXMin();
    }
}
<file_sep>/Assets/Scripts/Oscar/testmenu.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class testmenu : MonoBehaviour
{
    public void loadGame()
    {
        UnityEngine.SceneManagement.SceneManager.LoadScene("Test Gameplay");
    }

    public void quit()
    {
        Debug.Log("Quit Game");
        Application.Quit();
    }
}
<file_sep>/Assets/Scripts/Oscar/backtomenu.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class backtomenu : MonoBehaviour
{
    void Update()
    {
        if(Input.GetButtonDown("Cancel"))
        {
            UnityEngine.SceneManagement.SceneManager.LoadScene("Test Main Menu");
        }
    }
}<file_sep>/Assets/Scripts/Christian/DynamicObstacle.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DynamicObstacle : Obstacle
{
    // Default velocities and accelerations
    public float xVel = 0f, yVel = 0f;
    public float xAccel = 0f, yAccel = 0f;

    // xScroll direction adjustment variable
    private int direction;

    // Velocity vectors
    private Vector2 velocityRelative; // Does not include the xScroll
    private Vector2 velocityTrue; // Includes the xScroll


    protected override void StartObstacle()
    {
        direction = (xScroll < 0) ? -1 : 1;

        // Adjust velocity and acceleration into the direction of xScroll
        xVel *= direction;
        xAccel *= direction;
    }

    protected override void MoveObstacle(bool dependent)
    {
        xVel += xAccel;
        yVel += yAccel;

        if (dependent)
        {
            transform.Translate(xVel + xScroll, yVel, 0);
        }
        else
        {
            transform.Translate(xVel, yVel, 0);
        }
        
    }
}
<file_sep>/Assets/Scripts/Christian/PauseObstacle.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PauseObstacle : Obstacle
{
    // Default inital and final velocities
    public float xVelInit = 0f, yVelInit = 0f;
    public float xVelFinal = 0f, yVelFinal = 0f;

    // Wait and pause times in seconds
    public float waitSeconds; // The time before it pauses
    public float pauseSeconds; // The time duration of the pause

    // Time stamp to unpause
    protected float unpause;

    // Private modifiable velocities
    protected float xVel, yVel;

    // xScroll direction adjustment variable
    protected int direction;

    // Local elapsed time tracking variable
    protected float timeElapsed = 0f;
    private bool completed = false;

    protected override void StartObstacle()
    {
        direction = (xScroll < 0) ? -1 : 1;

        // Adjust velocities into the direction of xScroll
        xVelInit *= direction;
        xVelFinal *= direction;

        // Unpause time stamp
        unpause = waitSeconds + pauseSeconds;

        // Set velocities
        xVel = xVelInit;
        yVel = yVelInit;
    }

    protected override void MoveObstacle(bool dependent)
    {
        // Set relative velocities according to the time stamps
        AdjustVelocities();

        // Move the obstacle according to its xScroll dependency
        if (dependent)
        {
            transform.Translate(xVel + xScroll, yVel, transform.position.z);
        }
        else
        {
            transform.Translate(xVel, yVel, transform.position.z);
        }

        timeElapsed += Time.deltaTime;
    }
    

    // Adjusts the velocities according to the time stamps
    protected void AdjustVelocities()
    {
        if (!completed && timeElapsed < unpause && timeElapsed >= waitSeconds)
        {
            xVel = 0;
            yVel = 0;
        }
        else if (!completed && timeElapsed >= unpause)
        {
            xVel = xVelFinal;
            yVel = yVelFinal;
            completed = true;
        }
    }
}
<file_sep>/Assets/Scripts/Christian/SineWaveObstacle.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SineWaveObstacle : Obstacle
{
    // Sine wave arguments (in Unity units)
    public float amplitude = 1;
    public float period = 4;
    public float offset = 0;

    // xScroll direction adjustment variable
    protected int direction;

    // Movement/location related variables
    private float conversionRatio;
    private float xInitPos, yInitPos;
    private float xPos, yPos;

    // Velocity vectors
    private Vector2 velocityRelative; // Does not include the xScroll
    private Vector2 velocityTrue; // Includes the xScroll


    protected override void StartObstacle()
    {
        direction = (xScroll < 0) ? -1 : 1;
        amplitude *= direction;
        offset *= direction;

        xInitPos = transform.position.x;
        yInitPos = transform.position.y;

        xPos = xInitPos;
        yPos = yInitPos;

        conversionRatio = (2 * Mathf.PI) / period;

        offset *= conversionRatio;
    }

    protected override void MoveObstacle(bool dependent)
    {
        xPos += xScroll;
        yPos = amplitude * Mathf.Sin(xPos * conversionRatio + offset) + yInitPos;

        transform.position = new Vector3(xPos, yPos, transform.position.z);
    }
}
<file_sep>/Assets/Scripts/Lillian/HighscoreScript.cs
﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HighscoreScript : MonoBehaviour
{
    // Start is called before the first frame update

	public Text score; 

	public void testingFunct()
	{
		int number = Random.Range(1, 7);
		score.text = number.ToString();
		//Debug.Log(score);
	} 


}
