diff --git a/Assets/Scripts/EnterPoint.cs b/Assets/Scripts/EnterPoint.cs index 6f474a574..6d453d5ca 100644 --- a/Assets/Scripts/EnterPoint.cs +++ b/Assets/Scripts/EnterPoint.cs @@ -10,7 +10,7 @@ public class EnterPoint : MonoBehaviour { [SerializeField] private Settings _settings; [SerializeField] private Canvas _targetCanvas; - private float _timeScale = 1; + private float _timeScale = 1f; void Start() { diff --git a/Assets/Scripts/Model/Runtime/Projectiles/ArchToTileProjectile.cs b/Assets/Scripts/Model/Runtime/Projectiles/ArchToTileProjectile.cs index c37ed0218..b984d737d 100644 --- a/Assets/Scripts/Model/Runtime/Projectiles/ArchToTileProjectile.cs +++ b/Assets/Scripts/Model/Runtime/Projectiles/ArchToTileProjectile.cs @@ -25,16 +25,10 @@ protected override void UpdateImpl(float deltaTime, float time) float localHeight = 0f; float totalDistance = _totalDistance; + float maxHeight = totalDistance * 0.6f; - /////////////////////////////////////// - // Insert you code here - /////////////////////////////////////// + localHeight = maxHeight * (-(t * 2 - 1) * (t * 2 - 1) + 1); - - /////////////////////////////////////// - // End of the code to insert - /////////////////////////////////////// - Height = localHeight; if (time > StartTime + _timeToTarget) Hit(_target); diff --git a/Assets/Scripts/UnitBrains/Player/SecondUnitBrain.cs b/Assets/Scripts/UnitBrains/Player/SecondUnitBrain.cs index c2c80e989..2fd6da507 100644 --- a/Assets/Scripts/UnitBrains/Player/SecondUnitBrain.cs +++ b/Assets/Scripts/UnitBrains/Player/SecondUnitBrain.cs @@ -1,6 +1,10 @@ -using System.Collections.Generic; +using Model; using Model.Runtime.Projectiles; +using System.Collections.Generic; +using System.Linq; using UnityEngine; +using UnityEngine.UIElements; +using Utilities; namespace UnitBrains.Player { @@ -12,43 +16,74 @@ public class SecondUnitBrain : DefaultPlayerUnitBrain private float _temperature = 0f; private float _cooldownTime = 0f; private bool _overheated; - + private List UnreachableTargets = new List(); + protected override void GenerateProjectiles(Vector2Int forTarget, List intoList) { float overheatTemperature = OverheatTemperature; - /////////////////////////////////////// - // Homework 1.3 (1st block, 3rd module) - /////////////////////////////////////// - var projectile = CreateProjectile(forTarget); - AddProjectileToList(projectile, intoList); - /////////////////////////////////////// + + if (GetTemperature() >= overheatTemperature) //Checking for overheating + { + return; + } + + int projectileCount = (int)( _temperature + 1); //Calculating the number of shells + + for (int i = 0; i < projectileCount; i++) //Creating projectiles in a cycle + { + var projectile = CreateProjectile(forTarget); + AddProjectileToList(projectile, intoList); + } + + IncreaseTemperature(); //Temperature rise } public override Vector2Int GetNextStep() { - return base.GetNextStep(); + if (UnreachableTargets.Count == 0 || GetReachableTargets().Contains(UnreachableTargets[0])) + return unit.Pos; + else + return unit.Pos.CalcNextStepTowards(UnreachableTargets[0]); } protected override List SelectTargets() { - /////////////////////////////////////// - // Homework 1.4 (1st block, 4rd module) - /////////////////////////////////////// - List result = GetReachableTargets(); - while (result.Count > 1) + UnreachableTargets.Clear(); + List result = GetAllTargets().ToList(); + if (result.Count > 1) { - result.RemoveAt(result.Count - 1); + float min = float.MaxValue; + Vector2Int minResult = new Vector2Int(); + foreach (Vector2Int res in result) + { + if (DistanceToOwnBase(res) < min) + { + min = DistanceToOwnBase(res); + minResult = res; + } + + } + result.Clear(); + UnreachableTargets.Add(minResult); + if (GetReachableTargets().Contains(minResult)) + result.Add(minResult); + } + else + { + result.Clear(); + var enemyBase = runtimeModel.RoMap.Bases[IsPlayerUnitBrain ? RuntimeModel.BotPlayerId : RuntimeModel.PlayerId]; + UnreachableTargets.Add(enemyBase); + result.Add(enemyBase); } return result; - /////////////////////////////////////// } public override void Update(float deltaTime, float time) { if (_overheated) - { + { _cooldownTime += Time.deltaTime; - float t = _cooldownTime / (OverheatCooldown/10); + float t = _cooldownTime / (OverheatCooldown / 10); _temperature = Mathf.Lerp(OverheatTemperature, 0, t); if (t >= 1) { @@ -57,7 +92,6 @@ public override void Update(float deltaTime, float time) } } } - private int GetTemperature() { if(_overheated) return (int) OverheatTemperature;