diff --git a/Assets/Scripts/RedRunner/Characters/Character.cs b/Assets/Scripts/RedRunner/Characters/Character.cs index 1ab7cd3a..10ac899a 100644 --- a/Assets/Scripts/RedRunner/Characters/Character.cs +++ b/Assets/Scripts/RedRunner/Characters/Character.cs @@ -1,37 +1,50 @@ -using System.Collections; +//Global Libraries +using System.Collections; using System.Collections.Generic; using UnityEngine; +//Local Libraries using RedRunner.Utilities; namespace RedRunner.Characters { - + //Required Components [RequireComponent ( typeof ( Rigidbody2D ) )] [RequireComponent ( typeof ( Collider2D ) )] [RequireComponent ( typeof ( Animator ) )] [RequireComponent ( typeof ( Skeleton ) )] + + //This Class consist of public getter functions that allow other scripts in RedRunner to access information about otherwise private RedCharacter variables. public abstract class Character : MonoBehaviour { - + //Function for handling a death event public delegate void DeadHandler (); + //What to do upon death public virtual event DeadHandler OnDead; + //Returns Character Max Run Speed public abstract float MaxRunSpeed { get; } + //Returns Character settling time public abstract float RunSmoothTime { get; } + //Returns current speed public abstract float RunSpeed { get; } + //Returns walking speed public abstract float WalkSpeed { get; } + //Returns the strength constant associated with jumping public abstract float JumpStrength { get; } + //Returns vector speed of Character public abstract Vector2 Speed { get; } + //Returns current actions in string array public abstract string[] Actions { get; } + //Retuns single string with current action public abstract string CurrentAction { get; } public abstract int CurrentActionIndex { get; } diff --git a/Assets/Scripts/RedRunner/Characters/RedCharacter.cs b/Assets/Scripts/RedRunner/Characters/RedCharacter.cs index 8858a1f7..72f72a0f 100644 --- a/Assets/Scripts/RedRunner/Characters/RedCharacter.cs +++ b/Assets/Scripts/RedRunner/Characters/RedCharacter.cs @@ -342,6 +342,7 @@ void Update () } } + //Updates all the Parameters for the RedCharacter void LateUpdate () { m_Animator.SetFloat ( "Speed", m_Speed.x ); @@ -357,34 +358,11 @@ void LateUpdate () } } - // void OnCollisionEnter2D ( Collision2D collision2D ) - // { - // bool isGround = collision2D.collider.CompareTag ( GroundCheck.GROUND_TAG ); - // if ( isGround && !m_IsDead ) - // { - // bool isBottom = false; - // for ( int i = 0; i < collision2D.contacts.Length; i++ ) - // { - // if ( !isBottom ) - // { - // isBottom = collision2D.contacts [ i ].normal.y == 1; - // } - // else - // { - // break; - // } - // } - // if ( isBottom ) - // { - // m_JumpParticleSystem.Play (); - // } - // } - // } - #endregion #region Private Methods + //Manipulates the Skeloton used in unity to close the eyes of the RedCharacter IEnumerator CloseEye () { m_ClosingEye = true; @@ -411,6 +389,7 @@ IEnumerator CloseEye () #region Public Methods + //Makes footstep swounds if RedCharacter is contacting the ground public virtual void PlayFootstepSound () { if ( m_GroundCheck.IsGrounded ) @@ -419,15 +398,12 @@ public virtual void PlayFootstepSound () } } + //Calculates and sets the velocity and position of the players movement public override void Move ( float horizontalAxis ) { if ( !IsDead.Value ) { float speed = m_CurrentRunSpeed; -// if ( CrossPlatformInputManager.GetButton ( "Walk" ) ) -// { -// speed = m_WalkSpeed; - // } Vector2 velocity = m_Rigidbody2D.velocity; velocity.x = speed * horizontalAxis; m_Rigidbody2D.velocity = velocity; @@ -446,6 +422,7 @@ public override void Move ( float horizontalAxis ) } } + public override void Jump () { if ( !IsDead.Value ) diff --git a/Assets/Scripts/RedRunner/Enemies/Enemy.cs b/Assets/Scripts/RedRunner/Enemies/Enemy.cs index 1afa0eaa..1562a80d 100644 --- a/Assets/Scripts/RedRunner/Enemies/Enemy.cs +++ b/Assets/Scripts/RedRunner/Enemies/Enemy.cs @@ -12,7 +12,9 @@ public abstract class Enemy : MonoBehaviour public abstract Collider2D Collider2D { get; } - public abstract void Kill ( Character target ); + public virtual void Kill ( Character target ){ + target.Die(true); + } } diff --git a/Assets/Scripts/RedRunner/Enemies/Mace.cs b/Assets/Scripts/RedRunner/Enemies/Mace.cs index 26849482..824fe9ea 100644 --- a/Assets/Scripts/RedRunner/Enemies/Mace.cs +++ b/Assets/Scripts/RedRunner/Enemies/Mace.cs @@ -7,7 +7,7 @@ namespace RedRunner.Enemies { - + [CreateAssetMenu] public class Mace : Enemy { @@ -48,32 +48,14 @@ void Reset () void OnCollisionEnter2D (Collision2D collision2D) { - Vector2 position = collision2D.contacts [0].point; Character character = collision2D.collider.GetComponent (); - bool pressable = false; - for (int i = 0; i < collision2D.contacts.Length; i++) { - if (!pressable) { - pressable = (collision2D.contacts [i].normal.y >= 0.8f && collision2D.contacts [i].normal.y <= 1f && m_PathFollower.Velocity.y > m_MaulSpeed) || - (collision2D.contacts [i].normal.y <= -0.8f && collision2D.contacts [i].normal.y >= -1f && m_PathFollower.Velocity.y < m_MaulSpeed) || - (collision2D.contacts [i].normal.x >= 0.8f && collision2D.contacts [i].normal.x <= 1f && m_PathFollower.Velocity.x < m_MaulSpeed) || - (collision2D.contacts [i].normal.x <= -0.8f && collision2D.contacts [i].normal.x >= -1f && m_PathFollower.Velocity.x > m_MaulSpeed); - } else { - break; - } - } - if (pressable && character == null && !collision2D.collider.CompareTag ("Player")) { - Slam (position); - } if (character != null && !character.IsDead.Value) { - if (pressable) { - Slam (position); - Vector3 scale = character.transform.localScale; - scale.y = m_MaulScale; - character.transform.localScale = scale; - } + Vector3 scale = character.transform.localScale; + scale.y = m_MaulScale; + character.transform.localScale = scale; Kill (character); } -// Camera.main.GetComponent ().Shake (3f, 30, 300f); + Camera.main.GetComponent ().Shake (3f, 30, 300f); } public virtual void Slam (Vector3 position) @@ -86,7 +68,7 @@ public virtual void Slam (Vector3 position) public override void Kill (Character target) { m_PathFollower.Stopped = true; - target.Die (true); + base.Kill(target); m_Animator.SetTrigger ("Smile"); AudioManager.Singleton.PlaySpikeSound (transform.position); } diff --git a/Assets/Scripts/RedRunner/Enemies/Saw.cs b/Assets/Scripts/RedRunner/Enemies/Saw.cs index 3ad13439..11a17511 100644 --- a/Assets/Scripts/RedRunner/Enemies/Saw.cs +++ b/Assets/Scripts/RedRunner/Enemies/Saw.cs @@ -78,11 +78,6 @@ void OnCollisionExit2D (Collision2D collision2D) } } - public override void Kill (Character target) - { - target.Die (true); - } - } } \ No newline at end of file diff --git a/Assets/Scripts/RedRunner/Enemies/Spike.cs b/Assets/Scripts/RedRunner/Enemies/Spike.cs index 8268d691..6921d590 100644 --- a/Assets/Scripts/RedRunner/Enemies/Spike.cs +++ b/Assets/Scripts/RedRunner/Enemies/Spike.cs @@ -25,24 +25,13 @@ void OnCollisionStay2D (Collision2D collision2D) { Character character = collision2D.collider.GetComponent (); if (character && !character.IsDead.Value) { - bool isTop = false; - ContactPoint2D mainPoint; - for (int i = 0; i < collision2D.contacts.Length; i++) { - if (!isTop) { - isTop = collision2D.contacts [i].normal.y < -0.7f && collision2D.contacts [i].normal.y >= -1f; - } else { - break; - } - } - if (isTop) { - Kill (character); - } + Kill(character); } } public override void Kill (Character target) { - target.Die (true); + base.Kill(target); m_FixedJoint2D.connectedBody = target.GetComponent ().Body; AudioManager.Singleton.PlaySpikeSound (transform.position); } diff --git a/Assets/Scripts/RedRunner/Enemies/Water.cs b/Assets/Scripts/RedRunner/Enemies/Water.cs index 48afa282..b935c563 100644 --- a/Assets/Scripts/RedRunner/Enemies/Water.cs +++ b/Assets/Scripts/RedRunner/Enemies/Water.cs @@ -29,7 +29,7 @@ void OnTriggerEnter2D (Collider2D other) public override void Kill (Character target) { - target.Die (); + base.Kill(target); Vector3 spawnPosition = target.transform.position; spawnPosition.y += -1f; ParticleSystem particle = Instantiate (target.WaterParticleSystem, spawnPosition, Quaternion.identity); diff --git a/Assets/Scripts/RedRunner/TerrainGeneration/BackgroundBlock.cs b/Assets/Scripts/RedRunner/TerrainGeneration/BackgroundBlock.cs index 962eaa91..e2f3891c 100644 --- a/Assets/Scripts/RedRunner/TerrainGeneration/BackgroundBlock.cs +++ b/Assets/Scripts/RedRunner/TerrainGeneration/BackgroundBlock.cs @@ -4,29 +4,34 @@ using RedRunner.Utilities; +// Details specific to the Background Block objects +// Assigned to prefabs in: Assets -> Prefabs -> Background Blocks namespace RedRunner.TerrainGeneration { - + // Extents Block.cs public class BackgroundBlock : Block { - + // Establish width min and max [SerializeField] protected float m_MinWidth = 1f; [SerializeField] protected float m_MaxWidth = 10f; + // gets defined minimum width public virtual float MinWidth { get { return m_MinWidth; } } + // gets defined maximum width public virtual float MaxWidth { get { return m_MaxWidth; } } + // setter and getter to override blocks width settings public override float Width { get { return base.Width; @@ -36,6 +41,7 @@ public override float Width { } } + // Behavior set up for backgroun block in start state protected virtual void Start () { diff --git a/Assets/Scripts/RedRunner/TerrainGeneration/BackgroundLayer.cs b/Assets/Scripts/RedRunner/TerrainGeneration/BackgroundLayer.cs index f2268871..9be3ae1c 100644 --- a/Assets/Scripts/RedRunner/TerrainGeneration/BackgroundLayer.cs +++ b/Assets/Scripts/RedRunner/TerrainGeneration/BackgroundLayer.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using UnityEngine; +// Class that is called by TerrainGenerator.cs which handles the background layer namespace RedRunner.TerrainGeneration { @@ -10,11 +11,12 @@ public struct BackgroundLayer { public string name; - public BackgroundBlock[] Blocks; - public BackgroundBlock LastBlock; + public BackgroundBlock[] Blocks; // Creates a Background Block array object to hold all of the level blocks + public BackgroundBlock LastBlock; // Creates a Background Block object to define the last block public float CurrentX; public float PreviousX; + // Sets the background block to default position on reset public void Reset () { CurrentX = 0f; diff --git a/Assets/Scripts/RedRunner/TerrainGeneration/Block.cs b/Assets/Scripts/RedRunner/TerrainGeneration/Block.cs index c5e303b5..c3e63a46 100644 --- a/Assets/Scripts/RedRunner/TerrainGeneration/Block.cs +++ b/Assets/Scripts/RedRunner/TerrainGeneration/Block.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using UnityEngine; +// Details specific to the Block objects +// Assigned to prefabs in: Assets -> Prefabs -> Blocks namespace RedRunner.TerrainGeneration { @@ -13,6 +15,7 @@ public abstract class Block : MonoBehaviour [SerializeField] protected float m_Probability = 1f; + // Setter and getter for the blocks width public virtual float Width { get { return m_Width; @@ -22,22 +25,26 @@ public virtual float Width { } } + // Getter for blocks probability public virtual float Probability { get { return m_Probability; } } + // Behavior setup for the moment a block is removed. public virtual void OnRemove (TerrainGenerator generator) { } + // Behavior setup for time prior to the blocks removal. public virtual void PreGenerate (TerrainGenerator generator) { } + // Behavior setup to time after the blocks removal. public virtual void PostGenerate (TerrainGenerator generator) { diff --git a/Assets/Scripts/RedRunner/TerrainGeneration/DefaultBlock.cs b/Assets/Scripts/RedRunner/TerrainGeneration/DefaultBlock.cs index 5b2ea0fa..85f60ac7 100644 --- a/Assets/Scripts/RedRunner/TerrainGeneration/DefaultBlock.cs +++ b/Assets/Scripts/RedRunner/TerrainGeneration/DefaultBlock.cs @@ -2,9 +2,11 @@ using System.Collections.Generic; using UnityEngine; +// Script assigned to each block prefabs in the to identify a new block node. +// Assigned to blocks (labeled Middle) in: Assets -> Scenes -> Creation namespace RedRunner.TerrainGeneration { - + // Extends block class defined in Block.cs public class DefaultBlock : Block { diff --git a/Assets/Scripts/RedRunner/TerrainGeneration/DefaultTerrainGenerator.cs b/Assets/Scripts/RedRunner/TerrainGeneration/DefaultTerrainGenerator.cs index 5ac97b3a..dbbdc40e 100644 --- a/Assets/Scripts/RedRunner/TerrainGeneration/DefaultTerrainGenerator.cs +++ b/Assets/Scripts/RedRunner/TerrainGeneration/DefaultTerrainGenerator.cs @@ -4,9 +4,11 @@ using RedRunner.Characters; +// Called by Terrain Generator in "Play" scene +// Play -> Managers -> Terrain Generator namespace RedRunner.TerrainGeneration { - + // Extends TerrainGenerator class defined in TerrainGenerator.cs public class DefaultTerrainGenerator : TerrainGenerator { diff --git a/Assets/Scripts/RedRunner/TerrainGeneration/TerrainGenerationSettings.cs b/Assets/Scripts/RedRunner/TerrainGeneration/TerrainGenerationSettings.cs index 2a70774c..31402ccc 100644 --- a/Assets/Scripts/RedRunner/TerrainGeneration/TerrainGenerationSettings.cs +++ b/Assets/Scripts/RedRunner/TerrainGeneration/TerrainGenerationSettings.cs @@ -2,9 +2,10 @@ using System.Collections.Generic; using UnityEngine; +// Settings used for the terain generator namespace RedRunner.TerrainGeneration { - + // Establishes terrain generation settings class established [CreateAssetMenu (menuName = "Create Terrain Generator Settings")] public class TerrainGenerationSettings : ScriptableObject { @@ -18,56 +19,64 @@ public class TerrainGenerationSettings : ScriptableObject [SerializeField] protected int m_EndBlocksCount = 1; [SerializeField] - protected Block[] m_StartBlocks; - [SerializeField] - protected Block[] m_MiddleBlocks; - [SerializeField] - protected Block[] m_EndBlocks; + protected Block[] m_StartBlocks; // Start Block Block.cs array variabl + [SerializeField] + protected Block[] m_MiddleBlocks; // Middle Block Block.cs array variabl + [SerializeField] + protected Block[] m_EndBlocks; // End Block Block.cs array variable [SerializeField] - protected BackgroundLayer[] m_BackgroundLayers; + protected BackgroundLayer[] m_BackgroundLayers; // Background Layer BackgroundLayer.cs array variable + // Getter setting for Level Length public float LevelLength { get { return m_LevelLength; } } + // Getter setting for Start Block Count public int StartBlocksCount { get { return m_StartBlocksCount; } } + // Getter setting for Middle Block Count public int MiddleBlocksCount { get { return m_MiddleBlocksCount; } } + // Getter for End Block Count public int EndBlocksCount { get { return m_EndBlocksCount; } } + // Get Start Blocks array element public Block[] StartBlocks { get { return m_StartBlocks; } } + // Get Middle Blocks array element public Block[] MiddleBlocks { get { return m_MiddleBlocks; } } + // Get End Blocks array element public Block[] EndBlocks { get { return m_EndBlocks; } } + // Get Background Layer array element public BackgroundLayer[] BackgroundLayers { get { return m_BackgroundLayers; diff --git a/Assets/Scripts/RedRunner/TerrainGeneration/TerrainGenerator.cs b/Assets/Scripts/RedRunner/TerrainGeneration/TerrainGenerator.cs index a8ba6ae2..3057f02a 100644 --- a/Assets/Scripts/RedRunner/TerrainGeneration/TerrainGenerator.cs +++ b/Assets/Scripts/RedRunner/TerrainGeneration/TerrainGenerator.cs @@ -4,14 +4,15 @@ using RedRunner.Characters; +// Base class of the terrain generator. This contains all logic concerning how a +// level is created, how it is randomized, and what happens to it in different states. namespace RedRunner.TerrainGeneration { public abstract class TerrainGenerator : MonoBehaviour { - + // Setup and getter for terrain generator singleton private static TerrainGenerator m_Singleton; - public static TerrainGenerator Singleton { get @@ -22,12 +23,12 @@ public static TerrainGenerator Singleton protected Dictionary m_Blocks; protected Dictionary m_BackgroundBlocks; - protected BackgroundLayer[] m_BackgroundLayers; + protected BackgroundLayer[] m_BackgroundLayers; // Creates a Background Layer array object from BackgroundLayer.cs protected float m_PreviousX; protected float m_CurrentX; protected float m_FathestBackgroundX; [SerializeField] - protected TerrainGenerationSettings m_Settings; + protected TerrainGenerationSettings m_Settings; // Create a Terrain Generation Settings object from TerainGenerationSettings.cs protected int m_GeneratedStartBlocksCount; protected int m_GeneratedMiddleBlocksCount; protected int m_GeneratedEndBlocksCount; @@ -38,12 +39,13 @@ public static TerrainGenerator Singleton [SerializeField] protected float m_BackgroundGenerateRange = 200f; [SerializeField] - protected Character m_Character; - protected Block m_LastBlock; - protected BackgroundBlock m_LastBackgroundBlock; + protected Character m_Character; // Creates a character object that can be placed in the environment [Assets -> Scripts -> RedRunner -> Characters -> Character.cs] + protected Block m_LastBlock; // Creates a Block object to find the last block + protected BackgroundBlock m_LastBackgroundBlock; // Creates a background Block object to define the last background block protected float m_RemoveTime = 0f; protected bool m_Reset = false; + // Getter for previous X coordinate public float PreviousX { get @@ -52,6 +54,7 @@ public float PreviousX } } + // Getter for current X coordinate public float CurrentX { get @@ -60,6 +63,7 @@ public float CurrentX } } + // Terrain Generator settings getter ~> TerainGenerationSettings.cs public TerrainGenerationSettings Settings { get @@ -68,6 +72,7 @@ public TerrainGenerationSettings Settings } } + // Awake the Terrain & establishes background. protected virtual void Awake () { if ( m_Singleton != null ) @@ -86,6 +91,7 @@ protected virtual void Awake () GameManager.OnReset += Reset; } + // Reset the Terrain to default positions and values protected virtual void Reset () { m_Reset = true; @@ -106,11 +112,13 @@ protected virtual void Reset () m_Reset = false; } + // When the Terrain layer is closed protected virtual void OnDestroy () { m_Singleton = null; } + // Update terrain if reset isnt called and there is still time. Call method ~> Generate() protected virtual void Update () { if ( m_Reset ) @@ -125,14 +133,18 @@ protected virtual void Update () Generate (); } + // Generate the terrains based on specific parameters. public virtual void Generate () { + // If your character has not reached the end of the level yet if ( m_CurrentX < m_Settings.LevelLength || m_Settings.LevelLength <= 0 ) { bool isEnd = false, isStart = false, isMiddle = false; Block block = null; Vector3 current = new Vector3 ( m_CurrentX, 0f, 0f ); float newX = 0f; + + // Determins what block you are currently for game status if ( m_GeneratedStartBlocksCount < m_Settings.StartBlocksCount || m_Settings.StartBlocksCount <= 0 ) { isStart = true; @@ -148,6 +160,8 @@ public virtual void Generate () isEnd = true; block = ChooseFrom ( m_Settings.EndBlocks ); } + + // If you havent reached the last block yet, determin next block. Else, not. if ( m_LastBlock != null ) { newX = m_CurrentX + m_LastBlock.Width; @@ -156,9 +170,12 @@ public virtual void Generate () { newX = 0f; } + + // If there are still blocks ahead of player character (not reached the end), run this if ( block != null && ( m_LastBlock == null || newX < m_Character.transform.position.x + m_GenerateRange ) ) { - if ( isStart ) + // Itterate specific block count. + if ( isStart ) { if ( m_Settings.StartBlocksCount > 0 ) { @@ -179,9 +196,12 @@ public virtual void Generate () m_GeneratedEndBlocksCount++; } } - CreateBlock ( block, current ); + // Call function ~> CreateBlock(Block, Vector3) + CreateBlock( block, current ); } } + + // Update background layer and randomly generate elements based on location for ( int i = 0; i < m_BackgroundLayers.Length; i++ ) { int random = Random.Range ( 0, 2 ); @@ -193,6 +213,7 @@ public virtual void Generate () Vector3 current = new Vector3 ( m_BackgroundLayers [ i ].CurrentX, 0f, 0f ); BackgroundBlock block = ( BackgroundBlock )ChooseFrom ( m_BackgroundLayers [ i ].Blocks ); float newX = 0f; + // While the background layer is not the last block, else, background block. if ( m_BackgroundLayers [ i ].LastBlock != null ) { newX = m_BackgroundLayers [ i ].CurrentX + m_BackgroundLayers [ i ].LastBlock.Width; @@ -201,6 +222,7 @@ public virtual void Generate () { newX = 0f; } + // While there are still blocks and is not the last block or the end of the level hasnt been reached if ( block != null && ( m_BackgroundLayers [ i ].LastBlock == null || newX < m_Character.transform.position.x + m_BackgroundGenerateRange ) ) { CreateBackgroundBlock ( block, current, m_BackgroundLayers [ i ], i ); @@ -208,6 +230,7 @@ public virtual void Generate () } } + // Remove block from scene to help performance. public virtual void Remove () { List blocksToRemove = new List (); @@ -236,6 +259,7 @@ public virtual void Remove () } } + // Remove all blocks from the scene public virtual void RemoveAll () { List blocksToRemove = new List (); @@ -258,11 +282,13 @@ public virtual void RemoveAll () } } + // Remove a specific block at indicated vector. Calls method ~> RemoveBlock(Block) public virtual void RemoveBlockAt ( Vector3 position ) { RemoveBlock ( m_Blocks [ position ] ); } + // Remove specific block. Calls method ~> Destroy() public virtual void RemoveBlock ( Block block ) { block.OnRemove ( this ); @@ -270,6 +296,7 @@ public virtual void RemoveBlock ( Block block ) m_Blocks.Remove ( block.transform.position ); } + // Removes block from the background. Calls method ~> Destroy() public virtual void RemoveBackgroundBlock ( BackgroundBlock block ) { block.OnRemove ( this ); @@ -277,39 +304,41 @@ public virtual void RemoveBackgroundBlock ( BackgroundBlock block ) m_BackgroundBlocks.Remove ( block.transform.position ); } + // Creates a new block in the scene. public virtual bool CreateBlock ( Block blockPrefab, Vector3 position ) { if ( blockPrefab == null ) { return false; } - blockPrefab.PreGenerate ( this ); + blockPrefab.PreGenerate ( this ); // from Block.cs Block block = Instantiate ( blockPrefab, position, Quaternion.identity ); m_PreviousX = m_CurrentX; m_CurrentX += block.Width; m_Blocks.Add ( position, block ); - blockPrefab.PostGenerate ( this ); + blockPrefab.PostGenerate ( this ); // from Block.cs m_LastBlock = block; return true; } + // Creates a new background block. public virtual bool CreateBackgroundBlock ( BackgroundBlock blockPrefab, Vector3 position, BackgroundLayer layer, int layerIndex ) { if ( blockPrefab == null ) { return false; } - blockPrefab.PreGenerate ( this ); + blockPrefab.PreGenerate ( this ); // from Block.cs position.z = blockPrefab.transform.position.z; position.y = blockPrefab.transform.position.y; BackgroundBlock block = Instantiate ( blockPrefab, position, Quaternion.identity ); - float width = Random.Range ( block.MinWidth, block.MaxWidth ); + float width = Random.Range ( block.MinWidth, block.MaxWidth ); // from BackgroundBlock.cs m_BackgroundLayers [ layerIndex ].PreviousX = m_BackgroundLayers [ layerIndex ].CurrentX; m_BackgroundLayers [ layerIndex ].CurrentX += width; block.Width = width; m_BackgroundLayers [ layerIndex ].LastBlock = block; m_BackgroundBlocks.Add ( position, block ); - blockPrefab.PostGenerate ( this ); + blockPrefab.PostGenerate ( this ); // from Block.cs if ( m_BackgroundLayers [ layerIndex ].CurrentX > m_FathestBackgroundX ) { m_FathestBackgroundX = m_BackgroundLayers [ layerIndex ].CurrentX; @@ -317,6 +346,7 @@ public virtual bool CreateBackgroundBlock ( BackgroundBlock blockPrefab, Vector3 return true; } + // Get character and places them in the scene. public Block GetCharacterBlock () { Block characterBlock = null; @@ -331,6 +361,7 @@ public Block GetCharacterBlock () return characterBlock; } + // Randomly selects block from array of possible blocks to choose from. Each block can only be used once. public static Block ChooseFrom ( Block[] blocks ) { if ( blocks.Length <= 0 ) diff --git a/Assets/Scripts/RedRunner/UI/UIScreen/EndScreen.cs b/Assets/Scripts/RedRunner/UI/UIScreen/EndScreen.cs index 32b37f18..22f788ef 100644 --- a/Assets/Scripts/RedRunner/UI/UIScreen/EndScreen.cs +++ b/Assets/Scripts/RedRunner/UI/UIScreen/EndScreen.cs @@ -1,34 +1,39 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; - -namespace RedRunner.UI -{ - public class EndScreen : UIScreen - { - [SerializeField] - protected Button ResetButton = null; - [SerializeField] - protected Button HomeButton = null; - [SerializeField] - protected Button ExitButton = null; - - private void Start() - { - ResetButton.SetButtonAction(() => - { - GameManager.Singleton.Reset(); - var ingameScreen = UIManager.Singleton.GetUIScreen(UIScreenInfo.IN_GAME_SCREEN); - UIManager.Singleton.OpenScreen(ingameScreen); - GameManager.Singleton.StartGame(); - }); - } - - public override void UpdateScreenStatus(bool open) - { - base.UpdateScreenStatus(open); - } - } - +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace RedRunner.UI +{ + public class EndScreen : UIScreen + { + [SerializeField] + protected Button ResetButton = null; + [SerializeField] + protected Button HomeButton = null; + [SerializeField] + protected Button ExitButton = null; + + private void Start() + { + ResetButton.SetButtonAction(() => + { + GameManager.Singleton.Reset(); + var ingameScreen = UIManager.Singleton.GetUIScreen(UIScreenInfo.IN_GAME_SCREEN); + UIManager.Singleton.OpenScreen(ingameScreen); + GameManager.Singleton.StartGame(); + }); + + HomeButton.SetButtonAction(() => + { + GameManager.Singleton.Init(); + }); + } + + public override void UpdateScreenStatus(bool open) + { + base.UpdateScreenStatus(open); + } + } + } \ No newline at end of file diff --git a/Assets/Scripts/RedRunner/UI/UIScreen/StartScreen.cs b/Assets/Scripts/RedRunner/UI/UIScreen/StartScreen.cs index 3eae3016..59617f9c 100644 --- a/Assets/Scripts/RedRunner/UI/UIScreen/StartScreen.cs +++ b/Assets/Scripts/RedRunner/UI/UIScreen/StartScreen.cs @@ -1,42 +1,43 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; - -namespace RedRunner.UI -{ - public class StartScreen : UIScreen - { - [SerializeField] - protected Button PlayButton = null; - [SerializeField] - protected Button HelpButton = null; - [SerializeField] - protected Button InfoButton = null; - [SerializeField] - protected Button ExitButton = null; - - private void Start() - { - PlayButton.SetButtonAction(() => - { - var uiManager = UIManager.Singleton; - var InGameScreen = uiManager.UISCREENS.Find(el => el.ScreenInfo == UIScreenInfo.IN_GAME_SCREEN); - if (InGameScreen != null) - { - uiManager.OpenScreen(InGameScreen); - GameManager.Singleton.StartGame(); - } - }); - - ExitButton.SetButtonAction(() => - { - GameManager.Singleton.ExitGame(); - }); - } - public override void UpdateScreenStatus(bool open) - { - base.UpdateScreenStatus(open); - } - } +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +namespace RedRunner.UI +{ + public class StartScreen : UIScreen + { + [SerializeField] + protected Button PlayButton = null; + [SerializeField] + protected Button HelpButton = null; + [SerializeField] + protected Button InfoButton = null; + [SerializeField] + protected Button ExitButton = null; + + private void Start() + { + PlayButton.SetButtonAction(() => + { + var uiManager = UIManager.Singleton; + var InGameScreen = uiManager.UISCREENS.Find(el => el.ScreenInfo == UIScreenInfo.IN_GAME_SCREEN); + if (InGameScreen != null) + { + GameManager.Singleton.Reset(); + uiManager.OpenScreen(InGameScreen); + GameManager.Singleton.StartGame(); + } + }); + + ExitButton.SetButtonAction(() => + { + GameManager.Singleton.ExitGame(); + }); + } + public override void UpdateScreenStatus(bool open) + { + base.UpdateScreenStatus(open); + } + } } \ No newline at end of file