Permalink
Browse files

Three different enemy types behave differently.

The three different enemy types behave differently. Player now darkens
the screen after taking damage.  (Which is a bug, it's supposed to turn
red.)
  • Loading branch information...
Retl committed Apr 6, 2014
1 parent a4bf395 commit d0e30f7f4c73650521ce68d8bc41d0090a2741bc
Binary file not shown.
@@ -1,15 +1,98 @@
using UnityEngine;
// Class Name: EnemyBoogerBehavior.cs
// Class Purpose: Represents the enemy behaviors that are unique to a Booger.
// It expects the gameObject this MonoBehavior is attached to to also have an EnemyGenericBehavior attached to function, otherwise it will do very little.
// The main distinct thing about this one is that it can stretch parts of itself towards the player.

using UnityEngine;
using System.Collections;

public class EnemyBoogerBehavior : MonoBehaviour {

// Use this for initialization
void Start () {

const float DAMAGE = 5f;
const float attackRange = 5f;
const float attackRate = 1.0f;

protected EnemyGenericBehavior genericEnemy;

// Use this for initialization
void Start()
{
genericEnemy = GetComponent<EnemyGenericBehavior>();
}

// Update is called once per frame
void Update () {
void FixedUpdate()
{
if (genericEnemy != null)
{
//Do stuff unique to Slabs.
}
}

void OnTriggerEnter(Collider other)
{
if (GameController.Testing)
{
print("Trigger Entered by: " + other.ToString());
}
}

void OnTriggerStay(Collider other)
{
if (genericEnemy != null)
{

if (GameController.Testing)
{
print("Trigger Stay by: " + other.ToString());
}
PlayerController playerController = other.transform.parent.GetComponent<PlayerController>();
if (playerController != null && genericEnemy.attackCooldownTime <= 0)
{
genericEnemy.SmoothLookAt(playerController.transform.position);
if (genericEnemy.IsFacingPlayer(attackRange))
{
playerController.TakeDamage(DAMAGE);
genericEnemy.attackCooldownTime = attackRate; //Wait one second before able to attack again.
}
}
}
}

void OnTriggerExit(Collider other)
{
if (GameController.Testing)
{
print("Trigger Left by: " + other.ToString());
}
}

#region Utility Methods

//I should move this into its own utility script class. - Moore
protected GameObject FindClosestGameObjectWithTag(string tagToFind)
{
GameObject result = null;
GameObject[] allObjects = GameObject.FindGameObjectsWithTag(tagToFind);

foreach (GameObject current in allObjects)
{
if (current != this.gameObject)
{
if (result == null)
{
result = current;
} else
{
if (Vector3.Distance(transform.position, result.transform.position) > Vector3.Distance(transform.position, current.transform.position))
{
result = current;
}
}
}
}
return result;
}

#endregion Utility Methods
}
@@ -1,4 +1,9 @@
using UnityEngine;
// Class Name: EnemyGenericBehavior.cs
// Class Purpose: Represents the enemy behaviors that are common between all enemies in The Seas Have Eyes.
// While not very threatening on its own, it could still be potentially useful for creating special-case enemies that only use
// a few of the behaviors associated with an enemy, like having an attack cooldown or checking if it's facing the player.

using UnityEngine;
using System.Collections;

public class EnemyGenericBehavior : MonoBehaviour
@@ -1,10 +1,15 @@
using UnityEngine;
// Class Name: EnemySlabBehavior.cs
// Class Purpose: Represents the enemy behaviors that are unique to a Slab.
// It expects the gameObject this MonoBehavior is attached to to also have an EnemyGenericBehavior attached to function, otherwise it will do very little.

using UnityEngine;
using System.Collections;

public class EnemySlabBehavior : MonoBehaviour {

const float DAMAGE = 1f;
const float attackRange = 10f;
const float attackRate = 1.0f;

protected EnemyGenericBehavior genericEnemy;

@@ -47,7 +52,7 @@ void OnTriggerStay(Collider other)
if (genericEnemy.IsFacingPlayer(attackRange))
{
playerController.TakeDamage(DAMAGE);
genericEnemy.attackCooldownTime = 1.0f; //Wait one second before able to attack again.
genericEnemy.attackCooldownTime = attackRate; //Wait one second before able to attack again.
}
}
}
@@ -1,15 +1,99 @@
using UnityEngine;
// Class Name: EnemyStalkBehavior.cs
// Class Purpose: Represents the enemy behaviors that are unique to a Stalk.
// It expects the gameObject this MonoBehavior is attached to to also have an EnemyGenericBehavior attached to function, otherwise it will do very little.
// The main distinct thing about this one is that it has a much larger player detection range.

using UnityEngine;
using System.Collections;

public class EnemyStalkBehavior : MonoBehaviour {

// Use this for initialization
void Start () {

const float DAMAGE = 7f;
const float attackRange = 20f;
const float attackRate = 2.0f;

protected EnemyGenericBehavior genericEnemy;

// Use this for initialization
void Start()
{
genericEnemy = GetComponent<EnemyGenericBehavior>();
}

// Update is called once per frame
void Update () {
void FixedUpdate()
{
if (genericEnemy != null)
{
//Do stuff unique to Slabs.
}
}

void OnTriggerEnter(Collider other)
{
if (GameController.Testing)
{
print("Trigger Entered by: " + other.ToString());
}
}

void OnTriggerStay(Collider other)
{
if (genericEnemy != null)
{

if (GameController.Testing)
{
print("Trigger Stay by: " + other.ToString());
}
PlayerController playerController = other.transform.parent.GetComponent<PlayerController>();
if (playerController != null && genericEnemy.attackCooldownTime <= 0)
{
genericEnemy.SmoothLookAt(playerController.transform.position);
if (genericEnemy.IsFacingPlayer(attackRange))
{
playerController.TakeDamage(DAMAGE);
genericEnemy.attackCooldownTime = attackRate; //Wait one second before able to attack again.
}
}
}
}

void OnTriggerExit(Collider other)
{
if (GameController.Testing)
{
print("Trigger Left by: " + other.ToString());
}
}

#region Utility Methods

//I should move this into its own utility script class. - Moore
protected GameObject FindClosestGameObjectWithTag(string tagToFind)
{
GameObject result = null;
GameObject[] allObjects = GameObject.FindGameObjectsWithTag(tagToFind);

foreach (GameObject current in allObjects)
{
if (current != this.gameObject)
{
if (result == null)
{
result = current;
} else
{
if (Vector3.Distance(transform.position, result.transform.position) > Vector3.Distance(transform.position, current.transform.position))
{
result = current;
}
}
}
}
return result;
}

#endregion Utility Methods
}
@@ -52,6 +52,8 @@ public class PlayerController : MonoBehaviour
public float strokeCooldown; //This is used to track if the player's able to give another 'stroke' in the direction they're facing. - Moore
public float timeBetweenStrokes; //Ideally, this would be a const, but is public to allow tweaking in the inspector. This is the cooldown is set to each stroke. - Moore

public float hurtEffectCountdown = 0f; //When the player takes damage, this is set to some value between 0 and 1 inclusive. 0 means 'don't show damage overlay'. 1 means 'do show it'.


//Options and Configuration type thigies.
public ControlStyle controlStyle = ControlStyle.Normal;
@@ -69,16 +71,27 @@ public class PlayerController : MonoBehaviour
// Use this for initialization
void Start()
{
health = healthMax;
stamina = staminaMax;
air = airMax;
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Player");
if (allObjects.Length > 1)
{
print("WARNING: Attempted to add multiple players to game. Destroying a player...");
Destroy(gameObject);
}

else
{
// Singleton pattern: We only want one player. If the level starts with more than one, get rid of them.
health = healthMax;
stamina = staminaMax;
air = airMax;

//And setting up event listener thingies here.
PickupBubble.CollidedWithPlayer += AddAir;
PickupBubble.CollidedWithPlayer += AddScore;
//And setting up event listener thingies here.
PickupBubble.CollidedWithPlayer += AddAir;
PickupBubble.CollidedWithPlayer += AddScore;

timeBetweenStrokes = 1.0f;
strokeDelayScalar = timeBetweenStrokes * 15;
timeBetweenStrokes = 1.0f;
strokeDelayScalar = timeBetweenStrokes * 15;
}

}

@@ -135,6 +148,7 @@ void FixedUpdate()

void OnGUI()
{
hurtEffectCountdown = DrawRedOverlay(hurtEffectCountdown);
DrawHUD();
//gameObject.GetComponent<3DText>(); //Deleteme?

@@ -177,6 +191,35 @@ void DrawMeter(Vector2 leftTop, Vector2 widthHeight, float varCurrent, float var
GUI.color = Color.white;
}

float DrawRedOverlay(float alpha)
{
if (alpha > 1)
{
alpha = 1;
}

float result = alpha;

if (alpha > 0)
{


Color redShade = new Color(1, 0, 0, alpha);

// This bit, I had to look up, because I couldn't just set GUI.colors directly. It was more than a little annoying. - Moore.
Texture2D myTexture = new Texture2D(1,1);
myTexture.SetPixel(1,1,redShade);
myTexture.wrapMode = TextureWrapMode.Repeat;
myTexture.Apply();
//End of looked-up section.

GUI.Box(new Rect(0, 0, Screen.width, Screen.height), myTexture);
result -= Time.deltaTime;
}

return result;
}

void HandlePlayerInput()
{

@@ -207,9 +250,7 @@ void HandlePlayerInput()
{
rigidbody.AddForce((transform.up * movespeed * (movementScalar + movementBoostScalar) * strokeDelayScalar));
}
}

else if (CanStroke())
} else if (CanStroke())
{
bool didStroke = false;
gamepadTriggerOffset = Input.GetAxis("Trigger");
@@ -225,8 +266,7 @@ void HandlePlayerInput()
if (controlStyle == ControlStyle.Advanced)
{
rigidbody.AddForce(new Vector3(-rigidbody.velocity.x, 0, -rigidbody.velocity.z)); //Cancel out existing forces except for Gravity and whatnot.
}
else if (controlStyle == ControlStyle.Normal)
} else if (controlStyle == ControlStyle.Normal)
{
rigidbody.AddForce(-rigidbody.velocity); //Cancel out all forces.
}
@@ -253,7 +293,10 @@ void HandlePlayerInput()
if (didStroke)
{
ResetStrokeCooldown();
if (movementBoostScalar != 0) {strokeCooldown /= 2;} //Boost means twice as many strokes per unit time and twice the speed.
if (movementBoostScalar != 0)
{
strokeCooldown /= 2;
} //Boost means twice as many strokes per unit time and twice the speed.
}

IsLookingAt();
@@ -287,6 +330,8 @@ public void TakeDamage(float amount)
health = 0;
GameOver();
}

hurtEffectCountdown = 1f;
}

public void AddAir(float amount)
@@ -359,7 +404,7 @@ public bool IsLookingAt(float distance)
{
result = true;
}
if (GameController.Testing)
if (GameController.Testing)
{
//If we want the player to display testing data, here might be a spot.
}

0 comments on commit d0e30f7

Please sign in to comment.