Life system implementation

I was able to add a life system into the game today. It works by making the player go invisible on enemy collision to imply invincibility frames until the life count has  decremented to the point that the player gets a game over.

Key lines of code:

public int playerLives = 3;

void Start ()
    {
	Debug.Log("Lives:"+playerLives);
        rend = GetComponent();
        rend.enabled = true;
    }

void OnTriggerEnter(Collider col)
	{
		if (col.gameObject.tag == "Enemy" && GodMode == false)
		{   
            if (playerLives <= 1)             {                 Destroy(gameObject);                 PlayerDie.PlayerAlive = false;                 Debug.Log("Death via enemy");             }             if (playerLives >= 2)
            {
                // Health = Health - 100f;
                playerLives--;
                Debug.Log("Player lost a life");
                Debug.Log("Lives:"+playerLives);
                StartCoroutine(blinkTime());
            }

 IEnumerator blinkTime()
    {
        rend.enabled = false;
        yield return new WaitForSeconds(1f);
        rend.enabled = true;
    }

Lives system

I did some research on ways to implement the lives into the HUD and found these examples:

Starfox

Starfox (SNES)

Starfox uses a “Lives x (number of lives)” format which I thought would be quite useful for our game, but decided against it as it implies that the player respawns on the spot which we wanted to avoid. We wanted something that properly showed that the player was getting damaged.

Super street fighter 2

Super Street Fighter 2 – Ryu Portrait

We looked at games that gave feedback of procedural damage to the player and decided that this was a good direction to go in, so I plan to use a similar format for our game. I’ll design a mugshot sprite of the main character with alternative damaged versions.

KHCoM

Kingdom Hearts: Chain of Memories Health HUD

Leave a comment