public static IEnumerable <HighlitedM> GetHighlitedMs(float x, float y, int UTerrain, ProceduralTiles[] terrains, float RockFound) { var HighlitedMs = new HighlitedM[9]; x = (int)x >> 4; y = (int)y >> 4; int HighlitedMIndex = 0; for (int iX = -1; iX < 2; iX++) { for (int iY = -1; iY < 2; iY++) { var terrain = terrains[RandomTile.Range(x + iX, y + iY, UTerrain, terrains.Length)]; float mass = RandomTile.Percent(x + iX, y + iY, UTerrain) * 8 + 2; HighlitedMs[HighlitedMIndex++] = new HighlitedM() { Terrain = terrain, Location = new Vector2((int)(x + iX) << 4, (int)(y + iY) << 4) }; } } return(HighlitedMs); }
public static HighlitedM near(IEnumerable <HighlitedM> HighlitedMs, Vector2 location, int UTerrain) { HighlitedM HighTileSel = null; float near = float.MaxValue; foreach (var HighlitedM in HighlitedMs) { float rand = RandomTile.Percent( (int)(HighlitedM.Location.x + location.x), (int)(HighlitedM.Location.y + location.y), UTerrain) * 8; float Away = Vector2.Distance(location, HighlitedM.Location); Away -= rand; if (Away < near) { near = Away; HighTileSel = HighlitedM; } } return(HighTileSel); }
// Re-drawing the map taking TankP as the referance void DrawTile() { transform.position = new Vector3((int)TankP.position.x, (int)TankP.position.y, TankP.position.z); _HighlitedMs = HighlitedM.GetHighlitedMs(transform.position.x, transform.position.y, UTerrain, ProceduralTiless, 1); var Tofset = new Vector3( transform.position.x - HTiles / 2, transform.position.y - VTiles / 2, 0); for (int x = 0; x < HTiles; x++) { for (int y = 0; y < VTiles; y++) { var spriteRenderer = CommitR[x, y]; var terrain = SelectTerrain( Tofset.x + x, Tofset.y + y); spriteRenderer.sprite = terrain.TileFetch(Tofset.x + x, Tofset.y + y, UTerrain); } } }
public ProceduralTiles SelectTerrain(float x, float y) { return(HighlitedM.near(_HighlitedMs, new Vector2(x, y), UTerrain).Terrain); }