From 4e09397be006e63723e920bd42afc0b53b59ced2 Mon Sep 17 00:00:00 2001 From: Naliwe GS Date: Tue, 18 Oct 2016 02:52:50 +0200 Subject: [PATCH] Need to add gameplay and HUD --- .idea/.idea.igem-quantifly/.idea/workspace.xml | 322 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Assets/Images.meta | 9 +++++++++ Assets/Images/BG.png | Bin 0 -> 685738 bytes Assets/Images/BG.png.meta | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Assets/Images/BG_double.png | Bin 0 -> 409539 bytes Assets/Images/BG_double.png.meta | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Assets/Images/joueur_fiole-01.png | Bin 0 -> 18624 bytes Assets/Images/joueur_fiole-01.png.meta | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Assets/Prefabs/Player.prefab | Bin 6784 -> 0 bytes Assets/Prefabs/Player.prefab.meta | 8 -------- Assets/Scenes/Main.unity | Bin 20472 -> 0 bytes Assets/Scripts/GameController.cs | 49 +++++++++++++++++++++++++++++++++++++++++-------- Assets/Scripts/MapGeneration/Cell.cs | 2 +- Assets/Scripts/MapGeneration/CellularAutomaton.cs | 47 ++++++++++++++++++++++++++++++++++------------- Assets/Scripts/Utils/Map.cs | 16 ++++++++++++++++ 15 files changed, 396 insertions(+), 244 deletions(-) create mode 100644 Assets/Images.meta create mode 100644 Assets/Images/BG.png create mode 100644 Assets/Images/BG.png.meta create mode 100644 Assets/Images/BG_double.png create mode 100644 Assets/Images/BG_double.png.meta create mode 100644 Assets/Images/joueur_fiole-01.png create mode 100644 Assets/Images/joueur_fiole-01.png.meta delete mode 100644 Assets/Prefabs/Player.prefab delete mode 100644 Assets/Prefabs/Player.prefab.meta diff --git a/.idea/.idea.igem-quantifly/.idea/workspace.xml b/.idea/.idea.igem-quantifly/.idea/workspace.xml index d3e8b24..6c083db 100644 --- a/.idea/.idea.igem-quantifly/.idea/workspace.xml +++ b/.idea/.idea.igem-quantifly/.idea/workspace.xml @@ -2,12 +2,7 @@ - - - - - - + @@ -29,79 +24,35 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - + + - - - - - - + + + + + + + - - - - - - - - - - - - - + + + - - - - - - - - - - - + + + @@ -124,9 +75,10 @@ - @@ -199,32 +151,6 @@ - @@ -305,7 +232,7 @@ - + @@ -341,41 +268,64 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - + + + + + + + @@ -384,24 +334,7 @@ - - - - - - - - - - - - - - - - - - + @@ -410,13 +343,13 @@ - - - - - - - + + + + + + + @@ -425,24 +358,7 @@ - - - - - - - - - - - - - - - - - - + @@ -453,73 +369,51 @@ - + + - - + + + - + - - + + - + - - - - - - - - - + + - + - - - - - - - - - - - + + + - + - - + + - - - - - - - - - - - - - - - - + + + + + + + diff --git a/Assets/Images.meta b/Assets/Images.meta new file mode 100644 index 0000000..3d6fd58 --- /dev/null +++ b/Assets/Images.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 0dcaa528c3d6b304987dad5504a14b70 +folderAsset: yes +timeCreated: 1475322288 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Images/BG.png b/Assets/Images/BG.png new file mode 100644 index 0000000..ad440b1 Binary files /dev/null and b/Assets/Images/BG.png differ diff --git a/Assets/Images/BG.png.meta b/Assets/Images/BG.png.meta new file mode 100644 index 0000000..b2d4989 --- /dev/null +++ b/Assets/Images/BG.png.meta @@ -0,0 +1,64 @@ +fileFormatVersion: 2 +guid: b3d5feb9f4e6ba04798dbfcab5599481 +timeCreated: 1476749624 +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: 2 + 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: 8 + buildTargetSettings: + - buildTarget: Standalone + maxTextureSize: 8192 + textureFormat: -2 + compressionQuality: 50 + allowsAlphaSplitting: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Images/BG_double.png b/Assets/Images/BG_double.png new file mode 100644 index 0000000..3381728 Binary files /dev/null and b/Assets/Images/BG_double.png differ diff --git a/Assets/Images/BG_double.png.meta b/Assets/Images/BG_double.png.meta new file mode 100644 index 0000000..ae822cb --- /dev/null +++ b/Assets/Images/BG_double.png.meta @@ -0,0 +1,64 @@ +fileFormatVersion: 2 +guid: ec51cb931534401419d3e3af7374cfdf +timeCreated: 1476749627 +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: 2 + 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: 200 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + buildTargetSettings: + - buildTarget: Standalone + maxTextureSize: 8192 + textureFormat: -3 + compressionQuality: 50 + allowsAlphaSplitting: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Images/joueur_fiole-01.png b/Assets/Images/joueur_fiole-01.png new file mode 100644 index 0000000..5db5596 Binary files /dev/null and b/Assets/Images/joueur_fiole-01.png differ diff --git a/Assets/Images/joueur_fiole-01.png.meta b/Assets/Images/joueur_fiole-01.png.meta new file mode 100644 index 0000000..a6b7e39 --- /dev/null +++ b/Assets/Images/joueur_fiole-01.png.meta @@ -0,0 +1,59 @@ +fileFormatVersion: 2 +guid: a3dc2b557aa1b724fb1d4f3e26dfbb5e +timeCreated: 1476749619 +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/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab deleted file mode 100644 index 84cafe0..0000000 Binary files a/Assets/Prefabs/Player.prefab and /dev/null differ diff --git a/Assets/Prefabs/Player.prefab.meta b/Assets/Prefabs/Player.prefab.meta deleted file mode 100644 index 8918377..0000000 --- a/Assets/Prefabs/Player.prefab.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: a0438dee19db39d4f8e47a6a83709b0e -timeCreated: 1469997714 -licenseType: Free -NativeFormatImporter: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index dc1dc9c..a29f0dd 100644 Binary files a/Assets/Scenes/Main.unity and b/Assets/Scenes/Main.unity differ diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index b2f43fb..a1ed9d2 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -11,12 +11,10 @@ namespace Assets.Scripts public static bool CanGrow(Cell cell) { - - if (cell.Position.x == 0) + if (cell.Position.y == 0) return true; - if (cell.Position.x % 10 == 0) - return (cell.Position.y < 16 && (cell.Position.y * r.Next(100)) / 100 - < 50); + if (cell.Position.x%4 == 0) + return cell.Position.y < 16 && ((100/cell.Position.y)) > 6 + r.Next(94); return false; } } @@ -25,6 +23,8 @@ namespace Assets.Scripts { public static int PoolSize = 256; + public GameObject Wall; + private Map _map; private ObjectPool _pooledWalls; @@ -33,6 +33,8 @@ namespace Assets.Scripts private CellularAutomaton _ca; + private GameObject[] _tiles; + void Start() { _map = new Map(128, 128); @@ -41,13 +43,44 @@ namespace Assets.Scripts _pooledProjectiles = new ObjectPool(PoolSize); _pooledWalls = new ObjectPool(PoolSize); - _ca = new CellularAutomaton(_map, TileType.Wall); - _ca.CanGrowRule = CADelegates.CanGrow; + _ca = new CellularAutomaton(_map, TileType.Wall) {CanGrowRule = CADelegates.CanGrow}; + _tiles = new GameObject[_map.Columns*_map.Rows]; + + for (uint i = 0 ; i < _map.Columns * _map.Rows ; i++) + { + _tiles[i] = (GameObject) Instantiate(Wall, new Vector3(0, 0, 0), Quaternion.identity); + _tiles[i].SetActive(false); + } } void Update() { - _ca.Step(); + Camera.main.transform.Translate(new Vector3(0.5f * Time.deltaTime, 0, 0)); + var rightBorder = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, + Screen.height, 0)).x; + var leftBorder = Camera.main.ScreenToWorldPoint(new Vector3(0, 0, 0)).x; + _ca.Step(rightBorder); + + DrawMap(leftBorder, rightBorder); + // Debug.Log(_map); + } + + void DrawMap(float min, float max) + { + for (uint y = 0; y < _map.Rows; y++) + { + for (uint x = (uint) min % _map.Columns; x < max + 1 % _map.Columns; x++) + { + if (_map[x, y] == TileType.Wall) + { + var tile = _tiles[_map.Columns * y + x]; + var newX = (uint) (min / _map.Columns) * _map.Columns + x; + + tile.transform.position = new Vector3(newX, y, 0); + tile.SetActive(true); + } + } + } } } } \ No newline at end of file diff --git a/Assets/Scripts/MapGeneration/Cell.cs b/Assets/Scripts/MapGeneration/Cell.cs index 4be8067..f772d8b 100644 --- a/Assets/Scripts/MapGeneration/Cell.cs +++ b/Assets/Scripts/MapGeneration/Cell.cs @@ -14,7 +14,7 @@ namespace Assets.Scripts.MapGeneration #region Ctors - public Cell(int x, int y, TileType type) + public Cell(uint x, uint y, TileType type) { Type = type; Position = new Vector2(x, y); diff --git a/Assets/Scripts/MapGeneration/CellularAutomaton.cs b/Assets/Scripts/MapGeneration/CellularAutomaton.cs index 97c274a..6a0e1a6 100644 --- a/Assets/Scripts/MapGeneration/CellularAutomaton.cs +++ b/Assets/Scripts/MapGeneration/CellularAutomaton.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Runtime.Remoting.Messaging; using Assets.Scripts.Utils; using UnityEngine; @@ -18,11 +19,6 @@ namespace Assets.Scripts.MapGeneration { return true; } - - public static Cell DefaultPickTarget(Map map, Cell origin) - { - return CellularAutomaton.GetNeighbors(map, origin).FirstOrDefault(); - } } public class CellularAutomaton @@ -54,39 +50,64 @@ namespace Assets.Scripts.MapGeneration #region Ctors - public CellularAutomaton(Map map, TileType targetType, int startX = 0, int startY = 0) + public CellularAutomaton(Map map, TileType targetType, uint startX = 0, uint startY = 0) { _map = map; _targetType = targetType; CanGrowRule = DefaultCellDelegates.DefaultCanGrow; WillGrowRule = DefaultCellDelegates.DefaultWillGrow; - PickTargetRule = DefaultCellDelegates.DefaultPickTarget; _toProcess = new List {new Cell(startX, startY, targetType)}; + _map[startX, startY] = targetType; + ApplyToMap(_toProcess); } #endregion #region Methods - public void Step() + public void Step(float max) { + if (!_toProcess.Any()) + return; var newCells = new List(); foreach (var cell in _toProcess) { - if (!CanGrowRule(cell) || !WillGrowRule(cell)) + if (!NeedToCompute(cell, max)) + { + newCells.Add(cell); continue; + } - Grow(PickTargetRule(_map, cell), _targetType); + foreach (var target in GetNeighbors(_map, cell)) + { + if (!CanGrowRule(target) || !WillGrowRule(target)) + continue; - newCells.Add(cell); - } + Grow(target, _targetType); + newCells.Add(target); + } + } + ApplyToMap(newCells); _toProcess = newCells; } + private bool NeedToCompute(Cell cell, float max) + { + return cell.Position.x < max % _map.Columns; + } + + public void ApplyToMap(List cells) + { + foreach (var cell in cells) + { + _map[(uint) cell.Position.x, (uint) cell.Position.y] = cell.Type; + } + } + public static IEnumerable GetNeighbors(Map map, Cell origin) { var ret = new List(); @@ -98,7 +119,7 @@ namespace Assets.Scripts.MapGeneration if ((Math.Abs(x - origin.Position.x) > .1f || Math.Abs(y - origin.Position.y) > .1f) && IsInMapRange(map, (int) x, (int) y) && map[(uint) x, (uint) y] != origin.Type) { - ret.Add(new Cell((int) x, (int) y, map[(uint) x, (uint) y])); + ret.Add(new Cell((uint) x, (uint) y, map[(uint) x, (uint) y])); } } } diff --git a/Assets/Scripts/Utils/Map.cs b/Assets/Scripts/Utils/Map.cs index fed9c54..db8020e 100644 --- a/Assets/Scripts/Utils/Map.cs +++ b/Assets/Scripts/Utils/Map.cs @@ -43,5 +43,21 @@ get { return _map[x, y]; } set { _map[x, y] = value; } } + + public override string ToString() + { + string ret = ""; + + for (int y = 0; y < Rows; y++) + { + for (int x = 0; x < Columns; x++) + { + ret += _map[x, y] + " "; + } + ret += "\n"; + } + + return ret; + } } } \ No newline at end of file -- libgit2 0.27.0