Permalink
Browse files

Screen Turns Red On Damage + Game Over

  • Loading branch information...
Retl committed Apr 6, 2014
1 parent d0e30f7 commit 36eb7cf35b92eb62dd18731eacb404d680a91758
@@ -73,7 +73,7 @@ public bool IsFacingPlayer()

public void SmoothLookAt(Vector3 target)
{
Quaternion rotation = Quaternion.LookRotation((new Vector3(target.x, transform.position.y, target.z) - transform.position));
Quaternion rotation = Quaternion.LookRotation((new Vector3(target.x, target.y, target.z) - transform.position));
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * GameController.DAMPING);
}

@@ -94,15 +94,23 @@ void Start()
}

}

void Update()
{
hurtEffectCountdown = UpdateCountdownMinMax(hurtEffectCountdown, 0f, 1f);

strokeCooldown -= Time.deltaTime;
air -= airLossRate * Time.deltaTime;
}

// FixedUpdate is called once per frame
// FixedUpdate is called reguarlly and is mainly used to deal with physics. For smoother, quicker changes, use Update.
void FixedUpdate()
{
strokeCooldown -= Time.fixedDeltaTime;


HandlePlayerInput();

air -= airLossRate * Time.fixedDeltaTime;

if (air < 0)
{
//If the player is out of air, then they rapidly lose health? Or instant game-over? - Moore
@@ -148,7 +156,7 @@ void FixedUpdate()

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

@@ -191,33 +199,28 @@ void DrawMeter(Vector2 leftTop, Vector2 widthHeight, float varCurrent, float var
GUI.color = Color.white;
}

float DrawRedOverlay(float alpha)
void 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);
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;
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), myTexture);
}

return result;
}

void HandlePlayerInput()
@@ -315,7 +318,8 @@ void GameOver()
{
//STUB
print("Oh noes, you Game Overed! Have some free HP.");
AddHealth(9999f);
Time.timeScale = 0f;
//AddHealth(9999f);

}

@@ -419,5 +423,29 @@ public bool IsLookingAt()
return IsLookingAt(Mathf.Infinity);
}

//Usage: For accurate results, only call this once per Update per countdownVariable. - Moore
float UpdateCountdownMinMax(float countdown, float min, float max)
{
float result = countdown;

//Clamp to upper bounds.
if (countdown > max)
{
countdown = max;
}

//Clamp to lower bounds.
if (countdown < min)
{
countdown = min;
}
//Decrement when not under bounds.
else if (countdown > min)
{
result -= Time.deltaTime;
}
return result;
}

#endregion Utility Methods.
}

0 comments on commit 36eb7cf

Please sign in to comment.