Skip to content

Commit

Permalink
Push
Browse files Browse the repository at this point in the history
Health Bar Done..
To do tmrw:
Pause Menu (Controls)
Score
Animations
Story..
  • Loading branch information
aps16104 committed Apr 21, 2020
1 parent f94ef1e commit 842592e
Show file tree
Hide file tree
Showing 9 changed files with 936 additions and 116,815 deletions.
25 changes: 25 additions & 0 deletions Platformer/Assets/Scripts/HealthBar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HealthBar : MonoBehaviour
{
public Slider slider;
public Gradient gradient;
public Image fill;

public void SetMaxHealth( int health)
{
slider.maxValue = health;
slider.value = health;

fill.color = gradient.Evaluate(1f);
}

public void SetHealth(int health)
{
slider.value = health;
fill.color =gradient.Evaluate(slider.normalizedValue);
}
}
11 changes: 11 additions & 0 deletions Platformer/Assets/Scripts/HealthBar.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 22 additions & 21 deletions Platformer/Assets/Scripts/Level 1/Player_Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ public class Player_Controller : MonoBehaviour
public float speed = 7.5f; //speed
public Rigidbody2D rb; //Rigidbody

public int health = 100; //health
private int maxhealth = 100; //max health
public int currentHealth; //health
private int maxHealth = 100; //max health

public HealthBar healthbar; //Healthbar

public int cash; //Cash

int jumps; //Amount of jumps available
Expand All @@ -26,6 +29,8 @@ void Start()
{
rb = GetComponent<Rigidbody2D>(); //Get rigidbody component from player
door.SetActive(false); // Turn off the door
currentHealth = maxHealth;
healthbar.SetMaxHealth(maxHealth);
}

void Update()
Expand All @@ -37,7 +42,6 @@ void Update()

if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)) //Player wants to Jump
{
rb.velocity = new Vector2(rb.velocity.x, 0);
Jump(); //Go to Jump
}

Expand Down Expand Up @@ -69,8 +73,16 @@ void Jump()
}
}


void TakeDamage(int damage) //Take Damage Function
{
currentHealth -= damage; //take damage
healthbar.SetHealth(currentHealth); //modify health bar
}

void OnCollisionEnter2D(Collision2D collide) //Floor Collision


void OnCollisionEnter2D(Collision2D collide) // Collisions
{
if (collide.gameObject.tag == "Box") //if you land on box then you have your jumps back
{
Expand All @@ -80,35 +92,23 @@ void OnCollisionEnter2D(Collision2D collide) //Floor Collision

if (collide.gameObject.tag == "Bouncer") //if you land on box then you have your jumps back
{
if (FacingRight == true)
if (FacingRight == true) //Rebound
{
rb.velocity = (new Vector2(-1.5f, 1f));
}

if (FacingRight == false)
if (FacingRight == false) //Rebound
{
rb.velocity = (new Vector2(1.5f, 1f));
}
}

if (collide.gameObject.CompareTag("Enemy"))
{
health = health - 25; // Full Health

if (FacingRight == true)
{
rb.velocity = (new Vector2(-4f, 2f));
}

if (FacingRight == false)
{
rb.velocity = (new Vector2(4f, 2f));
}

TakeDamage(15); //Go to take damage function and pass in the integer 20

if ( health < 1)
if ( currentHealth < 1) //Death
{
Destroy(gameObject);
Time.timeScale = 0;
}
}
Expand All @@ -133,7 +133,8 @@ void OnTriggerEnter2D(Collider2D other) //Pickups
if (other.gameObject.CompareTag("Heart"))
{
other.gameObject.SetActive(false); // heart dissapears
health = maxhealth; // Full Health
currentHealth = maxHealth; // Full Health
healthbar.SetHealth(currentHealth); //Full HealthBar
}


Expand Down
File renamed without changes.
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
110 changes: 110 additions & 0 deletions Platformer/Assets/World Build/enemy_health_bar_foreground_005.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 842592e

Please sign in to comment.