Skip to content

Commit

Permalink
Shmui
Browse files Browse the repository at this point in the history
  • Loading branch information
LEM-II\Ilja committed Jan 22, 2017
1 parent d0e2ae5 commit 09b6764
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 126 deletions.
Binary file modified GGJ17/Assets/Scene/BlockTest.unity
Binary file not shown.
31 changes: 13 additions & 18 deletions GGJ17/Assets/Script/Blocks/AbstractBuildingBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,52 +70,47 @@ public void Init(BuildingBlockInit init) {
}

#region ActivateNodes
public bool isNodesActive = true;
public bool BlockOccupied
{
get
{
return neighbors[up];
}
}

public void ShowNodes(bool topN, bool sidesN)
{
isNodesActive = true;
if (topN && neighbors[up] == null)
if (topN && !neighbors[up] && nodes[up])
{
nodes[up].Show();
}
if (sidesN)
{
if (neighbors[left] == null)
if (!neighbors[left] && nodes[left])
{
nodes[left].Show();
}
if (neighbors[right] == null)
if (!neighbors[right] && nodes[right])
{
nodes[right].Show();
}
if (neighbors[front] == null)
if (!neighbors[front] && nodes[front])
{
nodes[front].Show();
}
if (neighbors[back] == null)
if (!neighbors[back] && nodes[back])
{
nodes[back].Show();
}
}
if(neighbors[down] && neighbors[down].tag == "Ground")
{
// update ground beneath me
neighbors[down].isNodesActive = true;
}
}

public void HideNodes()
{
isNodesActive = false;
foreach(BuildNode n in nodes)
{
if(n) n.Hide();
}
// update ground beneath me
if (neighbors[down] && neighbors[down].tag == "Ground")
{
neighbors[down].isNodesActive = false;
}
}
#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,86 @@
using System.Collections.Generic;
using UnityEngine;

