public virtual int Size() { int nSize = 0; try { nSize += ErrorCode_Serializer.Size(error_code); nSize += sizeof(int); nSize += sizeof(int); nSize += sizeof(int); foreach (var tiles_itr in tiles) { DungeonTileType tiles_elmt = tiles_itr; nSize += DungeonTileType_Serializer.Size(tiles_elmt); } nSize += sizeof(ulong); nSize += Vector2Int_Serializer.Size(position); nSize += sizeof(int); foreach (var comrades_itr in comrades) { Player comrades_elmt = comrades_itr; nSize += Player_Serializer.Size(comrades_elmt); } nSize += sizeof(int); foreach (var enemies_itr in enemies) { Monster enemies_elmt = enemies_itr; nSize += Monster_Serializer.Size(enemies_elmt); } } catch (System.Exception) { return(-1); } return(nSize); }
public bool CheckSpaceType(int x, int y, int sizeX, int sizeY, DungeonTileType tileType) { //if (!CheckValidBounds(x, y, sizeX, sizeY)) // throw new ArgumentException("Invalid space bounds in room"); return(dungeon.CheckSpaceType(x + roomPositionX, y + roomPositionY, sizeX, sizeY, tileType)); }
public static bool Store(System.IO.MemoryStream _buf_, DungeonTileType obj) { try { _buf_.Write(System.BitConverter.GetBytes((int)obj), 0, sizeof(DungeonTileType)); } catch (System.Exception) { return(false); } return(true); }
public static bool Load(ref DungeonTileType obj, MemoryStream _buf_) { try { obj = (DungeonTileType)System.BitConverter.ToInt32(_buf_.ToArray(), (int)_buf_.Position); _buf_.Position += sizeof(DungeonTileType); } catch (System.Exception) { return(false); } return(true); }
public void ToggleCollider(DungeonTileType NewType) { bool SolidTile = NewType == DungeonTileType.TopWall || NewType == DungeonTileType.TopRightWall || NewType == DungeonTileType.RightWall || NewType == DungeonTileType.BottomRightWall || NewType == DungeonTileType.BottomWall || NewType == DungeonTileType.BottomLeftWall || NewType == DungeonTileType.LeftWall || NewType == DungeonTileType.TopLeftWall; SetCollider(SolidTile); }
//Initialised the tile gameobject if its not done yet, then sets its type and sprite to render with public void SetType(DungeonTileType TileType) { //Store the new tile type this.TileType = TileType; //Initialize the tile object if it hasnt been done yet if (!TileInitialised) { TileInitialised = true; TileObject = GameObject.Instantiate(DungeonGenerator.Instance.DungeonTilePrefab, WorldPos, Quaternion.identity, DungeonGenerator.Instance.CurrentDungeon.transform); } //Update the tiles sprite to match the new type given foreach (DungeonTileSprites.DungeonTileSprite TileSprite in DungeonTileSprites.Instance.TileSprites) { if (TileSprite.Type == TileType) { TileObject.SendMessage("UpdateSprite", TileSprite.Sprite); TileObject.SendMessage("ToggleCollider", TileType); break; } } //Update the tiles tag if (TileType == DungeonTileType.Door) { TileObject.tag = "Door"; } else if (TileType == DungeonTileType.BottomLeftWall || TileType == DungeonTileType.BottomRightWall || TileType == DungeonTileType.BottomWall || TileType == DungeonTileType.LeftWall || TileType == DungeonTileType.RightWall || TileType == DungeonTileType.TopLeftWall || TileType == DungeonTileType.TopRightWall || TileType == DungeonTileType.TopWall) { TileObject.tag = "Wall"; } else if (TileType == DungeonTileType.Floor) { TileObject.tag = "Floor"; } else { TileObject.tag = "Empty"; } }
public virtual bool Store(MemoryStream _buf_) { try { if (false == ErrorCode_Serializer.Store(_buf_, error_code)) { return(false); } _buf_.Write(BitConverter.GetBytes(width), 0, sizeof(int)); _buf_.Write(BitConverter.GetBytes(height), 0, sizeof(int)); _buf_.Write(BitConverter.GetBytes(tiles.Count), 0, sizeof(int)); foreach (var tiles_itr in tiles) { DungeonTileType tiles_elmt = tiles_itr; if (false == DungeonTileType_Serializer.Store(_buf_, tiles_elmt)) { return(false); } } _buf_.Write(BitConverter.GetBytes(unit_seq), 0, sizeof(ulong)); if (false == Vector2Int_Serializer.Store(_buf_, position)) { return(false); } _buf_.Write(BitConverter.GetBytes(comrades.Count), 0, sizeof(int)); foreach (var comrades_itr in comrades) { Player comrades_elmt = comrades_itr; if (false == Player_Serializer.Store(_buf_, comrades_elmt)) { return(false); } } _buf_.Write(BitConverter.GetBytes(enemies.Count), 0, sizeof(int)); foreach (var enemies_itr in enemies) { Monster enemies_elmt = enemies_itr; if (false == Monster_Serializer.Store(_buf_, enemies_elmt)) { return(false); } } } catch (System.Exception) { return(false); } return(true); }
public bool CheckSpaceType(int x, int y, int sizeX, int sizeY, DungeonTileType tileType) { if (!CheckValidBounds(x, y, sizeX, sizeY)) { throw new ArgumentException("Invalid space bounds"); } for (int xx = 0; xx < sizeX; xx++) { for (int yy = 0; yy < sizeY; yy++) { if (GetTile(xx + x, yy + y).type != tileType) { return(false); } } } return(true); }
public void UpdateEditorMesh() { MeshFilter meshFilter = GetComponent <MeshFilter>(); MeshCollider meshCollider = GetComponent <MeshCollider>(); if (!meshFilter || !meshCollider) { return; } UpdateDungeonSize(); Mesh mesh = meshFilter.sharedMesh; if (!mesh) { mesh = new Mesh(); } Vector3[] vertices = mesh.vertices; Color32[] colors = mesh.colors32; int[] triangles = mesh.triangles; int numVertices = sizeX * sizeY * 4; int numTriangles = sizeX * sizeY * 6; if (vertices == null || vertices.Length != numVertices) { vertices = new Vector3[numVertices]; } if (colors == null || colors.Length != numVertices) { colors = new Color32[numVertices]; } if (triangles == null || triangles.Length != numTriangles) { triangles = new int[numTriangles]; } if (triangleToTileMapping == null || triangleToTileMapping.Length != sizeX * sizeY * 2) { triangleToTileMapping = new int[sizeX * sizeY * 2]; } int vIndex = 0; int tIndex = 0; int tIndexMapping = 0; for (int x = 0; x < sizeX; x++) { for (int y = 0; y < sizeY; y++) { DungeonTileType tileType = tiles[x + y * sizeX]; Color32 color; switch (tileType) { case DungeonTileType.Wall: color = Color.red; break; default: color = Color.white; break; } vertices[vIndex + 0] = new Vector3(x, 0, y); vertices[vIndex + 1] = new Vector3(x + 1, 0, y); vertices[vIndex + 2] = new Vector3(x + 1, 0, y + 1); vertices[vIndex + 3] = new Vector3(x, 0, y + 1); colors[vIndex + 0] = color; colors[vIndex + 1] = color; colors[vIndex + 2] = color; colors[vIndex + 3] = color; triangles[tIndex + 0] = vIndex + 2; triangles[tIndex + 1] = vIndex + 1; triangles[tIndex + 2] = vIndex + 0; triangles[tIndex + 3] = vIndex + 0; triangles[tIndex + 4] = vIndex + 3; triangles[tIndex + 5] = vIndex + 2; triangleToTileMapping[tIndexMapping + 0] = (x << 16) | y; triangleToTileMapping[tIndexMapping + 1] = (x << 16) | y; vIndex += 4; tIndex += 6; tIndexMapping += 2; } } mesh.vertices = vertices; mesh.colors32 = colors; mesh.triangles = triangles; meshFilter.sharedMesh = mesh; meshCollider.sharedMesh = mesh; }
public static System.Int32 Size(DungeonTileType obj) { return(sizeof(DungeonTileType)); }
private bool isDoorDoor(DungeonTileType id) { return(id == DungeonTileType.DOORH || id == DungeonTileType.DOORV); }
private bool isDoorWall(DungeonTileType id) { return(id == DungeonTileType.WALL || id == DungeonTileType.WALLCORNER); }
public DungeonTile( DungeonTileType id ) { this.id = id; }
public virtual bool Load(MemoryStream _buf_) { try { if (false == ErrorCode_Serializer.Load(ref error_code, _buf_)) { return(false); } if (sizeof(int) > _buf_.Length - _buf_.Position) { return(false); } width = BitConverter.ToInt32(_buf_.GetBuffer(), (int)_buf_.Position); _buf_.Position += sizeof(int); if (sizeof(int) > _buf_.Length - _buf_.Position) { return(false); } height = BitConverter.ToInt32(_buf_.GetBuffer(), (int)_buf_.Position); _buf_.Position += sizeof(int); if (sizeof(int) > _buf_.Length - _buf_.Position) { return(false); } int tiles_length = BitConverter.ToInt32(_buf_.GetBuffer(), (int)_buf_.Position); _buf_.Position += sizeof(int); for (int tiles_itr = 0; tiles_itr < tiles_length; tiles_itr++) { DungeonTileType tiles_val = new DungeonTileType(); if (false == DungeonTileType_Serializer.Load(ref tiles_val, _buf_)) { return(false); } tiles.Add(tiles_val); } if (sizeof(ulong) > _buf_.Length - _buf_.Position) { return(false); } unit_seq = BitConverter.ToUInt64(_buf_.GetBuffer(), (int)_buf_.Position); _buf_.Position += sizeof(ulong); if (false == Vector2Int_Serializer.Load(ref position, _buf_)) { return(false); } if (sizeof(int) > _buf_.Length - _buf_.Position) { return(false); } int comrades_length = BitConverter.ToInt32(_buf_.GetBuffer(), (int)_buf_.Position); _buf_.Position += sizeof(int); for (int comrades_itr = 0; comrades_itr < comrades_length; comrades_itr++) { Player comrades_val = new Player(); if (false == Player_Serializer.Load(ref comrades_val, _buf_)) { return(false); } comrades.Add(comrades_val); } if (sizeof(int) > _buf_.Length - _buf_.Position) { return(false); } int enemies_length = BitConverter.ToInt32(_buf_.GetBuffer(), (int)_buf_.Position); _buf_.Position += sizeof(int); for (int enemies_itr = 0; enemies_itr < enemies_length; enemies_itr++) { Monster enemies_val = new Monster(); if (false == Monster_Serializer.Load(ref enemies_val, _buf_)) { return(false); } enemies.Add(enemies_val); } } catch (System.Exception) { return(false); } return(true); }
public DungeonTile(DungeonTileType id, int x, int y) { this.id = id; this.x = x; this.y = y; }
private bool isDoorFloor(DungeonTileType id) { return (id == DungeonTileType.CORRIDOR || id == DungeonTileType.ROOM); }
public DungeonTile( DungeonTileType id, int x, int y ) { this.id = id; this.x = x; this.y = y; }