Implement passive relics and six-family defense towers
This commit is contained in:
@@ -5,11 +5,15 @@ namespace BumpCombat.Defense
|
||||
[DisallowMultipleComponent]
|
||||
public sealed class DefenseSummonUnit : MonoBehaviour
|
||||
{
|
||||
private static Sprite[] idleFrames;
|
||||
private static Sprite[] attackFrames;
|
||||
|
||||
private DefenseTower owner;
|
||||
private DefensePrototypeController controller;
|
||||
private Vector2 anchorLocalPosition;
|
||||
private SpriteRenderer spriteRenderer;
|
||||
private float attackCooldown;
|
||||
private float attackAnimationTime = -1f;
|
||||
|
||||
public void Configure(
|
||||
DefenseTower tower,
|
||||
@@ -20,18 +24,22 @@ namespace BumpCombat.Defense
|
||||
controller = prototypeController;
|
||||
anchorLocalPosition = localAnchor;
|
||||
spriteRenderer = gameObject.AddComponent<SpriteRenderer>();
|
||||
Sprite[] frames = Resources.LoadAll<Sprite>("Tutorial/Swordsman_Idle");
|
||||
if (frames != null && frames.Length > 0)
|
||||
idleFrames ??= Resources.LoadAll<Sprite>("Tutorial/Swordsman_Idle");
|
||||
attackFrames ??= Resources.LoadAll<Sprite>("Tutorial/Swordsman_BumpAttack-v1");
|
||||
if (idleFrames.Length > 0)
|
||||
{
|
||||
spriteRenderer.sprite = frames[0];
|
||||
spriteRenderer.sprite = idleFrames[0];
|
||||
}
|
||||
spriteRenderer.color = new Color32(255, 234, 137, 255);
|
||||
spriteRenderer.sortingOrder = 11;
|
||||
transform.localScale = new Vector3(0.9f, 0.9f, 1f);
|
||||
float scale = owner.Tier == 4 && owner.Branch == DefenseTowerBranch.First
|
||||
? 1.35f : 0.9f;
|
||||
transform.localScale = new Vector3(scale, scale, 1f);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateAttackSprite();
|
||||
if (owner == null
|
||||
|| !owner.isActiveAndEnabled
|
||||
|| controller == null
|
||||
@@ -41,11 +49,11 @@ namespace BumpCombat.Defense
|
||||
}
|
||||
|
||||
attackCooldown = Mathf.Max(0f, attackCooldown - Time.deltaTime);
|
||||
Vector2 anchor = owner.transform.TransformPoint(anchorLocalPosition);
|
||||
DefenseRouteAgent target = controller.FindNearestTarget(
|
||||
transform.position,
|
||||
anchor,
|
||||
controller.Tuning.SummonAreaRadius,
|
||||
DefenseTowerKind.Summon);
|
||||
Vector2 anchor = owner.transform.TransformPoint(anchorLocalPosition);
|
||||
if (target == null)
|
||||
{
|
||||
transform.position = Vector2.MoveTowards(
|
||||
@@ -56,24 +64,56 @@ namespace BumpCombat.Defense
|
||||
}
|
||||
|
||||
Vector2 targetPosition = target.transform.position;
|
||||
Vector2 fromAnchor = targetPosition - anchor;
|
||||
if (fromAnchor.magnitude > controller.Tuning.SummonAreaRadius)
|
||||
{
|
||||
targetPosition = anchor + fromAnchor.normalized * controller.Tuning.SummonAreaRadius;
|
||||
}
|
||||
|
||||
spriteRenderer.flipX = targetPosition.x < transform.position.x;
|
||||
transform.position = Vector2.MoveTowards(
|
||||
transform.position,
|
||||
targetPosition,
|
||||
controller.Tuning.SummonUnitMoveSpeed * Time.deltaTime);
|
||||
float attackRange = controller.Tuning.SummonAttackRange
|
||||
* (owner.Tier == 4 && owner.Branch == DefenseTowerBranch.Second ? 2.5f : 1f);
|
||||
if (attackCooldown <= 0f
|
||||
&& (target.transform.position - transform.position).sqrMagnitude <= controller.Tuning.SummonAttackRange * controller.Tuning.SummonAttackRange)
|
||||
&& (targetPosition - (Vector2)transform.position).sqrMagnitude
|
||||
<= attackRange * attackRange
|
||||
&& owner.TryAttack(target))
|
||||
{
|
||||
if (owner.TryAttack(target))
|
||||
{
|
||||
attackCooldown = controller.Tuning.SummonAttackInterval;
|
||||
}
|
||||
PlayAttackSprite();
|
||||
owner.ShowSummonAttackEffect(transform.position, targetPosition);
|
||||
attackCooldown = controller.Tuning.SummonAttackInterval
|
||||
/ (1f + 0.15f * (owner.Tier - 1))
|
||||
* controller.GetTowerAttackIntervalMultiplier(owner);
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayAttackSprite()
|
||||
{
|
||||
if (attackFrames.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
attackAnimationTime = 0f;
|
||||
spriteRenderer.sprite = attackFrames[0];
|
||||
}
|
||||
|
||||
private void UpdateAttackSprite()
|
||||
{
|
||||
if (attackAnimationTime < 0f || attackFrames == null
|
||||
|| attackFrames.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
attackAnimationTime += Time.deltaTime;
|
||||
int frame = Mathf.FloorToInt(attackAnimationTime * 12f);
|
||||
if (frame >= attackFrames.Length)
|
||||
{
|
||||
attackAnimationTime = -1f;
|
||||
if (idleFrames != null && idleFrames.Length > 0)
|
||||
{
|
||||
spriteRenderer.sprite = idleFrames[0];
|
||||
}
|
||||
return;
|
||||
}
|
||||
spriteRenderer.sprite = attackFrames[frame];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user