public class BuildNode : MonoBehaviour {
#region references
public class BuildNode : MonoBehaviour {
#region references
private new BoxCollider collider;
private new MeshRenderer renderer;
private AbstractBuildingBlock block;
private AbstractBuildingBlock block;
#endregion


private int orientation;
private FixedJoint joint;
public float jointBreakForce = 100;

void Awake()
{
collider = GetComponent<BoxCollider>();
renderer = GetComponent<MeshRenderer>();
collider.enabled = true;
void Awake()
{
collider = GetComponent<BoxCollider>();
renderer = GetComponent<MeshRenderer>();
collider.enabled = true;
}

void OnTriggerEnter(Collider c)
{
BuildNode node = c.GetComponent<BuildNode>();
if (node)
{
block.neighbors[orientation] = node.block;
joint = block.gameObject.AddComponent<FixedJoint>();
joint.breakForce = jointBreakForce;
joint.connectedBody = node.block.GetComponent<Rigidbody>();
}
void OnTriggerEnter(Collider c)
{
BuildNode node = c.GetComponent<BuildNode>();
if (node)
{
block.neighbors[orientation] = node.block;
joint = block.gameObject.AddComponent<FixedJoint>();
joint.breakForce = jointBreakForce;
joint.connectedBody = node.block.GetComponent<Rigidbody>();
}
}

public void Init(int i, AbstractBuildingBlock block, bool invis)
{
if (invis)
{
Destroy(renderer);
Destroy(GetComponent<MeshFilter>());
}
this.block = block;
orientation = i;
transform.position = transform.parent.position;
switch (orientation)
{
case AbstractBuildingBlock.up:
transform.Translate(0, 0.5f, 0);
break;
case AbstractBuildingBlock.down:
transform.Translate(0, -0.5f, 0);
break;
case AbstractBuildingBlock.left:
transform.Translate(-0.5f, 0, 0);
break;
case AbstractBuildingBlock.right:
transform.Translate(0.5f, 0, 0);
break;
case AbstractBuildingBlock.front:
transform.Translate(0, 0, -0.5f);
break;
case AbstractBuildingBlock.back:
transform.Translate(0, 0, 0.5f);
break;
}

public void Init(int i, AbstractBuildingBlock block, bool invis)
{
if (invis)
{
Destroy(renderer);
Destroy(GetComponent<MeshFilter>());
}
this.block = block;
orientation = i;
transform.position = transform.parent.position;
switch (orientation)
{
case AbstractBuildingBlock.up:
transform.Translate(0, 0.5f, 0);
break;
case AbstractBuildingBlock.down:
transform.Translate(0, -0.5f, 0);
break;
case AbstractBuildingBlock.left:
transform.Translate(-0.5f, 0, 0);
break;
case AbstractBuildingBlock.right:
transform.Translate(0.5f, 0, 0);
break;
case AbstractBuildingBlock.front:
transform.Translate(0, 0, -0.5f);
break;
case AbstractBuildingBlock.back:
transform.Translate(0, 0, 0.5f);
break;
}
}

public void Show()
{
if (!joint)
{
if (renderer) renderer.enabled = true;
collider.enabled = true;
}
public void Show()
{
if (!joint)
{
if (renderer) renderer.enabled = true;
collider.enabled = true;
}
}

public void Hide()
{
if (renderer) renderer.enabled = false;
collider.enabled = false;
public void Hide()
{
if (renderer) renderer.enabled = false;
collider.enabled = false;
}

public Vector3 GetSpawnPosition()
{
return AbstractBuildingBlock.SpawnPoint(transform.parent.position, orientation);
public Vector3 GetSpawnPosition()
{
return AbstractBuildingBlock.SpawnPoint(transform.parent.position, orientation);
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion GGJ17/Assets/Script/Blocks/Building/Building_Barracks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class Building_Barracks : AbstractBuildingBlock {

// Use this for initialization
void Start () {
void Awake () {
BuildingBlockInit bbi = new BuildingBlockInit();
bbi.up = bbi.down = true;
bbi.sides = false;
Expand Down
2 changes: 1 addition & 1 deletion GGJ17/Assets/Script/Blocks/Building/Building_EnemyLair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class Building_EnemyLair : AbstractBuildingBlock {

// Use this for initialization
void Start () {
void Awake () {
BuildingBlockInit bbi = new BuildingBlockInit();
bbi.up = true;
bbi.down = true;
Expand Down
2 changes: 1 addition & 1 deletion GGJ17/Assets/Script/Blocks/Building/Building_Extractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class Building_Extractor : AbstractBuildingBlock {

// Use this for initialization
void Start () {
void Awake () {
BuildingBlockInit bbi = new BuildingBlockInit();
bbi.up = bbi.down = true;
bbi.sides = false;
Expand Down
2 changes: 1 addition & 1 deletion GGJ17/Assets/Script/Blocks/Building/Building_Wall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class Building_Wall : AbstractBuildingBlock {

// Use this for initialization
void Start () {
void Awake () {
BuildingBlockInit bbi = new BuildingBlockInit();
bbi.up = true;
bbi.down = true;
Expand Down
2 changes: 1 addition & 1 deletion GGJ17/Assets/Script/Blocks/Ground/Ground_Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class Ground_Resource : AbstractBuildingBlock {

// Use this for initialization
void Start () {
void Awake () {
BuildingBlockInit bbi = new BuildingBlockInit();
bbi.up = true;
bbi.down = false;
Expand Down
2 changes: 1 addition & 1 deletion GGJ17/Assets/Script/Blocks/Ground/Ground_Soil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class Ground_Soil : AbstractBuildingBlock {

// Use this for initialization
void Start () {
void Awake () {
BuildingBlockInit bbi = new BuildingBlockInit();
bbi.up = true;
bbi.down = bbi.sides = false;
Expand Down
33 changes: 22 additions & 11 deletions GGJ17/Assets/Script/GodView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,39 @@ public void enableConstructionMode(GameObject prefab)
void Start () {
myCam = GetComponent<Camera>();
w = FindObjectOfType<WorldScript>();
StartCoroutine(MouseLeftClick());
StartCoroutine(MouseRightClick());
}

// Update is called once per frame
void Update()
IEnumerator MouseLeftClick()
{
if (Input.GetMouseButtonUp(0))
while (true)
{
Ray r = myCam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(r, out hit))
yield return new WaitUntil(() => constructionPrefab && Input.GetMouseButtonDown(0));
{
BuildNode node = hit.collider.GetComponent<BuildNode>();
if (node)
GameObject construction = constructionPrefab;
RaycastHit hit;
if (Physics.Raycast(myCam.ScreenPointToRay(Input.mousePosition), out hit))
{
Instantiate(constructionPrefab, node.GetSpawnPosition(), Quaternion.identity);
BuildNode node = hit.collider.GetComponent<BuildNode>();
if (node)
{
Instantiate(construction, node.GetSpawnPosition(), Quaternion.identity);
}
yield return new WaitForFixedUpdate();
enableConstructionMode(constructionPrefab);
}
}
}
if (Input.GetMouseButtonDown(1) && constructionPrefab != null)
}

IEnumerator MouseRightClick()
{
while (true)
{
w.HideNodes();
yield return new WaitUntil(() => Input.GetMouseButtonDown(1));
constructionPrefab = null;
w.HideNodes();
}
}
}
9 changes: 9 additions & 0 deletions GGJ17/Assets/Script/WorldControl.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 09b6764

Please sign in to comment.