Skip to content

Commit

Permalink
Barracks NYI
Browse files Browse the repository at this point in the history
  • Loading branch information
LEM-II\Ilja committed Jan 22, 2017
1 parent 4cb7504 commit 53421cb
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 13 deletions.
Binary file modified GGJ17/Assets/Scene/BlockTest.unity
Binary file not shown.
91 changes: 78 additions & 13 deletions GGJ17/Assets/Script/Blocks/Building/Building_Barracks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,101 @@

public class Building_Barracks : AbstractBaseBuilding {

public float EffectiveRange = 5;
public float AlertCheckIntervall = 1f;
public float AtackIntervall = 0.5f;
public bool isAlerted;
public Vector3 effectiveRange = new Vector3(5, 20, 5);
public float sonarPulseIntervall = 2f;
public int ticksToLeaveAlert = 10;
public float alertResourceDrain = -0.1f;
public float atackIntervall = 0.5f;

private LineRenderer ousiaRay;
private Collider[] enemiesSpotted = new Collider[0];

private bool isAlerted;
public bool IsAlerted
{
set
{
isAlerted = value;
if (value)
{
FindObjectOfType<ResourceManager>().RegisterResources(alertResourceDrain);
}
else
{
FindObjectOfType<ResourceManager>().DeregisterResources(alertResourceDrain);
}
}
}

// Use this for initialization
void Awake () {
ousiaRay = GetComponent<LineRenderer>();
ousiaRay.SetPosition(0, transform.position);
BuildingBlockInit bbi = new BuildingBlockInit();
bbi.up = bbi.down = true;
bbi.sides = false;
Init(bbi);
}

void Update()
void Start()
{
StartCoroutine(Sonar());
}

private bool AlertCheck(out Collider[] cc)
{
cc = Physics.OverlapBox(transform.position,
effectiveRange,
Quaternion.identity,
LayerMask.NameToLayer("Enemy"));
return cc.Length > 0;
}

public Collider AquireTarget()
{
if (!isAlerted)
foreach(Collider enemy in enemiesSpotted)
{
Collider[] cc = Physics.OverlapBox(transform.position, new Vector3(EffectiveRange, 20, EffectiveRange));
foreach(Collider c in cc)
Vector3 dir = enemy.transform.position - transform.position;
float distance = dir.magnitude;
dir.Normalize();
if (Physics.Raycast(transform.position, dir, distance))
{ continue; }
else
{
if(c.tag == "Enemy")
{
ousiaRay.SetPosition(1, enemy.transform.position);
return enemy;
}

}
}
return null;
}

public IEnumerator Sonar()
{
int clearTicks = 0;
while(true)
{
Collider[] cc;
if(AlertCheck(out cc))
{
if(!isAlerted) StartCoroutine(Engaging());
clearTicks = 0;
IsAlerted = true;
}
else if(++clearTicks == ticksToLeaveAlert)
{
IsAlerted = false;
}
yield return new WaitForSeconds(sonarPulseIntervall);
}
}

public IEnumerator OnAlert()
public IEnumerator Engaging()
{
yield return null;
for(Collider target = AquireTarget(); target; target = AquireTarget())
{

yield return null;
}
}
}

0 comments on commit 53421cb

Please sign in to comment.