Skip to content

Commit

Permalink
buildings
Browse files Browse the repository at this point in the history
  • Loading branch information
LEM-II\Ilja committed Jan 22, 2017
1 parent 53421cb commit 0aca747
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 18 deletions.
2 changes: 0 additions & 2 deletions GGJ17/Assets/LairCannon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ public class LairCannon : MonoBehaviour {

void OnParticleCollision(GameObject go)
{
Debug.Log("Blubl");
if (go.tag.Equals("Ground"))
{
Debug.Log("Blubl" + go.transform.position);
Building_EnemyLair lair = GetComponentInParent<Building_EnemyLair>();
GameObject obj = Instantiate(lair.spawnPrefab);
obj.transform.position = go.transform.position + Vector3.up * 1.2f;
Expand Down
Binary file modified GGJ17/Assets/Prefab/BuildingBlocks/Building_Barracks.prefab
Binary file not shown.
Binary file modified GGJ17/Assets/Prefab/BuildingBlocks/Building_EnemyLair.prefab
Binary file not shown.
Binary file modified GGJ17/Assets/Prefab/BuildingBlocks/Building_Extractor.prefab
Binary file not shown.
Binary file modified GGJ17/Assets/Prefab/BuildingBlocks/Building_Flag.prefab
Binary file not shown.
Binary file modified GGJ17/Assets/Prefab/BuildingBlocks/Building_Wall.prefab
Binary file not shown.
Binary file modified GGJ17/Assets/Scene/BlockTest.unity
Binary file not shown.
48 changes: 32 additions & 16 deletions GGJ17/Assets/Script/Blocks/Building/Building_Barracks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Building_Barracks : AbstractBaseBuilding {
public float sonarPulseIntervall = 2f;
public int ticksToLeaveAlert = 10;
public float alertResourceDrain = -0.1f;
public float atackIntervall = 0.5f;
public float attackAimDuration = 1f, attackFlareDuration = 0.1f;

private LineRenderer ousiaRay;
private Collider[] enemiesSpotted = new Collider[0];
Expand All @@ -19,13 +19,14 @@ public bool IsAlerted
set
{
isAlerted = value;
ResourceManager m = FindObjectOfType<ResourceManager>();
if (value)
{
FindObjectOfType<ResourceManager>().RegisterResources(alertResourceDrain);
if(m)m.RegisterResources(alertResourceDrain);
}
else
{
FindObjectOfType<ResourceManager>().DeregisterResources(alertResourceDrain);
if(m)m.DeregisterResources(alertResourceDrain);
}
}
}
Expand Down Expand Up @@ -58,32 +59,36 @@ public Collider AquireTarget()
{
foreach(Collider enemy in enemiesSpotted)
{
Vector3 dir = enemy.transform.position - transform.position;
float distance = dir.magnitude;
dir.Normalize();
if (Physics.Raycast(transform.position, dir, distance))
{ continue; }
else
if (EvaluateTarget(enemy))
{
ousiaRay.SetPosition(1, enemy.transform.position);
return enemy;
}

}
return null;
}

public bool EvaluateTarget(Collider enemy)
{
Vector3 dir = enemy.transform.position - transform.position;
float distance = dir.magnitude;
dir.Normalize();
return !Physics.Raycast(transform.position, dir, distance, LayerMask.NameToLayer("Building"));
}

public int clearTicks = 0;
public IEnumerator Sonar()
{
int clearTicks = 0;
while(true)
{
Collider[] cc;
if(AlertCheck(out cc))
{
if(!isAlerted) StartCoroutine(Engaging());
if (!isAlerted)
{
StartCoroutine(Engaging());
IsAlerted = true;
}
clearTicks = 0;
IsAlerted = true;
}
else if(++clearTicks == ticksToLeaveAlert)
{
Expand All @@ -95,10 +100,21 @@ public IEnumerator Sonar()

public IEnumerator Engaging()
{
Debug.Log("Engaged!");
for(Collider target = AquireTarget(); target; target = AquireTarget())
{

yield return null;
Debug.Log("Aiming!");
Debug.DrawLine(transform.position, target.transform.position, Color.cyan);
yield return new WaitForSeconds(attackAimDuration);
if (EvaluateTarget(target))
{
ousiaRay.SetPosition(1, target.transform.position);
ousiaRay.enabled = true;
Destroy(target.gameObject);
yield return new WaitForSeconds(attackFlareDuration);
ousiaRay.enabled = false;
}
}
Debug.Log("No Targets!");
}
}
Binary file modified GGJ17/ProjectSettings/TagManager.asset
Binary file not shown.

0 comments on commit 0aca747

Please sign in to comment.