Skip to content

Commit

Permalink
Add removing grass and adding dirt
Browse files Browse the repository at this point in the history
  • Loading branch information
nchistov committed Oct 5, 2022
1 parent 9de1f17 commit 2dcac50
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
4 changes: 2 additions & 2 deletions terra_craft/Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ BoxCollider2D:
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0.03503585, y: 0}
m_Offset: {x: 0.03503585, y: 0.060607076}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
Expand All @@ -502,7 +502,7 @@ BoxCollider2D:
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.77142286, y: 1.11}
m_Size: {x: 0.77142286, y: 1.2312143}
m_EdgeRadius: 0
--- !u!50 &730272227
Rigidbody2D:
Expand Down
50 changes: 42 additions & 8 deletions terra_craft/Assets/Scripts/WorldController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class WorldController : MonoBehaviour
{
private static Dictionary<GameObject, int> blocks = new Dictionary<GameObject, int>();
private Dictionary<GameObject, int> blocks = new Dictionary<GameObject, int>();
private static Dictionary<int, List<float>> BLOCK_DATA = new Dictionary<int, List<float>>();

[SerializeField] private GameObject[] prefabs;
Expand All @@ -14,6 +14,8 @@ public class WorldController : MonoBehaviour
private static GameObject _block;
private List<float> add = new List<float>();

private int count = 0;

public float currentInstremunt = 0.0f;

void Start()
Expand All @@ -39,9 +41,11 @@ void Start()
public GameObject GetObject(Vector3 position)
{
foreach (GameObject block in blocks.Keys) {
if (position.y > block.transform.position.y - 0.28f && position.y < block.transform.position.y + 0.28f) {
if (position.x > block.transform.position.x - 0.28f && position.x < block.transform.position.x + 0.28f) {
return block;
if (block != null) {
if (position.y > block.transform.position.y - 0.28f && position.y < block.transform.position.y + 0.28f) {
if (position.x > block.transform.position.x - 0.28f && position.x < block.transform.position.x + 0.28f) {
return block;
}
}
}
}
Expand Down Expand Up @@ -103,9 +107,11 @@ public void AddObject(Vector3 position, int type)
public bool ExistObject(Vector3 position)
{
foreach (GameObject block in blocks.Keys) {
if (position.y > block.transform.position.y - 0.28f && position.y < block.transform.position.y + 0.28f) {
if (position.x > block.transform.position.x - 0.28f && position.x < block.transform.position.x + 0.28f) {
return true;
if (block != null) {
if (position.y > block.transform.position.y - 0.28f && position.y < block.transform.position.y + 0.28f) {
if (position.x > block.transform.position.x - 0.28f && position.x < block.transform.position.x + 0.28f) {
return true;
}
}
}
}
Expand All @@ -114,6 +120,34 @@ public bool ExistObject(Vector3 position)

void Update()
{

if (count >= 180) {
count = 0;
FrameUpdate();
} else {
count += 1;
}
}

private void FrameUpdate()
{
Dictionary<Vector3, int> added = new Dictionary<Vector3, int>();

foreach (GameObject block in blocks.Keys) {
if (block != null) {
if (block.GetComponent<SpriteRenderer>().isVisible) {
if (blocks[block] == 0 && ExistObject(new Vector3(block.transform.position.x, block.transform.position.y + 1.15f, 0))) {
Vector3 pos = new Vector3(block.transform.position.x, block.transform.position.y, 0);
added.Add(pos, 1);
Destroy(block);
}
}
}
}

foreach (Vector3 pos in added.Keys) {
AddObject(pos, added[pos]);
}

added.Clear();
}
}

0 comments on commit 2dcac50

Please sign in to comment.