add all mechanics
This commit is contained in:
parent
87383d5b8c
commit
0e2a7cc7c3
434 changed files with 238349 additions and 2092 deletions
|
|
@ -1,18 +1,27 @@
|
|||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Player : Entity
|
||||
{
|
||||
[Header("Invulnerability")]
|
||||
[SerializeField] private float invulnerabilityLength;
|
||||
private float currentInvulnerabilityTime;
|
||||
[SerializeField] private float invincibilityBlinkLength;
|
||||
private float currentInvincibilityBlink;
|
||||
[SerializeField] private SpriteRenderer[] playerSprites;
|
||||
[SerializeField] private Color invincibilityColor;
|
||||
[Header("UI")]
|
||||
[SerializeField] private TextMeshProUGUI livesText;
|
||||
[SerializeField] private Image[] healthBar;
|
||||
[SerializeField] private Sprite heart;
|
||||
[SerializeField] private Sprite depletedHeart;
|
||||
|
||||
[Header("SFX")]
|
||||
[SerializeField] private AudioClip hurtSound;
|
||||
[SerializeField] private float hurtVolume = 1f;
|
||||
[SerializeField] private AudioClip gameOverSound;
|
||||
[SerializeField] private float gameOverVolume = 1f;
|
||||
private void Update()
|
||||
{
|
||||
if (!isStalled)
|
||||
|
|
@ -30,8 +39,24 @@ public class Player : Entity
|
|||
if (currentInvulnerabilityTime > 0)
|
||||
{
|
||||
currentInvulnerabilityTime -= Time.deltaTime;
|
||||
if (currentInvincibilityBlink > 0)
|
||||
{
|
||||
currentInvincibilityBlink -= Time.deltaTime;
|
||||
foreach (SpriteRenderer sprite in playerSprites)
|
||||
{
|
||||
sprite.color = Color.Lerp(invincibilityColor, Color.white, 1f - currentInvincibilityBlink);
|
||||
}
|
||||
}
|
||||
else if (currentInvincibilityBlink <= 0)
|
||||
{
|
||||
currentInvincibilityBlink = invincibilityBlinkLength;
|
||||
}
|
||||
if (currentInvulnerabilityTime <= 0)
|
||||
{
|
||||
foreach (SpriteRenderer sprite in playerSprites)
|
||||
{
|
||||
sprite.color = Color.white;
|
||||
}
|
||||
invulnerable = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -53,9 +78,20 @@ public class Player : Entity
|
|||
protected override void OnDeath()
|
||||
{
|
||||
GameManager.instance.LoseGame();
|
||||
WaveManager.instance.audioSource.PlayOneShot(gameOverSound, gameOverVolume);
|
||||
}
|
||||
private void UpdateLivesUI()
|
||||
{
|
||||
livesText.text = $"Lives: {health}/{maxHealth}";
|
||||
for (int i = 0; i < healthBar.Length; i++)
|
||||
{
|
||||
if (i < health)
|
||||
{
|
||||
healthBar[i].sprite = heart;
|
||||
}
|
||||
else
|
||||
{
|
||||
healthBar[i].sprite = depletedHeart;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue