-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
124 lines (108 loc) · 3.53 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System.Drawing;
using Colorful;
using Console = Colorful.Console;
namespace ProcGenTiles
{
public class Program
{
static ColorEnumerator colors = new ColorEnumerator(
new List<Color> {
Color.Red,
Color.Orange,
Color.Yellow,
Color.Green,
Color.Blue,
Color.White,
Color.Brown,
Color.Purple
}); //Holds nine colors for use in coloring regions or such
public static void Main()
{
int Height = 10;
int Width = 25;
float noiseScale = 0.5f;
float noiseFrequency = 0.25f;
int seed = 10;
Map map = new Map(Height, Width);
Pathfinding path = new Pathfinding(map);
//Terrain definitions and such
Dictionary<Range, TerrainInfo> elevationCharacters = new Dictionary<Range, TerrainInfo>();
TerrainInfo deepWater = new TerrainInfo(Color.DarkBlue, '~', "Deep Water");
TerrainInfo shallowWater = new TerrainInfo(Color.LightBlue, '`', "Shallow Water");
TerrainInfo lowGround = new TerrainInfo(Color.LightGreen, '.', "Low Ground");
TerrainInfo mediumGround = new TerrainInfo(Color.Green, '_', "Medium Ground");
TerrainInfo highlands = new TerrainInfo(Color.DarkGray, '-', "Highland");
TerrainInfo mountains = new TerrainInfo(Color.Gray, '^', "Mountain");
//Add the definitions to the ranges
elevationCharacters.Add(new Range(-1f, -0.5f), deepWater); //If under 0.5 use this symbol
elevationCharacters.Add(new Range(-0.5f, 0), shallowWater);
elevationCharacters.Add(new Range(0, 0.3f), lowGround);
elevationCharacters.Add(new Range(0.3f, 0.6f), mediumGround);
elevationCharacters.Add(new Range(0.6f, 0.9f), highlands);
elevationCharacters.Add(new Range(0.9f, 1.1f), mountains); //Push the range up slightly higher so we don't miss tiles
//Init map and prep noise for terrain layer
FastNoiseLite noise = new FastNoiseLite();
noise.SetNoiseType(FastNoiseLite.NoiseType.Perlin);
noise.SetFrequency(noiseFrequency);
noise.SetSeed(seed);
//Loop through width and height and generate noise for terrain elevation
//And print to the console while we're here.
string layerName = "Elevation";
for (int i = 0; i < Height; i++)
{
for (int j = 0; j < Width; j++)
{
float value = noise.GetNoise(i * noiseScale, j * noiseScale);
map.Tiles[i, j].ValuesHere.Add(layerName, value);
TerrainInfo? found = null;
foreach (Range r in elevationCharacters.Keys)
{
if (r.InRange(value))
{
found = elevationCharacters[r];
break; //We found the character, exit the loop
}
}
//Console.Write(elevationIcon + "Noise: " + value);
Console.Write(found.DisplayCharacter, found.GlyphColor);
}
Console.WriteLine("");
}
Console.WriteLine("");
Console.WriteLine("----------");
Console.WriteLine("");
path.LandWaterFloodfill((0, 0)); //Just floodfill from the first tile and mark everything 0 or 1
PrintLayerValues(map, "Land");
Console.WriteLine("");
Console.WriteLine("----------");
Console.WriteLine("");
path.MarkAllRegions();
PrintLayerValues(map, "Region");
}
private static void PrintLayerValues(Map map, string layer)
{
for (int x = 0; x < map.Width; x++)
{
for (int y = 0; y < map.Height; y++)
{
Tile t = map.GetTile((x, y));
float value = t.ValuesHere[layer];
Color color;
if (layer == "Land")
{
if (value == 1)
color = Color.Green;
else
color = Color.Blue;
}
else
{
color = colors.Next((int)value);
}
Console.Write(value, color);
}
Console.WriteLine("");
}
}
}
}