diff --git a/Assets/Prefabs/blue.prefab b/Assets/Prefabs/blue.prefab index fe83f9cb2bb02c2daf22ce3c9ccdc13907025393..ad3ec1f1cefa2b9de5d1ff20bdc6fe7fbe7d46b4 100644 Binary files a/Assets/Prefabs/blue.prefab and b/Assets/Prefabs/blue.prefab differ diff --git a/Assets/Prefabs/blue.prefab.meta b/Assets/Prefabs/blue.prefab.meta new file mode 100644 index 0000000000000000000000000000000000000000..68d44e510b3b8f5a95fd8ce07acb0229c9104c6c --- /dev/null +++ b/Assets/Prefabs/blue.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d3fd44e8ccb7ad54b8f9d534900cdb93 +timeCreated: 1477085344 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/white.prefab b/Assets/Prefabs/white.prefab index 50b1fdfc8dc45127949c6fb9d584042587d278c9..bad495bc607a63723e35c69cbba4baa3f8003848 100644 Binary files a/Assets/Prefabs/white.prefab and b/Assets/Prefabs/white.prefab differ diff --git a/Assets/Prefabs/white.prefab.meta b/Assets/Prefabs/white.prefab.meta new file mode 100644 index 0000000000000000000000000000000000000000..f48cf8de2ee9b2e0261f09c098fbd17262ccd81c --- /dev/null +++ b/Assets/Prefabs/white.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d84b90404a95ff74c813d205e25dfd0c +timeCreated: 1477085344 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Levels/.txt b/Assets/Resources/Levels/.txt deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/Assets/Resources/Levels/0.png b/Assets/Resources/Levels/0.png new file mode 100644 index 0000000000000000000000000000000000000000..f92bd32ee050c95b99b70a959d95abe12920eec7 Binary files /dev/null and b/Assets/Resources/Levels/0.png differ diff --git a/Assets/Resources/Levels/0.png.meta b/Assets/Resources/Levels/0.png.meta new file mode 100644 index 0000000000000000000000000000000000000000..8a49d8c73f7d30eb2afb90772a81eeb1660a082e --- /dev/null +++ b/Assets/Resources/Levels/0.png.meta @@ -0,0 +1,59 @@ +fileFormatVersion: 2 +guid: 74d7f1f922d265a4cb8e8989f9608bbf +timeCreated: 1477086866 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 2 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + linearTexture: 0 + correctGamma: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 1 + grayScaleToAlpha: 0 + generateCubemap: 0 + cubemapConvolution: 0 + cubemapConvolutionSteps: 7 + cubemapConvolutionExponent: 1.5 + seamlessCubemap: 0 + textureFormat: -1 + maxTextureSize: 2048 + textureSettings: + filterMode: 0 + aniso: 16 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + rGBM: 0 + compressionQuality: 50 + allowsAlphaSplitting: 0 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 5 + buildTargetSettings: [] + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Levels/0.txt b/Assets/Resources/Levels/0.txt new file mode 100644 index 0000000000000000000000000000000000000000..eadf0afbc81f541466d507ef6a9cf1550a3ada95 --- /dev/null +++ b/Assets/Resources/Levels/0.txt @@ -0,0 +1,16 @@ +Assets/Resources/Prefab/1_front.prefab +0 +0 +0 +Assets/Resources/Prefab/5_back.prefab +255 +255 +255 +Assets/Resources/Prefab/crate_16.prefab +255 +0 +0 +Assets/Resources/Prefab/Tree_01.prefab +0 +255 +0 diff --git a/Assets/Resources/Levels/0.txt.meta b/Assets/Resources/Levels/0.txt.meta new file mode 100644 index 0000000000000000000000000000000000000000..30df50c31b5e8ce0cd780c026182ca5bf4daa464 --- /dev/null +++ b/Assets/Resources/Levels/0.txt.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b994f2c1c032bdf47a3135af993751bf +timeCreated: 1477086128 +licenseType: Free +TextScriptImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Prefab/1_front.prefab b/Assets/Resources/Prefab/1_front.prefab new file mode 100644 index 0000000000000000000000000000000000000000..414e65c68f83cf86cecec21f92c9309ae9e41670 Binary files /dev/null and b/Assets/Resources/Prefab/1_front.prefab differ diff --git a/Assets/Resources/Prefab/1_front.prefab.meta b/Assets/Resources/Prefab/1_front.prefab.meta new file mode 100644 index 0000000000000000000000000000000000000000..be2ceed80f88b82667d92d0c24cc646239e53741 --- /dev/null +++ b/Assets/Resources/Prefab/1_front.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 87ed77aef35072942a2705888df1a98f +timeCreated: 1477086529 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Prefab/5_back.prefab b/Assets/Resources/Prefab/5_back.prefab new file mode 100644 index 0000000000000000000000000000000000000000..c239f5bb48d46c2261253662b179cc6ff4590007 Binary files /dev/null and b/Assets/Resources/Prefab/5_back.prefab differ diff --git a/Assets/Resources/Prefab/5_back.prefab.meta b/Assets/Resources/Prefab/5_back.prefab.meta new file mode 100644 index 0000000000000000000000000000000000000000..a4154c1cf060558c9b3a872859e8245b9c73402f --- /dev/null +++ b/Assets/Resources/Prefab/5_back.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fe45769cb9d72ef458a5450c4d6cb5f6 +timeCreated: 1477086550 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Prefab/Tree_01.prefab b/Assets/Resources/Prefab/Tree_01.prefab new file mode 100644 index 0000000000000000000000000000000000000000..655cf9d603da9938272327f8b12c99ec02ab0e08 Binary files /dev/null and b/Assets/Resources/Prefab/Tree_01.prefab differ diff --git a/Assets/Resources/Prefab/Tree_01.prefab.meta b/Assets/Resources/Prefab/Tree_01.prefab.meta new file mode 100644 index 0000000000000000000000000000000000000000..ebb8462ef26ed198213b9167dea5025cb300c33a --- /dev/null +++ b/Assets/Resources/Prefab/Tree_01.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 47cd14cbf89bb8c4e9312e93e76b8811 +timeCreated: 1477086506 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Prefabs.meta b/Assets/Scenes.meta similarity index 67% rename from Assets/Resources/Prefabs.meta rename to Assets/Scenes.meta index 29cc42d1b801d4eab971e70d19bfbf9f86e5d047..936d9615199e86ab5b51d137a6204057f0095b87 100644 --- a/Assets/Resources/Prefabs.meta +++ b/Assets/Scenes.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 8e3fef4918cc34643b1b36754416b44c +guid: 9286c3aa67775f045a5055f3f164abde folderAsset: yes -timeCreated: 1477029607 +timeCreated: 1477085342 licenseType: Free DefaultImporter: userData: diff --git a/Assets/Scenes/Map Loader.unity b/Assets/Scenes/Map Loader.unity new file mode 100644 index 0000000000000000000000000000000000000000..0f4c33d8785100efea7b49a9ad82816e267a02da Binary files /dev/null and b/Assets/Scenes/Map Loader.unity differ diff --git a/Assets/Scenes/Map Loader.unity.meta b/Assets/Scenes/Map Loader.unity.meta new file mode 100644 index 0000000000000000000000000000000000000000..aecaa8e7c155b27760b6b7ad5f5756fa7dc1d659 --- /dev/null +++ b/Assets/Scenes/Map Loader.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9ebfaa068bf3ce248a1b8b8036d59c46 +timeCreated: 1477086128 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Map Maker.unity b/Assets/Scenes/Map Maker.unity new file mode 100644 index 0000000000000000000000000000000000000000..8633b31b53a2b68d1bb8df3a0ad91d18be76463d Binary files /dev/null and b/Assets/Scenes/Map Maker.unity differ diff --git a/Assets/Scenes/Map Maker.unity.meta b/Assets/Scenes/Map Maker.unity.meta new file mode 100644 index 0000000000000000000000000000000000000000..4c844d1ab560c5123c65e1622dcdb18c5ed0e40a --- /dev/null +++ b/Assets/Scenes/Map Maker.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d9bbbcc5e70ac6c4bbd42b3651aefea7 +timeCreated: 1477611955 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/test.unity b/Assets/Scenes/test.unity new file mode 100644 index 0000000000000000000000000000000000000000..f3b954557dc7095c294c281d6529b44c02024e38 Binary files /dev/null and b/Assets/Scenes/test.unity differ diff --git a/Assets/Scenes/test.unity.meta b/Assets/Scenes/test.unity.meta new file mode 100644 index 0000000000000000000000000000000000000000..3506cf387ebc7bec163b85fae151ef5632760596 --- /dev/null +++ b/Assets/Scenes/test.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2c983046a45213c438316fd281ecc003 +timeCreated: 1477182966 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts.meta b/Assets/Scripts.meta new file mode 100644 index 0000000000000000000000000000000000000000..154f4553467e8d0f43c8d61afe1bd1d6008d411f --- /dev/null +++ b/Assets/Scripts.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 4560b1c3b268ec94ca00c66f9b71ea9d +folderAsset: yes +timeCreated: 1477085342 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Heap.cs b/Assets/Scripts/Heap.cs deleted file mode 100644 index fdff8596b56240ffc15025a3dd6262b32db497cb..0000000000000000000000000000000000000000 --- a/Assets/Scripts/Heap.cs +++ /dev/null @@ -1,143 +0,0 @@ -using UnityEngine; -using System; -using System.Collections; -using System.Collections.Generic; - -/* -public class Heap where Tile : HeapItem{ - - Tile[] heapTiles; - int itemCount; - - //replace openList with Heap - - //add heapIndex, compareTo to tile class - //compare fCost of node then hCost - //item.compareTo(item2) should return pos if item is less than item2, neg if item is greater than item2 - - //create heap - public Heap(int maxSize) - { - heapTiles = new Tile[maxSize]; - } - - //add item into heap and sort it into position - public void Add(Tile item) - { - item.heapIndex = itemCount; - heapTiles[itemCount] = item; - SortUp(item); - itemCount++; - } - - //remove first tile and resort heap - public Tile RemoveFirst() - { - Tile first = heapTiles[0]; - itemCount--; - heapTiles[0] = heapTiles[itemCount]; - heapTiles[0].heapIndex = 0; - SortDown(heapTiles[0]); - return first; - } - - //resort item position - public void UpdateItem(Tile item) - { - SortUp(item); - } - - - public int Count - { - get - { - return itemCount; - } - } - - //does heap contain item - public bool Contains(Tile item) - { - return Equals(heapTiles[item.heapIndex], item); - } - - //sort tile lower into heap - void SortDown(Tile item) - { - while (true) - { - int leftChildIndex = item.heapIndex * 2 + 1; - int rightChildIndex = (item.heapIndex * 2) + 2; - int swapIndex = 0; - - if (leftChildIndex < itemCount) - { - swapIndex = leftChildIndex; - - if (rightChildIndex < itemCount) - { - if (heapTiles[leftChildIndex].CompareTo(heapTiles[rightChildIndex]) < 0) - { - swapIndex = rightChildIndex; - } - } - - if (item.CompareTo(heapTiles[swapIndex]) < 0) - { - Swap(item, heapTiles[swapIndex]); - } - else - { - return; - } - } - else - { - return; - } - } - } - - //sort item higher into heap - void SortUp(Tile item) - { - int indexOfParent = (item.heapIndex - 1) / 2; - - while (true) - { - Tile parent = heapTiles[indexOfParent]; - - if (item.CompareTo(parent) > 0) - { - Swap(item, parent); - } - else - { - break; - } - indexOfParent = (item.heapIndex - 1) / 2; - } - } - - //swap tiles - void Swap(Tile item1, Tile item2) - { - heapTiles[item1.heapIndex] = item2; - heapTiles[item2.heapIndex] = item1; - int tempIndex = item1.heapIndex; - item1.heapIndex = item2.heapIndex; - item2.heapIndex = tempIndex; - } -} - -public interface HeapItem : IComparable -{ - int heapIndex - { - get; - - set; - } -} -*/ diff --git a/Assets/Scripts/Heap.cs.meta b/Assets/Scripts/Heap.cs.meta deleted file mode 100644 index 79aa22748674935c8b2e328d864bad8b36fc6886..0000000000000000000000000000000000000000 --- a/Assets/Scripts/Heap.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 243bb794b9f808b409bcd50557270e5b -timeCreated: 1477007304 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/MapTool/MapMaker.cs b/Assets/Scripts/MapTool/MapMaker.cs new file mode 100644 index 0000000000000000000000000000000000000000..c47408021034e95c9f5620b790e0499eec00f78f --- /dev/null +++ b/Assets/Scripts/MapTool/MapMaker.cs @@ -0,0 +1,44 @@ +using UnityEngine; +using UnityEngine.UI; +using System.Collections; + +public class MapMaker : MonoBehaviour { + + public GameObject emptyTile; + + private Text rowsText; + private Text colsText; + + private Tile[,] map; + + void Start () { + + rowsText = GameObject.Find ("Rows").transform.FindChild("Text").GetComponent (); + colsText = GameObject.Find ("Cols").transform.FindChild("Text").GetComponent (); + } + + public void GenerateEmptyTiles () { + + int rows = 0; + int cols = 0; + + int.TryParse (rowsText.text, out rows); + int.TryParse (colsText.text, out cols); + + map = new Tile[cols, rows]; + + float startx = -(float)cols / 2f * emptyTile.transform.lossyScale.x; + float starty = (float)rows / 2f * emptyTile.transform.lossyScale.y; + + for (int y = 0; y < rows; y++) { + for (int x = 0; x < cols; x++) { + + map[x, y] = ((GameObject) Instantiate (emptyTile, new Vector2(startx + x * emptyTile.GetComponent().size.x, + starty - y * emptyTile.GetComponent().size.x), Quaternion.identity)).GetComponent (); + + map [x, y].x = x; + map [x, y].y = y; + } + } + } +} diff --git a/Assets/Scripts/Pathing/MapMaker.cs.meta b/Assets/Scripts/MapTool/MapMaker.cs.meta similarity index 76% rename from Assets/Scripts/Pathing/MapMaker.cs.meta rename to Assets/Scripts/MapTool/MapMaker.cs.meta index d5b85b43274aa4e948e802fef5c319686b65662b..9d297995b3ebc1a4b3ed19acd9a4e98088a6ddac 100644 --- a/Assets/Scripts/Pathing/MapMaker.cs.meta +++ b/Assets/Scripts/MapTool/MapMaker.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: b20dbd9f19ada364ca36dceb48c769a1 -timeCreated: 1477071770 +guid: 01d8f8592a701b6458d43a3ab7d32040 +timeCreated: 1477612509 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/Scripts/Pathing.meta b/Assets/Scripts/Pathing.meta new file mode 100644 index 0000000000000000000000000000000000000000..3c2cb23590cd65decd41fbdca9767e9520ab985b --- /dev/null +++ b/Assets/Scripts/Pathing.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 9dbbd5fe69390d5489f18914e7f5f7ad +folderAsset: yes +timeCreated: 1477085342 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Pathing/MapGen.cs b/Assets/Scripts/Pathing/AStar.cs similarity index 93% rename from Assets/Scripts/Pathing/MapGen.cs rename to Assets/Scripts/Pathing/AStar.cs index 85c3fc011ad71f9bef72dfeb3ca6f61fe5f5842e..5f6394a3014db10ef1b91c2644e20eb1ea5ea222 100644 --- a/Assets/Scripts/Pathing/MapGen.cs +++ b/Assets/Scripts/Pathing/AStar.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; -public class MapGen : MonoBehaviour { +public class AStar : MonoBehaviour { public int rows = 6; public int cols = 6; @@ -60,7 +60,7 @@ public class MapGen : MonoBehaviour { if (start == finish) { return; } - + open.Add (start); start.goal = 0; start.fitness = EstimateHeuristic (start, finish); @@ -76,7 +76,7 @@ public class MapGen : MonoBehaviour { continue; } - float tempGoal = current.goal + DistBetween(current, neighbors[i]) + 1 / neighbors[i].speedPercent; + float tempGoal = current.goal + DistBetween(current, neighbors[i]) + neighbors[i].weight; if (!open.Contains (neighbors[i])) { neighbors [i].prev = current; @@ -91,7 +91,9 @@ public class MapGen : MonoBehaviour { } // PrintPathRetrace (finish); - enemy.GetComponent ().BeginTraversingPath (CreatePath (finish)); + if (finish.prev != null) { + enemy.GetComponent ().BeginTraversingPath (CreatePath (finish)); + } } float EstimateHeuristic (Tile current, Tile finish) { diff --git a/Assets/Scripts/Pathing/MapGen.cs.meta b/Assets/Scripts/Pathing/AStar.cs.meta similarity index 100% rename from Assets/Scripts/Pathing/MapGen.cs.meta rename to Assets/Scripts/Pathing/AStar.cs.meta diff --git a/Assets/Scripts/Pathing/Heap.cs b/Assets/Scripts/Pathing/Heap.cs index 0cb244dbb6feed022a3a03aaf061bb0c94407b10..c0a3bfa73b89ca780d6417d79eea5d5da881fa42 100644 --- a/Assets/Scripts/Pathing/Heap.cs +++ b/Assets/Scripts/Pathing/Heap.cs @@ -40,6 +40,13 @@ public class Heap { return first; } + public void Remove (Tile item){ + + heapTiles [item.heapIndex].fitness = float.MinValue; + UpdateItem (item); + RemoveFirst (); + } + //resort item position public void UpdateItem(Tile item) { @@ -128,14 +135,4 @@ public class Heap { item1.heapIndex = item2.heapIndex; item2.heapIndex = tempIndex; } -} - -public interface HeapItem : IComparable -{ - int heapIndex - { - get; - - set; - } } \ No newline at end of file diff --git a/Assets/Scripts/Pathing/Heap.cs.meta b/Assets/Scripts/Pathing/Heap.cs.meta index 79aa22748674935c8b2e328d864bad8b36fc6886..322d1d255978794bfd9618da18c12148709f69d6 100644 --- a/Assets/Scripts/Pathing/Heap.cs.meta +++ b/Assets/Scripts/Pathing/Heap.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 243bb794b9f808b409bcd50557270e5b +guid: 2d7c8f1877f1ef34290c4e5d768fd5e4 timeCreated: 1477007304 licenseType: Free MonoImporter: diff --git a/Assets/Scripts/Pathing/MapMaker.cs b/Assets/Scripts/Pathing/MapMaker.cs deleted file mode 100644 index a6d95622a22ed14e7b7663c5f024f33020c9b4a8..0000000000000000000000000000000000000000 --- a/Assets/Scripts/Pathing/MapMaker.cs +++ /dev/null @@ -1,15 +0,0 @@ -using UnityEngine; -using System.Collections; - -public class MapMaker : MonoBehaviour { - - // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } -} diff --git a/Assets/Scripts/Pathing/ThetaStar.cs b/Assets/Scripts/Pathing/ThetaStar.cs new file mode 100644 index 0000000000000000000000000000000000000000..c4ae6364576dd2e316b16383d4e975357bb46fe9 --- /dev/null +++ b/Assets/Scripts/Pathing/ThetaStar.cs @@ -0,0 +1,150 @@ +using UnityEngine; +using System.Collections; +using System.Collections.Generic; + +public class ThetaStar : MonoBehaviour { + + public int rows = 6; + public int cols = 6; + + public GameObject tile; + public GameObject enemy; + public static Tile[,] map; + + public Tile startPos; + public Tile endPos; + + public Heap open; + + void Start () { + + map = new Tile[rows, cols]; + + float startx = -(float)rows / 2f * tile.transform.lossyScale.x; + float starty = (float)cols / 2f * tile.transform.lossyScale.y; + + for (int y = 0; y < cols; y++) { + for (int x = 0; x < rows; x++) { + + map[x, y] = ((GameObject) Instantiate (tile, new Vector2(startx + x * tile.GetComponent().size.x, + starty - y * tile.GetComponent().size.y), Quaternion.identity)).GetComponent (); + + map [x, y].x = x; + map [x, y].y = y; + } + } + + open = new Heap (rows * cols); + + enemy = (GameObject)(Instantiate (enemy, map[0, 0].transform.position, Quaternion.identity)); + } + + void FixedUpdate () { + + if (map[rows - 1, cols - 1].prev != null) { + + Tile current = map [rows - 1, cols - 1]; + while (current.prev != null) { + Debug.DrawLine (current.transform.position, current.prev.transform.position, Color.red); + current = current.prev; + } + } + } + + public void BeginPath () { + Path (map[0, 0], map[rows - 1, cols - 1]); + } + + void Path (Tile start, Tile finish) { + + start.goal = 0; + + start.fitness = EstimateHeuristic (start, finish); + open.Add (start); + + while (open.Count > 0) { + + Tile current = open.RemoveFirst (); + if (current == finish) { + break; + } + + current.closed = true; + + List neighbors = current.GetNeighbors (); + for (int i = 0; i < neighbors.Count; i++) { + + if (!neighbors[i].closed) { + if (!open.Contains(neighbors[i])) { + + neighbors [i].goal = float.MaxValue; + neighbors [i].prev = null; + } + + UpdateVertices (current, neighbors[i], finish); + } + } + } + + PrintPathRetrace (finish); + if (finish.prev != null) { + enemy.GetComponent ().BeginTraversingPath (CreatePath (finish)); + } + } + + void UpdateVertices (Tile current, Tile neighbor, Tile finish) { + + Debug.Log (neighbor.goal); + + if (current.goal + DistBetween(current, neighbor) < neighbor.goal) { + + neighbor.goal = current.goal + DistBetween (current, neighbor); + neighbor.prev = current; + + if (open.Contains (neighbor)) { + open.Remove (neighbor); + } + + neighbor.fitness = neighbor.goal + EstimateHeuristic(neighbor, finish); + open.Add (neighbor); + } + + Debug.Log (neighbor.goal); + } + + void ComputeCosts (Tile current, Tile neighbor) { + + if (current.goal + DistBetween(current, neighbor) + neighbor.weight < neighbor.goal) { + neighbor.prev = current; + neighbor.goal = current.goal + DistBetween(current, neighbor) + neighbor.weight; + } + } + + float EstimateHeuristic (Tile current, Tile finish) { + return Mathf.Abs (current.x - finish.x) + Mathf.Abs (current.y - finish.y); + } + + float DistBetween (Tile current, Tile neighbor) { + return Mathf.Pow(current.x - neighbor.x, 2) + Mathf.Pow(current.y - neighbor.y, 2); + } + + void PrintPathRetrace (Tile end) { + + while (end != null) { + Debug.Log (end.x + ", " + end.y); + end = end.prev; + } + } + + Path CreatePath (Tile finish) { + + Path path = new Path (); + + while (finish != null) { + path.Push (finish); + finish = finish.prev; + } + + return path; + } +} diff --git a/Assets/Scripts/Pathing/Tile.cs.meta b/Assets/Scripts/Pathing/ThetaStar.cs.meta similarity index 76% rename from Assets/Scripts/Pathing/Tile.cs.meta rename to Assets/Scripts/Pathing/ThetaStar.cs.meta index 9301078ce746358d6d21e9f631c4c734a9bc5a05..252c138fadcd1a50e29d5cd389b65d5b982ab125 100644 --- a/Assets/Scripts/Pathing/Tile.cs.meta +++ b/Assets/Scripts/Pathing/ThetaStar.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: 73c2a34237ac9dc4e98a964e7145a761 -timeCreated: 1476403999 +guid: 00b711ab1a936404798437e001aab668 +timeCreated: 1477184481 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Assets/Scripts/Pathing/Tile.cs b/Assets/Scripts/Pathing/Tile.cs deleted file mode 100644 index f58fe629639936f7d6892ce47a085a959729646c..0000000000000000000000000000000000000000 --- a/Assets/Scripts/Pathing/Tile.cs +++ /dev/null @@ -1,94 +0,0 @@ -using UnityEngine; -using System; -using System.Collections; -using System.Collections.Generic; - -public class Tile : MonoBehaviour, IComparable { - - public bool passable = true; - - public Color canPas = new Color (255f, 255f, 255f); - public Color cantPas = new Color (0f, 0f, 0f); - - private SpriteRenderer sprite; - - public int x; - public int y; - public Tile prev; - - public float goal = float.MaxValue; - public float fitness = float.MaxValue; - - public float speedPercent = 1f; - - public int heapIndex; - public bool closed; - - void Start () { - - sprite = GetComponent (); - } - - void OnMouseDown () { - - passable = !passable; - - if (passable) { - sprite.color = canPas; - } else { - sprite.color = cantPas; - } - } - - public int CompareTo (object obj) { - - if (!(obj is Tile)) { - return -1; - } - - return fitness - ((Tile) obj).fitness < 0 ? 1 : -1; - } - - public List GetNeighbors () { - - List neighbors = new List (); - - if (x < MapGen.map.GetLength(0) - 1 && MapGen.map[x + 1, y].passable) { - neighbors.Add (MapGen.map[x + 1, y]); - } - - if (x < MapGen.map.GetLength(0) - 1 && y < MapGen.map.GetLength(1) - 1 && MapGen.map[x + 1, y + 1].passable - && MapGen.map[x, y + 1].passable && MapGen.map[x + 1, y].passable) { - neighbors.Add (MapGen.map[x + 1, y + 1]); - } - - if (y < MapGen.map.GetLength (1) - 1 && MapGen.map [x, y + 1].passable) { - neighbors.Add (MapGen.map[x, y + 1]); - } - - if (x > 0 && y < MapGen.map.GetLength(1) - 1 && MapGen.map[x - 1, y + 1].passable - && MapGen.map[x, y + 1].passable && MapGen.map[x - 1, y].passable) { - neighbors.Add (MapGen.map[x - 1, y + 1]); - } - - if (x > 0 && MapGen.map[x - 1, y].passable) { - neighbors.Add (MapGen.map[x - 1, y]); - } - - if (x > 0 && y > 0 && MapGen.map[x - 1, y - 1].passable - && MapGen.map[x, y - 1].passable && MapGen.map[x - 1, y].passable) { - neighbors.Add (MapGen.map[x - 1, y - 1]); - } - - if (y > 0 && MapGen.map[x, y - 1].passable) { - neighbors.Add (MapGen.map[x, y - 1]); - } - - if (x < MapGen.map.GetLength(0) - 1 && y > 0 && MapGen.map[x + 1, y - 1].passable - && MapGen.map[x, y - 1].passable && MapGen.map[x + 1, y].passable) { - neighbors.Add (MapGen.map[x + 1, y - 1]); - } - - return neighbors; - } -} diff --git a/Assets/Scripts/World/Tile.cs b/Assets/Scripts/World/Tile.cs index 51eaf3ceba7f20e08dc063ef419d2dc6059d2896..2b7f3e9dbb0d98b577d1d1345ba603d3f77ead61 100644 --- a/Assets/Scripts/World/Tile.cs +++ b/Assets/Scripts/World/Tile.cs @@ -1,28 +1,91 @@ using UnityEngine; -using System.Collections; using System; +using System.Collections; +using System.Collections.Generic; public class Tile : MonoBehaviour, IComparable { - public bool walkable = false; - public int weight = 1; // The cost for moving through this tile + public bool walkable = true; + public float weight = 1; // The cost for moving through this tile // Set negative for unwalkable - public int x; public int y; - public Tile(bool walkable = true, int weight = 1) - { - this.walkable = walkable; - this.weight = weight; - } + public Color canPas = new Color (255f, 255f, 255f); + public Color cantPas = new Color (0f, 0f, 0f); - public int CompareTo(Tile other) - { - if (other == null) - return 1; - return (x + y) - (other.x - other.y); // Same coordinate. Should be the same tiles - } + private SpriteRenderer sprite; + + public Tile prev; + + public float goal = float.MaxValue; + public float fitness = float.MaxValue; + + public int heapIndex; + public bool closed; + + void Start () { + sprite = GetComponent (); + } + + void OnMouseDown () { + + walkable = !walkable; + + if (walkable) { + sprite.color = canPas; + } else { + sprite.color = cantPas; + } + } + + public int CompareTo (Tile tile) { + + return fitness - tile.fitness < 0 ? 1 : -1; + } + + public List GetNeighbors () { + + List neighbors = new List (); + + if (x < AStar.map.GetLength(0) - 1 && AStar.map[x + 1, y].walkable) { + neighbors.Add (AStar.map[x + 1, y]); + } + + if (x < AStar.map.GetLength(0) - 1 && y < AStar.map.GetLength(1) - 1 && AStar.map[x + 1, y + 1].walkable + && AStar.map[x, y + 1].walkable && AStar.map[x + 1, y].walkable) { + neighbors.Add (AStar.map[x + 1, y + 1]); + } + + if (y < AStar.map.GetLength (1) - 1 && AStar.map [x, y + 1].walkable) { + neighbors.Add (AStar.map[x, y + 1]); + } + + if (x > 0 && y < AStar.map.GetLength(1) - 1 && AStar.map[x - 1, y + 1].walkable + && AStar.map[x, y + 1].walkable && AStar.map[x - 1, y].walkable) { + neighbors.Add (AStar.map[x - 1, y + 1]); + } + + if (x > 0 && AStar.map[x - 1, y].walkable) { + neighbors.Add (AStar.map[x - 1, y]); + } + + if (x > 0 && y > 0 && AStar.map[x - 1, y - 1].walkable + && AStar.map[x, y - 1].walkable && AStar.map[x - 1, y].walkable) { + neighbors.Add (AStar.map[x - 1, y - 1]); + } + + if (y > 0 && AStar.map[x, y - 1].walkable) { + neighbors.Add (AStar.map[x, y - 1]); + } + + if (x < AStar.map.GetLength(0) - 1 && y > 0 && AStar.map[x + 1, y - 1].walkable + && AStar.map[x, y - 1].walkable && AStar.map[x + 1, y].walkable) { + neighbors.Add (AStar.map[x + 1, y - 1]); + } + + return neighbors; + } public String toString() { diff --git a/Assets/Sprites.meta b/Assets/Sprites.meta new file mode 100644 index 0000000000000000000000000000000000000000..8400516443c5815a1335054b55c7b013c29daee8 --- /dev/null +++ b/Assets/Sprites.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: e6249e9ab7bfe1e4fa5b4387b6eba4ac +folderAsset: yes +timeCreated: 1477085342 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Sprites/blue.png b/Assets/Sprites/blue.png new file mode 100644 index 0000000000000000000000000000000000000000..7904c5ba14d4b0cd61d2b6d4a246db53af4ffbdb Binary files /dev/null and b/Assets/Sprites/blue.png differ diff --git a/Assets/Sprites/blue.png.meta b/Assets/Sprites/blue.png.meta new file mode 100644 index 0000000000000000000000000000000000000000..bbc446018101b6592f5e94ec1494fe649c5ab496 --- /dev/null +++ b/Assets/Sprites/blue.png.meta @@ -0,0 +1,59 @@ +fileFormatVersion: 2 +guid: 39ceabc3f0997bf45bee68443c2786e2 +timeCreated: 1477183198 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 2 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + linearTexture: 0 + correctGamma: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 0 + cubemapConvolution: 0 + cubemapConvolutionSteps: 7 + cubemapConvolutionExponent: 1.5 + seamlessCubemap: 0 + textureFormat: -1 + maxTextureSize: 2048 + textureSettings: + filterMode: -1 + aniso: 16 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + rGBM: 0 + compressionQuality: 50 + allowsAlphaSplitting: 0 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 75 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + buildTargetSettings: [] + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Sprites/white 1.png b/Assets/Sprites/white 1.png new file mode 100644 index 0000000000000000000000000000000000000000..7c309a828e955b1b234b0222ea6b7857a84ced8e Binary files /dev/null and b/Assets/Sprites/white 1.png differ diff --git a/Assets/Sprites/white 1.png.meta b/Assets/Sprites/white 1.png.meta new file mode 100644 index 0000000000000000000000000000000000000000..91dab945b1c6b27d562599aae75e91df8a687aa1 --- /dev/null +++ b/Assets/Sprites/white 1.png.meta @@ -0,0 +1,59 @@ +fileFormatVersion: 2 +guid: 4e148317f1e84144db6d31f953893014 +timeCreated: 1477183198 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 2 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + linearTexture: 0 + correctGamma: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 0 + cubemapConvolution: 0 + cubemapConvolutionSteps: 7 + cubemapConvolutionExponent: 1.5 + seamlessCubemap: 0 + textureFormat: -1 + maxTextureSize: 2048 + textureSettings: + filterMode: -1 + aniso: 16 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + rGBM: 0 + compressionQuality: 50 + allowsAlphaSplitting: 0 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 75 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + buildTargetSettings: [] + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Sprites/white.png b/Assets/Sprites/white.png new file mode 100644 index 0000000000000000000000000000000000000000..9f7469b6b78b4061cb82c1f2ca19a5a96c13d76a Binary files /dev/null and b/Assets/Sprites/white.png differ diff --git a/Assets/Sprites/white.png.meta b/Assets/Sprites/white.png.meta new file mode 100644 index 0000000000000000000000000000000000000000..0c9a89afdbf0858e365472b1c1f139f168857df9 --- /dev/null +++ b/Assets/Sprites/white.png.meta @@ -0,0 +1,59 @@ +fileFormatVersion: 2 +guid: 2d88ea4508e5ffe42bd657ca080dc10b +timeCreated: 1477183198 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 2 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + linearTexture: 0 + correctGamma: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 0 + cubemapConvolution: 0 + cubemapConvolutionSteps: 7 + cubemapConvolutionExponent: 1.5 + seamlessCubemap: 0 + textureFormat: -1 + maxTextureSize: 2048 + textureSettings: + filterMode: -1 + aniso: -1 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + rGBM: 0 + compressionQuality: 50 + allowsAlphaSplitting: 0 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + buildTargetSettings: [] + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index 96548d5ef7218d34a18c32ab9fc5ee6908d02ebe..86d66c2c5f9ce09e3b7f58e2dbc5bced0a0ae09c 100644 Binary files a/ProjectSettings/GraphicsSettings.asset and b/ProjectSettings/GraphicsSettings.asset differ diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 0cbbfc1979b9767dd3792ef139609f3034a89800..70a61dd82c6a29c5d42f322b15b40800bf41a8f7 100755 Binary files a/ProjectSettings/ProjectSettings.asset and b/ProjectSettings/ProjectSettings.asset differ diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 558807b2abb8caaf19a04a93cd9e8d602f3d9a8a..96b25e7ca99d09513d0a1a425a1306567236dade 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 5.3.5f1 +m_EditorVersion: 5.4.1f1 m_StandardAssetsVersion: 0