Skip to content

Commit

Permalink
Merged branch master into master
Browse files Browse the repository at this point in the history
  • Loading branch information
AdronTech committed Jan 21, 2017
2 parents 8ee819a + cb4a2d7 commit 9fd6a3a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 40 deletions.
Binary file modified GGJ17/Assets/Scene/BlockTest.unity
Binary file not shown.
19 changes: 9 additions & 10 deletions GGJ17/Assets/Script/Blocks/AbstractBuildingBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ public void Init(BuildingBlockInit init) {
nodes[back] = Instantiate(nodePrefab, transform).GetComponent<BuildNode>();
nodes[back].Init(back, this, false);
}
// initially dont show nodes
HideNodes();
}

#region ActivateNodes
public bool isNodesActive = false;
public bool isNodesActive = true;
public void ShowNodes(bool topN, bool sidesN)
{
isNodesActive = true;
Expand All @@ -81,19 +82,19 @@ public void ShowNodes(bool topN, bool sidesN)
}
if (sidesN)
{
if(neighbors[left] == null)
if (neighbors[left] == null)
{
nodes[left].Show();
}
if (neighbors[left] == null)
if (neighbors[right] == null)
{
nodes[right].Show();
}
if (neighbors[left] == null)
if (neighbors[front] == null)
{
nodes[front].Show();
}
if (neighbors[left] == null)
if (neighbors[back] == null)
{
nodes[back].Show();
}
Expand All @@ -102,12 +103,10 @@ public void ShowNodes(bool topN, bool sidesN)

public void HideNodes()
{
if (nodes == null)
isNodesActive = false;
foreach(BuildNode n in nodes)
{
foreach(BuildNode n in nodes)
{
if(n == null) n.Hide();
}
if(n) n.Hide();
}
}
#endregion
Expand Down
3 changes: 3 additions & 0 deletions GGJ17/Assets/Script/Blocks/Building/Building_EnemyLair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ void Start () {
bbi.sides = true;
Init(bbi);
}

public new void ShowNodes(bool topN, bool botN) { }
public new void HideNodes() { }
}
30 changes: 14 additions & 16 deletions GGJ17/Assets/Script/GodView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,32 @@ public class GodView : MonoBehaviour {
Camera myCam;
[SerializeField]
private GameObject constructionPrefab;
WorldScript w;

public void enableConstructionMode(GameObject prefab)
{
constructionPrefab = prefab;
WorldScript w = FindObjectOfType<WorldScript>();
AbstractBuildingBlock a = prefab.GetComponent<AbstractBuildingBlock>();
if (a)
if (a is Building_Wall)
{
if (a is Building_Wall)
{
w.flag.ShowNodes(true, true);
}
else if (a is Building_Extractor)
{
w.flag.ShowNodes(true, false);
}
else if (a is Building_Barracks)
{
w.flag.ShowNodes(true, false);
}
w.flag.ShowNodes(true, true);
}

else if (a is Building_Extractor)
{
w.flag.ShowNodes(true, false);
}
else if (a is Building_Barracks)
{
w.flag.ShowNodes(true, false);
}
w.ShowBuildNodes();
}

// Use this for initialization
void Start () {
myCam = GetComponent<Camera>();
}
w = FindObjectOfType<WorldScript>();
}

// Update is called once per frame
void Update()
Expand Down
41 changes: 27 additions & 14 deletions GGJ17/Assets/Script/WorldScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ public class WorldScript : MonoBehaviour {
public AbstractBuildingBlock[,] blocks;

public GameObject flagPrefab;
[HideInInspector]
public AbstractBuildingBlock flag;

void Start()
void Awake()
{
GenerateWorld();
}

void Start()
{
Vector3 flagSpawn = blocks[(int)size.x / 2, (int)size.y / 2].transform.position;
flagSpawn.y = 1;
flag = Instantiate(flagPrefab).GetComponent<AbstractBuildingBlock>();
flag.transform.position = flagSpawn;
HideBuildNodes();
}

void OnValidate()
{
size = new Vector2(Mathf.Floor(Mathf.Abs(size.x)), Mathf.Floor(Mathf.Abs(size.y)));
Expand All @@ -37,33 +47,36 @@ public void GenerateWorld()
blocks[x, y].transform.position = Vector3.forward * x + Vector3.right * y;
}
}
Vector3 flagSpawn = blocks[(int)size.x / 2, (int)size.y / 2].transform.position;
flagSpawn.y = 1;
if (flag) Destroy(flag);
flag = Instantiate(flagPrefab).GetComponent<AbstractBuildingBlock>();
flag.transform.position = flagSpawn;
}

public void ShowGroundBuildNodes(bool topN, bool sideN)
public void ShowBuildNodes()
{
//sweep the floor
for (int x = 0; x < size.x; x++)
for (int y = 0; y < size.y; y++)
{
if (blocks[x, y].isNodesActive)
{
blocks[x - 1, y].ShowNodes(topN,sideN);
blocks[x, y - 1].ShowNodes(topN, sideN);
if (x - 1 >= 0) blocks[x - 1, y].ShowNodes(true, false);
if (y - 1 >= 0) blocks[x, y - 1].ShowNodes(true, false);
}
else
{
if (blocks[x - 1, y].isNodesActive || blocks[x, y - 1].isNodesActive)
{
blocks[x, y].ShowNodes(topN, sideN); ;
}
if(x > 0)
if(blocks[x - 1, y].isNodesActive)
{
blocks[x, y].ShowNodes(true, false);
}
if(y > 0)
if(blocks[x, y - 1].isNodesActive)
{
blocks[x, y].ShowNodes(true, false);
}
}
}
}
public void HideGroundBuildNodes()

public void HideBuildNodes()
{
for (int x = 0; x < size.x; x++)
for (int y = 0; y < size.y; y++)
Expand Down

0 comments on commit 9fd6a3a

Please sign in to comment.