Commit 4e09397b by Naliwe GS

Need to add gameplay and HUD

parent c31cdab8
fileFormatVersion: 2
guid: a0438dee19db39d4f8e47a6a83709b0e
timeCreated: 1469997714
guid: 0dcaa528c3d6b304987dad5504a14b70
folderAsset: yes
timeCreated: 1475322288
licenseType: Free
NativeFormatImporter:
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
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:
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:
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:
No preview for this file type
......@@ -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
......@@ -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);
......
......@@ -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<Cell> {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<Cell>();
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<Cell> cells)
{
foreach (var cell in cells)
{
_map[(uint) cell.Position.x, (uint) cell.Position.y] = cell.Type;
}
}
public static IEnumerable<Cell> GetNeighbors(Map map, Cell origin)
{
var ret = new List<Cell>();
......@@ -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]));
}
}
}
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment