Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Assets/Scripts/Model/Runtime/Projectiles/ArchToTileProjectile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ArchToTileProjectile : BaseProjectile
private readonly Vector2Int _target;
private readonly float _timeToTarget;
private readonly float _totalDistance;

public ArchToTileProjectile(Unit unit, Vector2Int target, int damage, Vector2Int startPoint) : base(damage, startPoint)
{
_target = target;
Expand All @@ -20,21 +20,23 @@ protected override void UpdateImpl(float deltaTime, float time)
{
float timeSinceStart = time - StartTime;
float t = timeSinceStart / _timeToTarget;

Pos = Vector2.Lerp(StartPoint, _target, t);

float localHeight = 0f;
float totalDistance = _totalDistance;

///////////////////////////////////////
// Insert you code here
///////////////////////////////////////

float maxHeight = totalDistance * 0.6f;
localHeight = maxHeight * (-(t * 2 - 1) * (t * 2 - 1) + 1);

///////////////////////////////////////
// End of the code to insert
///////////////////////////////////////

Height = localHeight;
if (time > StartTime + _timeToTarget)
Hit(_target);
Expand Down
70 changes: 58 additions & 12 deletions Assets/Scripts/UnitBrains/Player/SecondUnitBrain.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.Generic;
using Model;
using Model.Runtime.Projectiles;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Utilities;

namespace UnitBrains.Player
{
Expand All @@ -12,43 +15,86 @@ public class SecondUnitBrain : DefaultPlayerUnitBrain
private float _temperature = 0f;
private float _cooldownTime = 0f;
private bool _overheated;

protected override void GenerateProjectiles(Vector2Int forTarget, List<BaseProjectile> intoList)
{
float overheatTemperature = OverheatTemperature;
///////////////////////////////////////
// Homework 1.3 (1st block, 3rd module)
///////////////////////////////////////
var projectile = CreateProjectile(forTarget);
AddProjectileToList(projectile, intoList);
///////////////////////////////////////

int temperature = GetTemperature();
if (temperature >= overheatTemperature)
{
return;
}

int projectileAmount = temperature + 1;
for (int i = 0; i < projectileAmount; i++)
{
var projectile = CreateProjectile(forTarget);
AddProjectileToList(projectile, intoList);
}

IncreaseTemperature();
///////////////////////////////////////
}

public override Vector2Int GetNextStep()
{
return base.GetNextStep();
List<Vector2Int> targets = SelectTargets();
if (targets.Count > 0)
{
Vector2Int firstTarget = targets[0];
if (IsTargetInRange(firstTarget))
{
return unit.Pos;
}
return unit.Pos.CalcNextStepTowards(firstTarget);
}
return unit.Pos;
}

protected override List<Vector2Int> SelectTargets()
{
///////////////////////////////////////
// Homework 1.4 (1st block, 4rd module)
///////////////////////////////////////
List<Vector2Int> result = GetReachableTargets();
while (result.Count > 1)
List<Vector2Int> allTargets = GetAllTargets().ToList();
List<Vector2Int> result = new List<Vector2Int>();

if (allTargets.Count <= 0)
{
result.RemoveAt(result.Count - 1);
Vector2Int enemyBase = runtimeModel.RoMap.Bases[RuntimeModel.BotPlayerId];
result.Add(enemyBase);
return result;
}

float minDistance = float.MaxValue;
Vector2Int finalTarget = allTargets[0];

foreach (var target in allTargets)
{
float targetDist = DistanceToOwnBase(target);
if (targetDist < minDistance)
{
minDistance = targetDist;
finalTarget = target;
}
}

result.Add(finalTarget);

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)
{
Expand All @@ -60,7 +106,7 @@ public override void Update(float deltaTime, float time)

private int GetTemperature()
{
if(_overheated) return (int) OverheatTemperature;
if (_overheated) return (int)OverheatTemperature;
else return (int)_temperature;
}

Expand Down