public override TileTextureData TexturePosition(TileChunk tileChunk, int x, int y) { TileTextureData tileTextureData = new TileTextureData(); tileTextureData.x = 2; tileTextureData.y = 1; return tileTextureData; }
public override TileTextureData TexturePosition(TileChunk tileChunk, int x, int y) { TileTextureData tileTextureData = new TileTextureData (); tileTextureData.x = 1; tileTextureData.y = 0; if(!tileChunk.GetTile(x, y + 1).IsSolid()) { tileTextureData.x = 1; tileTextureData.y = 1; } return tileTextureData; }
public void SetTile(int x, int y, Tile tile) { TileChunk chunk = GetChunk(x, y); if (chunk != null) { chunk.SetTile(x - chunk.pos.x, y - chunk.pos.y, tile); chunk.ChunkUpdate = true; UpdateIfEqual(x - chunk.pos.x, 0, new TileWorldPos(x - 1, y)); UpdateIfEqual(x - chunk.pos.x, TileChunk.ChunkSizeX - 1, new TileWorldPos(x + 1, y)); UpdateIfEqual(y - chunk.pos.y, 0, new TileWorldPos(x, y - 1)); UpdateIfEqual(y - chunk.pos.y, TileChunk.ChunkSizeY - 1, new TileWorldPos(x, y + 1)); } }
public TileChunk GetChunk(int x, int y) { TileWorldPos pos = new TileWorldPos(); float multipleX = TileChunk.ChunkSizeX; float multipleY = TileChunk.ChunkSizeY; pos.x = Mathf.FloorToInt(x / multipleX) * TileChunk.ChunkSizeX; pos.y = Mathf.FloorToInt(y / multipleY) * TileChunk.ChunkSizeY; TileChunk containerChunk = null; chunks.TryGetValue(pos, out containerChunk); return(containerChunk); }
public static bool SetTile(TileWorld World, Tile tile, Vector2 Pos) { TileChunk chunk = World.GetChunk(Mathf.RoundToInt(Pos.x), Mathf.RoundToInt(Pos.y)); if (chunk == null) { return(false); } TileWorldPos pos = GetTilePos(Pos); chunk.World.SetTile(pos.x, pos.y, tile); return(true); }
public override TileTextureData TexturePosition(TileChunk tileChunk, int x, int y) { TileTextureData tileTextureData = new TileTextureData(); tileTextureData.x = 1; tileTextureData.y = 0; if (!tileChunk.GetTile(x, y + 1).IsSolid()) { tileTextureData.x = 1; tileTextureData.y = 1; } return(tileTextureData); }
public void SaveTileChunkToFile(TileChunk Chunk, int Seed) { //Ask user if they want to continue as saving will overwrite all previous written chunks //Create directory if it doesn't exist string NewSaveDirectory = Application.dataPath + "\\World-" + Seed.ToString(); if (!Directory.Exists(NewSaveDirectory)) { Directory.CreateDirectory(NewSaveDirectory); Debug.Log("Directory Created"); } string FileName = Chunk.Position.x.ToString() + "," + Chunk.Position.y.ToString() + ".tc"; //Create File if it doesn't exist if (!File.Exists(NewSaveDirectory + "\\" + FileName)) { //File.Create (NewSaveDirectory + "\\" + FileName); File.Create(NewSaveDirectory + "\\" + FileName).Dispose(); } FileBinWriter = new BinaryWriter(File.Open(NewSaveDirectory + "\\" + FileName, FileMode.Open)); FileBinWriter.Write(Chunk.Position.x); FileBinWriter.Write(Chunk.Position.y); FileBinWriter.Write(Chunk.Width); FileBinWriter.Write(Chunk.Height); for (int i = 0; i < Chunk.Layers.Length; i++) { FileBinWriter.Write(Chunk.Layers [i]); } for (int i = 0; i < Chunk.LayerData.Length; i++) { FileBinWriter.Write(Chunk.LayerData [i].MaterialID); for (int x = 0; x < Chunk.Width; x++) { for (int y = 0; y < Chunk.Height; y++) { FileBinWriter.Write(Chunk.LayerData[i].Data[y * Chunk.Width + x]); } } } FileBinWriter.Close(); Debug.Log("File " + FileName + " written"); }
public void RpcSetTileAtNoBuild(Vector2 position, int id) { TileChunk cPrefab = tMass.tileChunkPrefab.GetComponent <TileChunk>(); Debug.Log("Yup"); int x = (int)position.x; int y = (int)position.y; int chunkX = (int)(x / cPrefab.chunkSizeX); int chunkY = (int)(y / cPrefab.chunkSizeY); int tileX = (int)(x - chunkX * cPrefab.chunkSizeX); int tileY = (int)(y - chunkY * cPrefab.chunkSizeY); tMass.tileChunks[chunkX, chunkY].GetComponent <TileChunk>().tiles[tileX, tileY].tileID = id; }
private void DestroyTilesInChunk(ref TileChunk chunk, Vector2 chunkPos, Vector2 explPos, Explosion explosion) { int ziklium = 0; int derylium = 0; for (int i = 0; i < TileChunk.Tiles; ++i) { var tile = chunk[i]; if (tile.type == TileType.None || tile.type == TileType.Bedrock) { continue; } var targetPos = chunkPos + TileChunk.PositionOffsetOfIndex(i) + Tile.OriginOffset; var distSqr = (targetPos - explPos).LengthSquared(); if (distSqr < explosion.radiusSqr) { var relDist = 1f - (distSqr / explosion.radiusSqr); var health = tile.health - (int)(explosion.impact * relDist) - 1; if (health <= 0) { if (tile.type == TileType.Derylium) { derylium++; } else if (tile.type == TileType.Ziklium) { ziklium++; } chunk[i] = new Tile(TileType.None); } else { chunk[i] = new Tile(chunk[i].type, health); } } } if (explosion.playerId == Player.playerId) { RocketResources.ziklium += ziklium * 20; RocketResources.derylium += derylium * 20; } }
public TileChunk LoadTileChunkFromFile(Vector2 ChunkPosition, int Seed) { TileChunk LoadedFile = new TileChunk(); string FileName = Application.dataPath + "\\World-" + Seed.ToString() + "\\" + ChunkPosition.x.ToString() + "," + ChunkPosition.y.ToString() + ".tc"; //Create File if it doesn't exist if (!File.Exists(FileName)) { Debug.Log("File does not exist"); } FileBinReader = new BinaryReader(File.OpenRead(FileName)); LoadedFile.Position.x = FileBinReader.ReadSingle(); LoadedFile.Position.y = FileBinReader.ReadSingle(); LoadedFile.Width = FileBinReader.ReadInt32(); LoadedFile.Height = FileBinReader.ReadInt32(); LoadedFile.Layers = new bool[8]; LoadedFile.LayerData = new TileData[8]; for (int i = 0; i < LoadedFile.Layers.Length; i++) { LoadedFile.Layers [i] = FileBinReader.ReadBoolean(); LoadedFile.LayerData [i] = new TileData(); } for (int i = 0; i < LoadedFile.LayerData.Length; i++) { LoadedFile.LayerData [i].MaterialID = FileBinReader.ReadInt32(); for (int x = 0; x < LoadedFile.Width; x++) { for (int y = 0; y < LoadedFile.Height; y++) { LoadedFile.LayerData [i].Data [y * LoadedFile.Width + x] = FileBinReader.ReadInt32(); } } } FileBinReader.Close(); Debug.Log("File " + FileName + " loaded"); return(LoadedFile); }
public TileChunk GetChunkNextTo(TileChunk chunk, int chunkOffsetX, int chunkOffsetY, int chunkOffsetZ) { int checkX = chunk.MinX + chunkOffsetX; int checkY = chunk.MinY + chunkOffsetY; int checkZ = chunk.MinZ + chunkOffsetZ; if ((checkX < 0 || checkX >= WidthInChunks) || (checkY < 0 || checkY >= HeightInChunks) || (checkZ < 0 || checkZ >= DepthInChunks) ) { return(null); } else { return(GetChunk(checkX, checkY, checkZ)); } }
//private void LoadSprites() { // Sprite[] loaded = Resources.LoadAll<Sprite>("sprites"); // foreach (Sprite s in loaded) { // //Debug.Log(s); // string sn = s.name; // int counter = 1; // while (true) { // if (!sprites.ContainsKey(sn)) { // sprites.Add(sn, s); // break; // } else { // sn = s.name + "_" + counter; // counter += 1; // } // } // } //} public void SetTileSprite(Tile t) { Sprite s = GetRandomSprite(t.type.sprites); TileChunk tc = t.chunk; tc.texture.SetPixels(t.local_x * 32, t.local_y * 32, 32, 32, s.texture.GetPixels()); tc.texture.Apply(); //SpriteRenderer sr = WorldController.Instance.GetGameObjectFromTile(t).GetComponent<SpriteRenderer>(); ////Debug.Log("give me sprite: " + t.type.spriteName); //sr.sprite = s;//GetSprite(t.type.spriteName); //if (t.zone == null) { // sr.color = Color.white; //} else { // sr.color = new Color(1, 0, 0, 0.1f); //} }
public void TileChunkGenerated(ChunkCoords coords, TileChunk chunk) { if (LoadedMeshes.ContainsKey(chunk.Coords)) { return; } var vertices = CreateVertexArray(chunk.BaseTiles); var indices = CreateIndicesArray(); var mesh = CreateMesh(vertices, indices); Entity meshEntity = new Entity($"ChunkMesh{coords.Cx},{coords.Cy}"); meshEntity.addComponent(mesh); scene.addEntity(meshEntity); meshEntity.position = chunk.Coords.ToWorldCoords(); LoadedMeshes.Add(chunk.Coords, meshEntity); }
public bool SetTile(int2 worldTilePosition, int id) { if (!TileUtil.BoundaryCheck(worldTilePosition, mapSize)) { return(false); } int index = TileUtil.To1DIndex(worldTilePosition, mapSize); if (tiles[index] == id) { return(false); } int2 chunkPosition = TileUtil.WorldTileToChunk(worldTilePosition, chunkSize); if (chunks.TryGetValue(chunkPosition, out TileChunk chunk)) { chunk.SetMeshDirty(); } else { TileChunk newChunk = GenerateChunk(chunkPosition); newChunk.SetMeshDirty(); } if (tileInformations[id].isSolid) { fluidQueue.Enqueue(new Tuple <int, float>(index, 0.0f)); } LightEmission beforeEmission = tileInformations[tiles[index]].emission; tiles[index] = id; SetEmission(worldTilePosition, tileInformations[id].emission); CheckTileToUpdateLight(worldTilePosition, id, beforeEmission); return(true); }
private IEnumerator UpdateRoutine() { while (true) { // No next tile, take the first tile from the queue if (m_NextTileChunk == null) { m_NextTileChunk = m_TileChunksQueue.Dequeue(); } // Check position player if (((m_NextTileChunk.transform.position.z) + 13.5f) < m_Player.transform.position.z) { Destroy(m_NextTileChunk.gameObject); AddTile(); m_NextTileChunk = null; } // Get tile at the beginning of the queue TileChunk tc = m_TileChunksQueue.Peek(); // ?? m_stx = (int)m_Player.transform.position.x; m_stx = (m_stx + 3) / 3; m_stz = (int)m_Player.transform.position.z; m_stz = (m_stz + 3) / 3; m_stz = m_stz % 3; m_stz = 2 - m_stz; /*if (tc.Collision(m_stx, m_stz) != TileControl.Tipos.Libre) * { * Debug.Log("!!!!!"); * }*/ yield return(new WaitForEndOfFrame()); } }
public void RpcSetTileAt(Vector2 position, int id) { TileChunk cPrefab = tMass.tileChunkPrefab.GetComponent <TileChunk>(); Debug.Log("Yup"); int x = (int)position.x; int y = (int)position.y; int chunkX = (int)(x / cPrefab.chunkSizeX); int chunkY = (int)(y / cPrefab.chunkSizeY); int tileX = (int)(x - chunkX * cPrefab.chunkSizeX); int tileY = (int)(y - chunkY * cPrefab.chunkSizeY); tMass.tileChunks[chunkX, chunkY].GetComponent <TileChunk>().tiles[tileX, tileY].tileID = id; tMass.BuildChunk(new Vector2(chunkX, chunkY), false); if (tileX == 0) { tMass.BuildChunk(new Vector2(chunkX - 1, chunkY), false); } if (tileX == cPrefab.chunkSizeX - 1) { tMass.BuildChunk(new Vector2(chunkX + 1, chunkY), false); } if (tileY == 0) { tMass.BuildChunk(new Vector2(chunkX, chunkY - 1), false); } if (tileY == cPrefab.chunkSizeY - 1) { tMass.BuildChunk(new Vector2(chunkX, chunkY + 1), false); } }
public virtual TileData TileData(TileChunk tileChunk, int x, int y, TileData _tileData) { _tileData.RenderDataforCol = true; if (tileChunk.GetTile(x + 1, y).IsSolid() && tileChunk.GetTile(x - 1, y).IsSolid() && tileChunk.GetTile(x, y - 1).IsSolid() && tileChunk.GetTile(x, y + 1).IsSolid()) { _tileData.RenderDataforCol = false; } _tileData.AddVertex(new Vector3(x - 0.5f, y - 0.5f, 0)); _tileData.AddVertex(new Vector3(x - 0.5f, y + 0.5f, 0)); _tileData.AddVertex(new Vector3(x + 0.5f, y + 0.5f, 0)); _tileData.AddVertex(new Vector3(x + 0.5f, y - 0.5f, 0)); _tileData.AddUVs(TileUVs(tileChunk, x, y)); _tileData.AddQuadTriangles(); return(_tileData); }
public void CreateChunkTileGameObjects(TileChunk chunk) { GameObject cgo = CreateGameObject("chunk_" + chunk.x + "_" + chunk.y, chunk.world_x, chunk.world_y, true); cgo.transform.Translate(-0.5f, -0.5f, 0); Chunks_GO_Map.Add(chunk, cgo); cgo.GetComponent <SpriteRenderer>().sprite = chunk.sprite; for (int xt = 0; xt < TileChunk.CHUNK_WIDTH; xt += 1) { for (int yt = 0; yt < TileChunk.CHUNK_HEIGHT; yt += 1) { Tile t = chunk.tiles[xt, yt]; //GameObject go = CreateGameObject("tile_" + t.world_x + "_" + t.world_y, t.world_x, t.world_y, true); //go.GetComponent<SpriteRenderer>().sortingLayerName = "Ground"; //Tiles_GO_Map.Add(t, go); t.cbRegisterOnChanged(SetTileSprite); t.SetType(t.type); } } }
public override TileTextureData TexturePosition(TileChunk tileChunk, int x, int y) { TileTextureData tileTextureData = new TileTextureData(); if (count < 60) { tileTextureData.x = 0; tileTextureData.y = 3; } else { tileTextureData.x = 0; tileTextureData.y = 0; } if (count >= 120) { count = 0; } count++; return(tileTextureData); }
public override TileData UpdateUV(TileChunk Chunk, int x, int y, TileData _tileData) { return _tileData; }
public override TileData TileData(TileChunk tileChunk, int x, int y, TileData _tileData) { _tileData.RenderDataforCol = false; return _tileData; }
public virtual TileData UpdateUV(TileChunk Chunk, int x, int y, TileData _tileData) { _tileData.AddUVs(TileUVs(Chunk, x, y)); return(_tileData); }
public virtual void Tick(TileData tileData, TileChunk chunk, int x, int y, float deltaTime) { }
public void OnChunkCreated(TileChunk chunk) { CreateChunkTileGameObjects(chunk); }
public override TileData UpdateUV(TileChunk Chunk, int x, int y, TileData _tileData) { return(_tileData); }
public override TileData TileData(TileChunk tileChunk, int x, int y, TileData _tileData) { _tileData.RenderDataforCol = false; return(_tileData); }
public void TileChunkGenerated(ChunkCoords coords, TileChunk chunk) { // TODO: Load tile entity renderables }
//Setters: public void SetPaused(bool paused) { if (!paused) { mIsPaused = false; Destroy(transform.GetChild(3).gameObject); foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("Player")) { Player playerScript = gameObject.GetComponent <Player>(); playerScript.UnPause(); } GameObject.Find("GlobalData").GetComponent <GlobalData>().UnPause(); if (GameObject.Find("Pawser") != null) { GameObject.Find("Pawser").GetComponent <Pawser>().UnPause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("enemy1")) { DustBunny dustBunnyScript = gameObject.GetComponent <DustBunny>(); dustBunnyScript.UnPause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("spider")) { Spider spiderScriptComp = gameObject.GetComponent <Spider>(); spiderScriptComp.UnPause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("bullet")) { Bullet bulletComp = gameObject.GetComponent <Bullet>(); bulletComp.UnPause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("knifeHandler")) { KnifeHandler knifeHandlerComp = gameObject.GetComponent <KnifeHandler>(); knifeHandlerComp.UnPause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("knife")) { Knife knifeComp = gameObject.GetComponent <Knife>(); knifeComp.UnPause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("tilechunk")) { TileChunk tileChunkComp = gameObject.GetComponent <TileChunk>(); tileChunkComp.UnPause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("shockwaveSpawner")) { ShockwaveSpawner curComp = gameObject.GetComponent <ShockwaveSpawner>(); curComp.UnPause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("hairball")) { Hairball curComp = gameObject.GetComponent <Hairball>(); curComp.UnPause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("debris")) { TileDebris tileDebrisComp = gameObject.GetComponent <TileDebris>(); tileDebrisComp.UnPause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("bee")) { Bee beeComp = gameObject.GetComponent <Bee>(); beeComp.UnPause(); } if (Camera.main.GetComponent <WallCamera>()) { Camera.main.GetComponent <WallCamera>().UnPause(); } } else { mIsPaused = true; GameObject pauseMenuObj = GameObject.Instantiate(mPauseMenuPrefab, new Vector3( 0.0f, 0.0f, -10.0f), Quaternion.identity); pauseMenuObj.transform.SetParent(transform); foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("Player")) { Player playerScript = gameObject.GetComponent <Player>(); playerScript.Pause(); } GameObject.Find("GlobalData").GetComponent <GlobalData>().Pause(); if (GameObject.Find("Pawser") != null) { GameObject.Find("Pawser").GetComponent <Pawser>().Pause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("enemy1")) { DustBunny dustBunnyScript = gameObject.GetComponent <DustBunny>(); dustBunnyScript.Pause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("spider")) { Spider spiderScriptComp = gameObject.GetComponent <Spider>(); spiderScriptComp.Pause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("bullet")) { Bullet bulletComp = gameObject.GetComponent <Bullet>(); bulletComp.Pause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("knifeHandler")) { KnifeHandler knifeHandlerComp = gameObject.GetComponent <KnifeHandler>(); knifeHandlerComp.Pause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("knife")) { Knife knifeComp = gameObject.GetComponent <Knife>(); knifeComp.Pause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("tilechunk")) { TileChunk tileChunkComp = gameObject.GetComponent <TileChunk>(); tileChunkComp.Pause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("shockwaveSpawner")) { ShockwaveSpawner curComp = gameObject.GetComponent <ShockwaveSpawner>(); curComp.Pause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("hairball")) { Hairball curComp = gameObject.GetComponent <Hairball>(); curComp.Pause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("debris")) { TileDebris tileDebrisComp = gameObject.GetComponent <TileDebris>(); tileDebrisComp.Pause(); } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("bee")) { Bee beeComp = gameObject.GetComponent <Bee>(); beeComp.Pause(); } if (Camera.main.GetComponent <WallCamera>()) { Camera.main.GetComponent <WallCamera>().Pause(); } } }
private void UpdateChunkVertices(TileChunk chunk) { chunk.UpdateVertices(VertexGenerator); }
public RecursiveTileMap(byte level, int submapSize) { Level = level; _submapSize = submapSize; _submap = new TileChunk <IRecursiveTileMap <T> >(submapSize); }
public void AddChunk(Int2 position, TileChunk chunk) => chunks.Add(position, chunk);