Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed UI buttons and some code smells #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Assets/Scripts/RedRunner/Characters/Character.cs
Original file line number Diff line number Diff line change
@@ -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; }
Expand Down
33 changes: 5 additions & 28 deletions Assets/Scripts/RedRunner/Characters/RedCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ void Update ()
}
}

//Updates all the Parameters for the RedCharacter
void LateUpdate ()
{
m_Animator.SetFloat ( "Speed", m_Speed.x );
Expand All @@ -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;
Expand All @@ -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 )
Expand All @@ -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;
Expand All @@ -446,6 +422,7 @@ public override void Move ( float horizontalAxis )
}
}


public override void Jump ()
{
if ( !IsDead.Value )
Expand Down
4 changes: 3 additions & 1 deletion Assets/Scripts/RedRunner/Enemies/Enemy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

Expand Down
30 changes: 6 additions & 24 deletions Assets/Scripts/RedRunner/Enemies/Mace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace RedRunner.Enemies
{

[CreateAssetMenu]
public class Mace : Enemy
{

Expand Down Expand Up @@ -48,32 +48,14 @@ void Reset ()

void OnCollisionEnter2D (Collision2D collision2D)
{
Vector2 position = collision2D.contacts [0].point;
Character character = collision2D.collider.GetComponent<Character> ();
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<CameraControl> ().Shake (3f, 30, 300f);
Camera.main.GetComponent<CameraControl> ().Shake (3f, 30, 300f);
}

public virtual void Slam (Vector3 position)
Expand All @@ -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);
}
Expand Down
5 changes: 0 additions & 5 deletions Assets/Scripts/RedRunner/Enemies/Saw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ void OnCollisionExit2D (Collision2D collision2D)
}
}

public override void Kill (Character target)
{
target.Die (true);
}

}

}
15 changes: 2 additions & 13 deletions Assets/Scripts/RedRunner/Enemies/Spike.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,13 @@ void OnCollisionStay2D (Collision2D collision2D)
{
Character character = collision2D.collider.GetComponent<Character> ();
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<Skeleton> ().Body;
AudioManager.Singleton.PlaySpikeSound (transform.position);
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/RedRunner/Enemies/Water.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParticleSystem> (target.WaterParticleSystem, spawnPosition, Quaternion.identity);
Expand Down
10 changes: 8 additions & 2 deletions Assets/Scripts/RedRunner/TerrainGeneration/BackgroundBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,6 +41,7 @@ public override float Width {
}
}

// Behavior set up for backgroun block in start state
protected virtual void Start ()
{

Expand Down
6 changes: 4 additions & 2 deletions Assets/Scripts/RedRunner/TerrainGeneration/BackgroundLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions Assets/Scripts/RedRunner/TerrainGeneration/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand All @@ -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;
Expand All @@ -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)
{

Expand Down
4 changes: 3 additions & 1 deletion Assets/Scripts/RedRunner/TerrainGeneration/DefaultBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand Down
Loading