Merge pull request #39 from dnutiu/player-upgrade

Implemenent PlayerUpgrade singleton
This commit is contained in:
Denis-Cosmin Nutiu 2019-06-29 13:45:37 +03:00 committed by GitHub
commit af87174622
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 3 deletions

View file

@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 685382037628668327}
- component: {fileID: 7037551310800415105}
- component: {fileID: 7958292204112110464}
- component: {fileID: 5334633105760309190}
m_Layer: 0
m_Name: FlameUpgrade
m_TagString: Untagged
@ -106,3 +107,15 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!114 &5334633105760309190
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7385886653159515755}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 94153367f2364ab38597c8f4a6521909, type: 3}
m_Name:
m_EditorClassIdentifier:

View file

@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 5958400204756161002}
- component: {fileID: 7382262205660184478}
- component: {fileID: 2747432428292150867}
- component: {fileID: 6291791717356696744}
m_Layer: 0
m_Name: SpeedUpgrade
m_TagString: Untagged
@ -106,3 +107,15 @@ BoxCollider2D:
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!114 &6291791717356696744
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4242909486338491383}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0b8c723aa8c7476789cbee67fcadfbef, type: 3}
m_Name:
m_EditorClassIdentifier:

View file

@ -11,6 +11,7 @@ namespace src.Player
private Transform _respawnPosition;
private BombsSpawner _bombsSpawner;
private Animator _animator;
private PlayerUpgrade _playerUpgrade;
private static readonly int AnimHorizontal = Animator.StringToHash("AnimHorizontal");
private static readonly int AnimVertical = Animator.StringToHash("AnimVertical");
@ -21,6 +22,12 @@ namespace src.Player
_respawnPosition = GameObject.Find("RespawnPosition").transform;
_bombsSpawner = GameObject.Find("BombSpawner").GetComponent<BombsSpawner>();
_animator = GetComponentInChildren<Animator>();
_playerUpgrade = PlayerUpgrade.Instance;
movementSpeed = _playerUpgrade.GetMovementSpeed();
_playerUpgrade.PlayerSpeed += IncreaseSpeed;
/* Always start at the starting point. */
Respawn();
}

View file

@ -0,0 +1,31 @@
namespace src.Player
{
public class PlayerUpgrade
{
public delegate void IncreaseSpeedDelegate(float speed);
public static PlayerUpgrade Instance = new PlayerUpgrade();
public event IncreaseSpeedDelegate PlayerSpeed;
public const float MaxPlayerSpeed = 8f;
private float _movementSpeed = 4f;
private PlayerUpgrade()
{
}
public float GetMovementSpeed()
{
return _movementSpeed;
}
public void IncreaseSpeed(float speed)
{
if (_movementSpeed >= MaxPlayerSpeed)
{
return;
}
_movementSpeed += speed;
PlayerSpeed.Invoke(speed);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f43c74f0122b4324bb89907975813ddb
timeCreated: 1561488128

View file

@ -1,5 +1,4 @@
using src.Player;
using UnityEngine;
namespace src.Upgrade
{
@ -7,8 +6,7 @@ namespace src.Upgrade
{
public override void PerformUpgrade()
{
/* TODO: Refactor to use a player manager. */
var player = GameObject.Find("Player").GetComponent<PlayerController>();
var player = PlayerUpgrade.Instance;
player.IncreaseSpeed(.5f);
}
}