Upgrade System
This commit is contained in:
@@ -3,17 +3,25 @@ using UnityEngine;
|
||||
|
||||
[
|
||||
RequireComponent(typeof(PlayerManager)),
|
||||
RequireComponent(typeof(SpriteRenderer))
|
||||
RequireComponent(typeof(SpriteRenderer)),
|
||||
RequireComponent(typeof(CircleCollider2D))
|
||||
]
|
||||
public class PlayerCollisions : MonoBehaviour
|
||||
{
|
||||
private PlayerManager _pm;
|
||||
private PlayerManager _manager;
|
||||
private SpriteRenderer _sr;
|
||||
private CircleCollider2D _trigger;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_pm = GetComponent<PlayerManager>();
|
||||
_manager = GetComponent<PlayerManager>();
|
||||
_sr = GetComponent<SpriteRenderer>();
|
||||
_trigger = GetComponent<CircleCollider2D>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_trigger.radius = _manager.OrbAbsorberRadius;
|
||||
}
|
||||
|
||||
private void OnTriggerStay2D(Collider2D collision)
|
||||
@@ -39,7 +47,7 @@ public class PlayerCollisions : MonoBehaviour
|
||||
|
||||
if (orb.transform.position == transform.position)
|
||||
{
|
||||
_pm.AddExperience((int)orb.GetComponent<OrbStats>().OrbValue);
|
||||
_manager.AddExperience((int)orb.GetComponent<OrbStats>().OrbValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,28 +3,44 @@ using UnityEngine;
|
||||
public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
// Character stats
|
||||
public int Health = 100;
|
||||
public int MaxHealth = 100;
|
||||
public int HealValue = 1;
|
||||
[Header("Character Stats")]
|
||||
public float Health = 100f;
|
||||
public float MaxHealth = 100f;
|
||||
public float HealValue = 1f;
|
||||
public float Speed = 2f;
|
||||
public int Exp = 0;
|
||||
public int Level = 1;
|
||||
public float Exp = 0f;
|
||||
public float Level = 1f;
|
||||
public float OrbAbsorberRadius = 0.7f;
|
||||
|
||||
// Weapons stats
|
||||
public int BeamDamages = 50;
|
||||
public int SwordsDamages = 25;
|
||||
public int ArrowDamages = 15;
|
||||
[Header("Weapons Stats")]
|
||||
public float BeamDamages = 50f;
|
||||
public float BeamFrequency = 5f;
|
||||
public float BeamLife = 0.5f;
|
||||
|
||||
public float SwordsHaloRadius = 1f;
|
||||
public float SwordsDamages = 25f;
|
||||
public float SwordsQuantity = 5f;
|
||||
|
||||
public float ArrowDamages = 15f;
|
||||
public float ArrowRange = 5f;
|
||||
public float ArrowFrequency = 2f;
|
||||
|
||||
public float laserOnX = 0f;
|
||||
public float laserOnY = 0f;
|
||||
|
||||
// Kills stats
|
||||
[Header("Kills Stats")]
|
||||
public int MayorKills = 0;
|
||||
public int MinautorKills = 0;
|
||||
public int BringerOfDeathKills = 0;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject pauseMenu;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject deathScreen;
|
||||
[SerializeField]
|
||||
private GameObject _upgradeScreen;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -33,6 +49,16 @@ public class PlayerManager : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (BeamFrequency < 0f)
|
||||
{
|
||||
BeamFrequency = 0f;
|
||||
}
|
||||
|
||||
if (ArrowFrequency < 0.5f)
|
||||
{
|
||||
ArrowFrequency = 0.5f;
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
pauseMenu.SetActive(true);
|
||||
@@ -48,6 +74,9 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
Exp -= Level * 10;
|
||||
Level++;
|
||||
Time.timeScale = 0f;
|
||||
_upgradeScreen.SetActive(true);
|
||||
_upgradeScreen.GetComponentInChildren<UpgradeScreen>().GenerateChoice();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,12 +88,9 @@ public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
Health = 0;
|
||||
|
||||
// Death animation + menu
|
||||
Time.timeScale = 0f;
|
||||
deathScreen.SetActive(true);
|
||||
deathScreen.GetComponent<DeathScreen>().ShowScreen();
|
||||
} else
|
||||
{
|
||||
// Damage animation
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,38 +1,84 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent (typeof(PlayerMovements))]
|
||||
public class PlayerWeapons : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject laser;
|
||||
[SerializeField] private bool laserOnX;
|
||||
[SerializeField] private bool laserOnY;
|
||||
|
||||
[SerializeField] private GameObject arrow;
|
||||
|
||||
private PlayerMovements _pm;
|
||||
private PlayerManager _manager;
|
||||
|
||||
private float oldBeamFrequency;
|
||||
private bool oldBeamX;
|
||||
private bool oldBeamY;
|
||||
|
||||
private float oldArrowFrequency;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_pm = GetComponent<PlayerMovements>();
|
||||
_manager = GetComponent<PlayerManager>();
|
||||
|
||||
InvokeRepeating(nameof(ShootBeam), 5f, 5f);
|
||||
InvokeRepeating(nameof(ShootArrow), 2f, 2f);
|
||||
oldBeamFrequency = _manager.BeamFrequency;
|
||||
oldBeamX = Convert.ToBoolean(_manager.laserOnX);
|
||||
oldBeamY = Convert.ToBoolean(_manager.laserOnY);
|
||||
oldArrowFrequency = _manager.ArrowFrequency;
|
||||
|
||||
InvokeRepeating(nameof(ShootBeam), _manager.BeamFrequency, _manager.BeamFrequency);
|
||||
InvokeRepeating(nameof(ShootArrow), _manager.ArrowFrequency, _manager.ArrowFrequency);
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (_manager.BeamFrequency != oldBeamFrequency)
|
||||
{
|
||||
if (_manager.BeamFrequency > 0f)
|
||||
{
|
||||
CancelInvoke(nameof(ShootBeam));
|
||||
InvokeRepeating(nameof(ShootBeam), _manager.BeamFrequency, _manager.BeamFrequency);
|
||||
}
|
||||
else
|
||||
{
|
||||
CancelInvoke(nameof(ShootBeam));
|
||||
ShootBeam();
|
||||
}
|
||||
oldBeamFrequency = _manager.BeamFrequency;
|
||||
}
|
||||
|
||||
if (_manager.BeamFrequency == 0)
|
||||
{
|
||||
if (oldBeamX != Convert.ToBoolean(_manager.laserOnX) || oldBeamY != Convert.ToBoolean(_manager.laserOnY))
|
||||
{
|
||||
foreach (var beam in GameObject.FindGameObjectsWithTag("Beam"))
|
||||
{
|
||||
Destroy(beam);
|
||||
}
|
||||
oldBeamX = Convert.ToBoolean(_manager.laserOnX);
|
||||
oldBeamY = Convert.ToBoolean(_manager.laserOnY);
|
||||
ShootBeam();
|
||||
}
|
||||
}
|
||||
|
||||
if (_manager.ArrowFrequency != oldArrowFrequency)
|
||||
{
|
||||
CancelInvoke(nameof(ShootArrow));
|
||||
InvokeRepeating(nameof(ShootArrow), _manager.ArrowFrequency, _manager.ArrowFrequency);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShootBeam()
|
||||
{
|
||||
GameObject defaultBeam = Instantiate(laser, transform.position, _pm.lookOnRight ? Quaternion.identity : Quaternion.Euler(0, 0, 180), transform);
|
||||
defaultBeam.GetComponent<LaserBeam>().Damages = _manager.BeamDamages;
|
||||
Instantiate(laser, transform.position, Quaternion.identity, transform);
|
||||
|
||||
if (laserOnX)
|
||||
if (_manager.laserOnX > 0)
|
||||
{
|
||||
Instantiate(laser, transform.position, _pm.lookOnRight ? Quaternion.Euler(0, 0, 180) : Quaternion.identity, transform);
|
||||
Instantiate(laser, transform.position, Quaternion.Euler(0, 0, 180), transform);
|
||||
}
|
||||
|
||||
if (laserOnY)
|
||||
if (_manager.laserOnY > 0)
|
||||
{
|
||||
Instantiate(laser, transform.position, Quaternion.Euler(0, 0, 90), transform);
|
||||
Instantiate(laser, transform.position, Quaternion.Euler(0, 0, 270), transform);
|
||||
@@ -43,7 +89,7 @@ public class PlayerWeapons : MonoBehaviour
|
||||
private void ShootArrow()
|
||||
{
|
||||
// Get all enemies in given radius
|
||||
Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, 20f, LayerMask.GetMask("Enemy"));
|
||||
Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, _manager.ArrowRange, LayerMask.GetMask("Enemy"));
|
||||
|
||||
if (hits.Length <= 0)
|
||||
{
|
||||
@@ -68,7 +114,6 @@ public class PlayerWeapons : MonoBehaviour
|
||||
{
|
||||
GameObject spawnedArrow = Instantiate(arrow, transform.position, Quaternion.identity);
|
||||
spawnedArrow.GetComponent<Arrow>().target = target;
|
||||
spawnedArrow.GetComponent<Arrow>().Damages = _manager.ArrowDamages;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user