public void ConstructorTest() { using (TCODRandom rand = new TCODRandom()) { using (TCODNoise a = new TCODNoise(1, rand)) { using (TCODNoise b = new TCODNoise(2, .5, 2.0)) { using (TCODNoise c = new TCODNoise(3, .2, .3, rand)) { } } } } }
public void Init() { perlin1d = new TCODNoise(1); perlin2d = new TCODNoise(2); perlin3d = new TCODNoise(3); perlin4d = new TCODNoise(4); brownian1d = new TCODNoise(1); brownian2d = new TCODNoise(2); brownian3d = new TCODNoise(3); brownian4d = new TCODNoise(4); turbulence1d = new TCODNoise(1); turbulence2d = new TCODNoise(2); turbulence3d = new TCODNoise(3); turbulence4d = new TCODNoise(4); }
void render_fov(bool first, KeyPress key) { if (map == null) { // initialize the map for the fov toolkit map = new TCODFov(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT); for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) { for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { if (smap[y][x] == ' ') map.SetCell(x, y, true, true);// ground else if (smap[y][x] == '=') map.SetCell(x, y, true, false); // window } } // 1d noise used for the torch flickering map_noise = new TCODNoise(1); } if (first) { TCODSystem.FPS = 30; // fps limited to 30 // we draw the foreground only the first time. // during the player movement, only the @ is redrawn. // the rest impacts only the background color // draw the help text & player @ sampleConsole.Clear(); sampleConsole.ForegroundColor = (ColorPresets.White); sampleConsole.PrintLine("IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[algonum], 1, 1, LineAlignment.Left); sampleConsole.ForegroundColor = (ColorPresets.Black); sampleConsole.PutChar(px, py, '@'); // draw windows for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) { for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { if (smap[y][x] == '=') { sampleConsole.PutChar(x, y, '='); } } } } if (recomputeFov) { // calculate the field of view from the player position recomputeFov = false; map.CalculateFOV(px, py, torch ? (int)TORCH_RADIUS : 0, light_walls, (FovAlgorithm)algonum); } // torch position & intensity variation float dx = 0.0f, dy = 0.0f, di = 0.0f; if (torch) { // slightly change the perlin noise parameter torchx += 0.2f; // randomize the light position between -1.5 and 1.5 float[] tdx = { torchx + 20.0f }; dx = map_noise.GetPerlinNoise(tdx) * 1.5f; tdx[0] += 30.0f; dy = map_noise.GetPerlinNoise(tdx) * 1.5f; // randomize the light intensity between -0.2 and 0.2 float[] torchxArray = { torchx }; di = 0.2f * map_noise.GetPerlinNoise(torchxArray); } // draw the dungeon for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) { for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { bool visible = map.CheckTileFOV(x, y); bool wall = (smap[y][x] == '#'); if (!visible) { sampleConsole.SetCharBackground(x, y, (wall ? darkWall : darkGround), Background.Set); } else { if (!torch) { sampleConsole.SetCharBackground(x, y, wall ? lightWall : lightGround, Background.Set); } else { // torch flickering fx Color baseColor = wall ? darkWall : darkGround; Color light = wall ? lightWall : lightGround; // cell distance to torch (squared) float r = (float)((x - px + dx) * (x - px + dx) + (y - py + dy) * (y - py + dy)); if (r < SQUARED_TORCH_RADIUS) { // l = 1.0 at player position, 0.0 at a radius of 10 cells float l = (SQUARED_TORCH_RADIUS - r) / SQUARED_TORCH_RADIUS + di; // clamp between 0 and 1 if (l < 0.0f) l = 0.0f; else if (l > 1.0f) l = 1.0f; // interpolate the color baseColor = Color.FromRGB((byte)(baseColor.Red + (light.Red - baseColor.Red) * l), (byte)(baseColor.Green + (light.Green - baseColor.Green) * l), (byte)(baseColor.Blue + (light.Blue - baseColor.Blue) * l)); } sampleConsole.SetCharBackground(x, y, baseColor, Background.Set); } } } } if (key.Character == 'I' || key.Character == 'i') { // player move north if (smap[py - 1][px] == ' ') { sampleConsole.PutChar(px, py, ' ', Background.None); py--; sampleConsole.PutChar(px, py, '@', Background.None); recomputeFov = true; } } else if (key.Character == 'K' || key.Character == 'k') { // player move south if (smap[py + 1][px] == ' ') { sampleConsole.PutChar(px, py, ' ', Background.None); py++; sampleConsole.PutChar(px, py, '@', Background.None); recomputeFov = true; } } else if (key.Character == 'J' || key.Character == 'j') { // player move west if (smap[py][px - 1] == ' ') { sampleConsole.PutChar(px, py, ' ', Background.None); px--; sampleConsole.PutChar(px, py, '@', Background.None); recomputeFov = true; } } else if (key.Character == 'L' || key.Character == 'l') { // player move east if (smap[py][px + 1] == ' ') { sampleConsole.PutChar(px, py, ' ', Background.None); px++; sampleConsole.PutChar(px, py, '@', Background.None); recomputeFov = true; } } else if (key.Character == 'T' || key.Character == 't') { // enable/disable the torch fx torch = !torch; sampleConsole.ForegroundColor = (ColorPresets.White); sampleConsole.PrintLine("IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[algonum], 1, 1, LineAlignment.Left); sampleConsole.ForegroundColor = (ColorPresets.Black); } else if (key.Character == 'W' || key.Character == 'W') { light_walls = !light_walls; sampleConsole.ForegroundColor = (ColorPresets.White); sampleConsole.PrintLine("IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[algonum], 1, 1, LineAlignment.Left); sampleConsole.ForegroundColor = (ColorPresets.Black); recomputeFov = true; } else if (key.Character == '+' || key.Character == '-') { algonum += key.Character == '+' ? 1 : -1; if (algonum >= (int)FovAlgorithm.NB_Fov_Algorithms) algonum = (int)FovAlgorithm.Restrictive; else if (algonum < 0) algonum = 0; sampleConsole.ForegroundColor = (ColorPresets.White); sampleConsole.PrintLine("IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[algonum], 1, 1, LineAlignment.Left); sampleConsole.ForegroundColor = (ColorPresets.Black); recomputeFov = true; } }
void render_noise(bool first, KeyPress key) { if (first) { TCODSystem.FPS = 30; /* limited to 30 fps */ } sampleConsole.Clear(); /* texture animation */ noise_dx += 0.01f; noise_dy += 0.01f; /* render the 2d noise function */ for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) { for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { float[] f = new float[2]; float value = 0.0f; byte c; Color col = new Color(); f[0] = noise_zoom * x / SAMPLE_SCREEN_WIDTH + noise_dx; f[1] = noise_zoom * y / SAMPLE_SCREEN_HEIGHT + noise_dy; switch (noise_func) { case noiseFunctions.Perlin: value = noise.GetPerlinNoise(f); break; case noiseFunctions.PerlinFBM: value = noise.GetPerlinBrownianMotion(f, noise_octaves); break; case noiseFunctions.PerlinTurbulence: value = noise.GetPerlinTurbulence(f, noise_octaves); break; case noiseFunctions.Simplex: value = noise.GetSimplexNoise(f); break; case noiseFunctions.SimplexFBM: value = noise.GetSimplexBrownianMotion(f, noise_octaves); break; case noiseFunctions.SimplexTurbulence: value = noise.GetSimplexTurbulence(f, noise_octaves); break; case noiseFunctions.Wavelet: value = noise.GetWaveletNoise(f); break; case noiseFunctions.WaveletFBM: value = noise.GetWaveletBrownianMotion(f, noise_octaves); break; case noiseFunctions.WaveletTurbulence: value = noise.GetWaveletTurbulence(f, noise_octaves); break; } c = (byte)((value + 1.0f) / 2.0f * 255); /* use a bluish color */ col = Color.FromRGB((byte)(c / 2), (byte)(c / 2), c); sampleConsole.SetCharBackground(x, y, col, Background.Set); } } /* draw a transparent rectangle */ sampleConsole.BackgroundColor = ColorPresets.Gray; sampleConsole.DrawRect(2, 2, (noise_func <= noiseFunctions.Wavelet ? 16 : 24), (noise_func <= noiseFunctions.Wavelet ? 4 : 7), false, new Background(BackgroundFlag.Multiply)); /* draw the text */ for (noiseFunctions curfunc = noiseFunctions.Perlin; curfunc <= noiseFunctions.WaveletTurbulence; curfunc++) { if (curfunc == noise_func) { sampleConsole.ForegroundColor = ColorPresets.White; sampleConsole.BackgroundColor = ColorPresets.Blue; sampleConsole.PrintLine(noise_funcName[(int)curfunc], 2, 2 + (int)(curfunc), Background.Set, LineAlignment.Left); } else { sampleConsole.ForegroundColor = ColorPresets.Gray; sampleConsole.PrintLine(noise_funcName[(int)curfunc], 2, 2 + (int)(curfunc), Background.None, LineAlignment.Left); } } /* draw parameters */ sampleConsole.ForegroundColor = ColorPresets.White; sampleConsole.PrintLine("Y/H : zome (" + noise_zoom.ToString("0.0") + ")", 2, 11, LineAlignment.Left); if (noise_func > noiseFunctions.Wavelet) { sampleConsole.PrintLine("E/D : hurst (" + noise_hurst.ToString("0.0") + ")", 2, 12, LineAlignment.Left); sampleConsole.PrintLine("R/F : lacunarity (" + noise_lacunarity.ToString("0.0") + ")", 2, 13, LineAlignment.Left); sampleConsole.PrintLine("T/G : octaves (" + noise_octaves.ToString("0.0") + ")", 2, 14, LineAlignment.Left); } /* handle keypress */ if (key.KeyCode == KeyCode.TCODK_NONE) return; if (key.Character >= '1' && key.Character <= '9') { noise_func = (noiseFunctions)(key.Character - '1'); } else if (key.Character == 'E' || key.Character == 'e') { /* increase hurst */ noise_hurst += 0.1f; noise.Dispose(); noise = new TCODNoise(2, noise_hurst, noise_lacunarity); } else if (key.Character == 'D' || key.Character == 'd') { /* decrease hurst */ noise_hurst -= 0.1f; noise.Dispose(); noise = new TCODNoise(2, noise_hurst, noise_lacunarity); } else if (key.Character == 'R' || key.Character == 'r') { /* increase lacunarity */ noise_lacunarity += 0.5f; noise.Dispose(); noise = new TCODNoise(2, noise_hurst, noise_lacunarity); } else if (key.Character == 'F' || key.Character == 'f') { /* decrease lacunarity */ noise_lacunarity -= 0.5f; noise.Dispose(); noise = new TCODNoise(2, noise_hurst, noise_lacunarity); } else if (key.Character == 'T' || key.Character == 't') { /* increase octaves */ noise_octaves += 0.5f; } else if (key.Character == 'G' || key.Character == 'g') { /* decrease octaves */ noise_octaves -= 0.5f; } else if (key.Character == 'Y' || key.Character == 'y') { /* increase zoom */ noise_zoom += 0.2f; } else if (key.Character == 'H' || key.Character == 'h') { /* decrease zoom */ noise_zoom -= 0.2f; } }
private void setupStaticData() { random = new TCODRandom(); render_cols = new Color[4]; render_cols[0] = Color.FromRGB(50, 40, 150); render_cols[1] = Color.FromRGB(240, 85, 5); render_cols[2] = Color.FromRGB(50, 35, 240); render_cols[3] = Color.FromRGB(10, 200, 130); render_dirr = new int[] { 1, -1, 1, 1 }; render_dirg = new int[] { 1, -1, -1, 1 }; render_dirb = new int[] { 1, 1, 1, -1 }; off_secondary = RootConsole.GetNewConsole(SAMPLE_SCREEN_WIDTH / 2, SAMPLE_SCREEN_HEIGHT / 2); off_screenshot = RootConsole.GetNewConsole(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT); line_bk = RootConsole.GetNewConsole(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT); noise = new TCODNoise(2, noise_hurst, noise_lacunarity); }