Walls + Start Arrow
This commit is contained in:
parent
7da33be977
commit
33467f6cc4
71 changed files with 4255 additions and 81 deletions
|
@ -1,11 +1,49 @@
|
|||
using UnityEngine;
|
||||
|
||||
public enum DeathSate
|
||||
{
|
||||
NotImportant = 0,
|
||||
QueenADead = 1,
|
||||
QueenBDead = 2,
|
||||
|
||||
}
|
||||
|
||||
public abstract class AbstractUnit : MonoBehaviour
|
||||
{
|
||||
public float price;
|
||||
[field: SerializeField] public bool IsTeamA { get; private set; }
|
||||
[field: SerializeField] public bool IsQueen { get; private set; }
|
||||
public abstract bool Attack();
|
||||
|
||||
public abstract void TakeDamage(float damage);
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
if (IsTeamA)
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamA.Add(this);
|
||||
if (IsQueen) GlobalsVariable.QueenA = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamB.Add(this);
|
||||
if (IsQueen) GlobalsVariable.QueenB = this;
|
||||
}
|
||||
}
|
||||
|
||||
public DeathSate AbstractDeath()
|
||||
{
|
||||
if (IsTeamA)
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamA.Remove(this);
|
||||
if (IsQueen) return DeathSate.QueenADead;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamB.Remove(this);
|
||||
if (IsQueen) return DeathSate.QueenBDead;
|
||||
}
|
||||
return DeathSate.NotImportant;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
8
Assets/Scripts/UnitScripts/Attacks.meta
Normal file
8
Assets/Scripts/UnitScripts/Attacks.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bbb6d2297b3261d3a8edbd488757550a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
37
Assets/Scripts/UnitScripts/Attacks/ArrowHandler.cs
Normal file
37
Assets/Scripts/UnitScripts/Attacks/ArrowHandler.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Should be attached to the Arrow, not the skeleton
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class ArrowHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float baseDamage;
|
||||
[SerializeField] private float baseKnockback;
|
||||
public Rigidbody _rigidBody;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_rigidBody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
public void LaunchArrow(Vector3 baseSpeed)
|
||||
{
|
||||
_rigidBody.linearVelocity = baseSpeed;
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
// Can be optimized with tags, but it add dependance beetween teams
|
||||
if (collision.gameObject.TryGetComponent<AbstractUnit>(out AbstractUnit unit))
|
||||
{
|
||||
if (unit is MinecraftUnit)
|
||||
{
|
||||
MinecraftUnit minecraftUnit = unit as MinecraftUnit;
|
||||
Vector3 knockback = _rigidBody.linearVelocity * baseKnockback;
|
||||
minecraftUnit.StartCoroutine(minecraftUnit.MovementHandler.TakeImpulse(knockback));
|
||||
}
|
||||
unit.TakeDamage(baseDamage);
|
||||
}
|
||||
}
|
||||
}
|
2
Assets/Scripts/UnitScripts/Attacks/ArrowHandler.cs.meta
Normal file
2
Assets/Scripts/UnitScripts/Attacks/ArrowHandler.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9aa6ff4d0673f53389daff2a5ba3c45f
|
|
@ -7,13 +7,13 @@ using Random = UnityEngine.Random;
|
|||
[RequireComponent(typeof(MinecraftUnit))]
|
||||
public class AttackHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float damage;
|
||||
[SerializeField] private float cooldown;
|
||||
[SerializeField] private Collider attackShape;
|
||||
[SerializeField] private float knockbackHorizontalForce;
|
||||
[SerializeField] private float knockbackVerticalForce;
|
||||
[SerializeField] protected float damage;
|
||||
[SerializeField] protected float cooldown;
|
||||
[SerializeField] protected Collider attackShape;
|
||||
[SerializeField] protected float knockbackHorizontalForce;
|
||||
[SerializeField] protected float knockbackVerticalForce;
|
||||
|
||||
private float _timer;
|
||||
protected float _timer;
|
||||
private MinecraftUnit _minecraftUnit;
|
||||
|
||||
void Awake()
|
||||
|
@ -36,7 +36,7 @@ public class AttackHandler : MonoBehaviour
|
|||
/// Launch an Attack, and return true if it's possible to attack
|
||||
/// see what Units are in the attackShape, apply damage and knockback to those unit if they're ennemies
|
||||
/// </summary>
|
||||
public bool Attack()
|
||||
public virtual bool Attack()
|
||||
{
|
||||
if (_timer > 0) return false;
|
||||
|
18
Assets/Scripts/UnitScripts/Attacks/AttackSkeleton.cs
Normal file
18
Assets/Scripts/UnitScripts/Attacks/AttackSkeleton.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class AttackSkeleton : AttackHandler
|
||||
{
|
||||
[SerializeField] private GameObject arrowPrefab;
|
||||
[SerializeField] private float arrowBaseSpeed;
|
||||
[SerializeField] private Transform spawnPos;
|
||||
public override bool Attack()
|
||||
{
|
||||
if (_timer > 0) return false;
|
||||
|
||||
GameObject arrow = Instantiate(arrowPrefab, spawnPos.position, spawnPos.rotation);
|
||||
ArrowHandler arrowHandler = arrow.GetComponent<ArrowHandler>();
|
||||
arrowHandler.LaunchArrow(arrowBaseSpeed * spawnPos.forward);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6fa6d262ce5ee0761b28bd18f6bcd247
|
|
@ -4,8 +4,8 @@ using UnityEngine;
|
|||
|
||||
public static class GlobalsVariable
|
||||
{
|
||||
public static List<MinecraftUnit> AliveUnitsTeamA = new List<MinecraftUnit>();
|
||||
public static List<MinecraftUnit> AliveUnitsTeamB = new List<MinecraftUnit>();
|
||||
public static List<AbstractUnit> AliveUnitsTeamA = new List<AbstractUnit>();
|
||||
public static List<AbstractUnit> AliveUnitsTeamB = new List<AbstractUnit>();
|
||||
public static AbstractUnit QueenA;
|
||||
public static AbstractUnit QueenB;
|
||||
}
|
||||
|
|
|
@ -46,16 +46,9 @@ public class HealthHandler : MonoBehaviour
|
|||
|
||||
public void Death()
|
||||
{
|
||||
print("you dead");
|
||||
if (_minecraftUnit.IsTeamA)
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamA.Remove(_minecraftUnit);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamB.Remove(_minecraftUnit);
|
||||
}
|
||||
|
||||
DeathSate deathState = _minecraftUnit.AbstractDeath();
|
||||
if (deathState == DeathSate.QueenADead) print("TEAM B WIN GG");
|
||||
if (deathState == DeathSate.QueenBDead) print("TEAM A WIN GG");
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,36 +11,18 @@ public class MinecraftUnit : AbstractUnit
|
|||
[field: SerializeField] public AttackHandler AttackHandler { get; private set; }
|
||||
[field: SerializeField] public MovementHandler MovementHandler { get; private set; }
|
||||
|
||||
|
||||
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
Debug.Assert(Body != null);
|
||||
Debug.Assert(Body != null);
|
||||
Debug.Assert(HealthHandler != null);
|
||||
Debug.Assert(AttackHandler != null);
|
||||
Debug.Assert(MovementHandler != null);
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
if (IsTeamA)
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamA.Add(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamB.Add(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Abstract implementation for compatibility with other team
|
||||
|
||||
public override bool Attack()
|
||||
{
|
||||
return AttackHandler.Attack();
|
||||
}
|
||||
|
||||
public override void TakeDamage(float damage)
|
||||
{
|
||||
HealthHandler.TakeDamage(damage);
|
||||
|
|
|
@ -46,23 +46,23 @@ public class MovementHandler : MonoBehaviour
|
|||
MoveTowards(FindNearestEnemy().transform.position);
|
||||
}
|
||||
|
||||
MinecraftUnit FindNearestEnemy()
|
||||
AbstractUnit FindNearestEnemy()
|
||||
{
|
||||
List<MinecraftUnit> enemies = _minecraftUnit.IsTeamA ? GlobalsVariable.AliveUnitsTeamB : GlobalsVariable.AliveUnitsTeamA;
|
||||
List<AbstractUnit> enemies = _minecraftUnit.IsTeamA ? GlobalsVariable.AliveUnitsTeamB : GlobalsVariable.AliveUnitsTeamA;
|
||||
|
||||
MinecraftUnit closestMinecraftUnit = null;
|
||||
AbstractUnit closestUnit = null;
|
||||
float closestDistance = float.MaxValue;
|
||||
foreach (MinecraftUnit enemy in enemies)
|
||||
foreach (AbstractUnit enemy in enemies)
|
||||
{
|
||||
float distanceToEnemy = (enemy.transform.position - transform.position).sqrMagnitude;
|
||||
if (distanceToEnemy < closestDistance)
|
||||
{
|
||||
closestMinecraftUnit = enemy;
|
||||
closestUnit = enemy;
|
||||
closestDistance = distanceToEnemy;
|
||||
}
|
||||
}
|
||||
|
||||
return closestMinecraftUnit;
|
||||
return closestUnit;
|
||||
}
|
||||
|
||||
public IEnumerator TakeImpulse(Vector3 impulse)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue