Implmenent PlayerUpgrade singleton
This commit is contained in:
parent
3bcdc54879
commit
e24371bf8b
6 changed files with 68 additions and 3 deletions
|
@ -11,6 +11,7 @@ GameObject:
|
||||||
- component: {fileID: 685382037628668327}
|
- component: {fileID: 685382037628668327}
|
||||||
- component: {fileID: 7037551310800415105}
|
- component: {fileID: 7037551310800415105}
|
||||||
- component: {fileID: 7958292204112110464}
|
- component: {fileID: 7958292204112110464}
|
||||||
|
- component: {fileID: 5334633105760309190}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: FlameUpgrade
|
m_Name: FlameUpgrade
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -106,3 +107,15 @@ BoxCollider2D:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Size: {x: 1, y: 1}
|
m_Size: {x: 1, y: 1}
|
||||||
m_EdgeRadius: 0
|
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:
|
||||||
|
|
|
@ -11,6 +11,7 @@ GameObject:
|
||||||
- component: {fileID: 5958400204756161002}
|
- component: {fileID: 5958400204756161002}
|
||||||
- component: {fileID: 7382262205660184478}
|
- component: {fileID: 7382262205660184478}
|
||||||
- component: {fileID: 2747432428292150867}
|
- component: {fileID: 2747432428292150867}
|
||||||
|
- component: {fileID: 6291791717356696744}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: SpeedUpgrade
|
m_Name: SpeedUpgrade
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -106,3 +107,15 @@ BoxCollider2D:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Size: {x: 1, y: 1}
|
m_Size: {x: 1, y: 1}
|
||||||
m_EdgeRadius: 0
|
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:
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace src.Player
|
||||||
private Transform _respawnPosition;
|
private Transform _respawnPosition;
|
||||||
private BombsSpawner _bombsSpawner;
|
private BombsSpawner _bombsSpawner;
|
||||||
private Animator _animator;
|
private Animator _animator;
|
||||||
|
private PlayerUpgrade _playerUpgrade;
|
||||||
private static readonly int AnimHorizontal = Animator.StringToHash("AnimHorizontal");
|
private static readonly int AnimHorizontal = Animator.StringToHash("AnimHorizontal");
|
||||||
private static readonly int AnimVertical = Animator.StringToHash("AnimVertical");
|
private static readonly int AnimVertical = Animator.StringToHash("AnimVertical");
|
||||||
|
|
||||||
|
@ -21,6 +22,12 @@ namespace src.Player
|
||||||
_respawnPosition = GameObject.Find("RespawnPosition").transform;
|
_respawnPosition = GameObject.Find("RespawnPosition").transform;
|
||||||
_bombsSpawner = GameObject.Find("BombSpawner").GetComponent<BombsSpawner>();
|
_bombsSpawner = GameObject.Find("BombSpawner").GetComponent<BombsSpawner>();
|
||||||
_animator = GetComponentInChildren<Animator>();
|
_animator = GetComponentInChildren<Animator>();
|
||||||
|
_playerUpgrade = PlayerUpgrade.Instance;
|
||||||
|
|
||||||
|
movementSpeed = _playerUpgrade.GetMovementSpeed();
|
||||||
|
_playerUpgrade.PlayerSpeed += IncreaseSpeed;
|
||||||
|
|
||||||
|
|
||||||
/* Always start at the starting point. */
|
/* Always start at the starting point. */
|
||||||
Respawn();
|
Respawn();
|
||||||
}
|
}
|
||||||
|
|
31
Assets/Scripts/src/Player/PlayerUpgrade.cs
Normal file
31
Assets/Scripts/src/Player/PlayerUpgrade.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
3
Assets/Scripts/src/Player/PlayerUpgrade.cs.meta
Normal file
3
Assets/Scripts/src/Player/PlayerUpgrade.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f43c74f0122b4324bb89907975813ddb
|
||||||
|
timeCreated: 1561488128
|
|
@ -1,5 +1,4 @@
|
||||||
using src.Player;
|
using src.Player;
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace src.Upgrade
|
namespace src.Upgrade
|
||||||
{
|
{
|
||||||
|
@ -7,8 +6,7 @@ namespace src.Upgrade
|
||||||
{
|
{
|
||||||
public override void PerformUpgrade()
|
public override void PerformUpgrade()
|
||||||
{
|
{
|
||||||
/* TODO: Refactor to use a player manager. */
|
var player = PlayerUpgrade.Instance;
|
||||||
var player = GameObject.Find("Player").GetComponent<PlayerController>();
|
|
||||||
player.IncreaseSpeed(.5f);
|
player.IncreaseSpeed(.5f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue