Couple PlayerUpgrade with Player

This commit is contained in:
Denis-Cosmin Nutiu 2019-08-25 22:38:20 +03:00
parent 52a7a536c8
commit 712965e5ad
6 changed files with 16 additions and 19 deletions

View file

@ -65,7 +65,7 @@ namespace src.Base
Collider2D.enabled = false;
_isDead = true;
Animator.SetTrigger(AnimExplode);
Destroy(gameObject, 1);
Destroy(gameObject, 0.7f);
}
public void OnCollisionEnter2D(Collision2D col)

View file

@ -1,5 +1,7 @@
using src.Interfaces;
using src.Managers;
using src.Player;
using src.Upgrade;
using UnityEngine;
namespace src.Base
@ -8,6 +10,7 @@ namespace src.Base
{
protected GameManager gameManager;
private UpgradeManager _upgradeManager;
protected PlayerController _playerToUpgrade;
public void Start()
{
@ -23,6 +26,7 @@ namespace src.Base
public void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag("Player")) return;
_playerToUpgrade = other.GetComponent<PlayerController>();
PerformUpgrade();
_upgradeManager.ClaimUpgrade(gameObject);
Destroy(gameObject);

View file

@ -37,7 +37,6 @@ namespace src.Managers
_gameStateManager = gameObject.AddComponent<GameStateManager>();
_levelManager = gameObject.AddComponent<LevelManager>();
_upgradeManager = gameObject.AddComponent<UpgradeManager>();
gameObject.AddComponent<PlayerUpgrade>();
// Load external components
_playerController = GameObject.Find("Player").GetComponent<PlayerController>();

View file

@ -29,14 +29,18 @@ namespace src.Player
private static readonly int AnimHorizontal = Animator.StringToHash("AnimHorizontal");
private static readonly int AnimVertical = Animator.StringToHash("AnimVertical");
private static readonly int AnimDeath = Animator.StringToHash("AnimDeath");
protected void Awake()
{
_playerUpgrade = gameObject.AddComponent<PlayerUpgrade>();
}
protected void Start()
{
_gameStateManager = GameStateManager.instance;
_playerUpgrade = PlayerUpgrade.instance;
_bombsUtil = BombsUtilManager.instance;
_rigidbody2d = GetComponent<Rigidbody2D>();
_collider2D = GetComponent<Collider2D>();
_animator = GetComponentInChildren<Animator>();

View file

@ -4,24 +4,14 @@ namespace src.Player
{
public class PlayerUpgrade : GameplayComponent
{
/* Events & Delegates */
public delegate void IncreaseSpeedDelegate(float speed);
public static PlayerUpgrade instance;
public event IncreaseSpeedDelegate PlayerSpeed;
/* Variables */
public const float MaxPlayerSpeed = 8f;
private float _movementSpeed = 4f;
public void Awake()
{
if (instance == null)
{
instance = this;
}
else if (instance != null)
{
Destroy(gameObject);
}
}
public float GetMovementSpeed()
{
return _movementSpeed;

View file

@ -7,7 +7,7 @@ namespace src.Upgrade
{
public override void PerformUpgrade()
{
var player = PlayerUpgrade.instance;
var player = _playerToUpgrade.GetComponent<PlayerUpgrade>();
player.IncreaseSpeed(.5f);
}
}