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); }
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)) { } } } } }
/// <summary> /// Initializes a new WorldMap object, which provides cell retrieval and terrain generation functions. /// </summary> /// <param name="seed">The map seed.</param> /// <param name="dbconn">The connection to the object database.</param> /// <param name="parameters">The parameters for terrain generation.</param> public WorldMap(uint seed, SQLiteConnection dbconn, int[] parameters) { //Initialization this.dbconn = dbconn; this.seed = seed; rand = new TCODRandom(seed, TCODRandomType.ComplementaryMultiplyWithCarry); noise = new TCODNoise(2, rand); CELL_WIDTH = parameters[0]; CELL_HEIGHT = parameters[1]; CELL_DEPTH = parameters[2]; CELLS_X = parameters[3]; CELLS_Y = parameters[4]; CELLS_Z = parameters[5]; GLOBAL_WIDTH = CELLS_X * CELL_WIDTH; GLOBAL_HEIGHT = CELLS_Y * CELL_HEIGHT; GLOBAL_DEPTH = CELLS_Z * CELL_DEPTH; GROUND_LEVEL = parameters[6]; //Create Cells cells = new Cell[CELLS_X, CELLS_Y, CELLS_Z]; int id = 0; for (int x = 0; x < CELLS_X; x++) { for (int y = 0; y < CELLS_Y; y++) { for (int z = 0; z < CELLS_Z; z++) { cells[x, y, z] = new Cell(x * CELL_WIDTH, y * CELL_HEIGHT, z * CELL_DEPTH, id, this); id++; } } } //Create Tiles makeDefaultTileSetup(); loadTileDict(); makeTestDiffs(); }
void render_fov(bool first, TCODKey key) { if (map == null) { // initialize the map for the fov toolkit map = new TCODMap(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.setProperties(x, y, true, true);// ground else if (smap[y][x] == '=') map.setProperties(x, y, true, false); // window } } // 1d noise used for the torch flickering map_noise = new TCODNoise(1); } if (first) { TCODSystem.setFps(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.setForegroundColor(TCODColor.white); string prompt = "IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[(int)algonum]; sampleConsole.print(1, 1, prompt); sampleConsole.setForegroundColor(TCODColor.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.computeFov(px, py, torch ? (int)TORCH_RADIUS : 0, light_walls, 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.isInFov(x, y); bool wall = (smap[y][x] == '#'); if (!visible) { sampleConsole.setCharBackground(x, y, (wall ? darkWall : darkGround), TCODBackgroundFlag.Set); } else { if (!torch) { sampleConsole.setCharBackground(x, y, wall ? lightWall : lightGround, TCODBackgroundFlag.Set); } else { // torch flickering fx TCODColor baseColor = wall ? darkWall : darkGround; TCODColor 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 = new TCODColor((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, TCODBackgroundFlag.Set); } } } } if (key.Character == 'I' || key.Character == 'i') { // player move north if (smap[py - 1][px] == ' ') { sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None); py--; sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None); recomputeFov = true; } } else if (key.Character == 'K' || key.Character == 'k') { // player move south if (smap[py + 1][px] == ' ') { sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None); py++; sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None); recomputeFov = true; } } else if (key.Character == 'J' || key.Character == 'j') { // player move west if (smap[py][px - 1] == ' ') { sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None); px--; sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None); recomputeFov = true; } } else if (key.Character == 'L' || key.Character == 'l') { // player move east if (smap[py][px + 1] == ' ') { sampleConsole.putChar(px, py, ' ', TCODBackgroundFlag.None); px++; sampleConsole.putChar(px, py, '@', TCODBackgroundFlag.None); recomputeFov = true; } } else if (key.Character == 'T' || key.Character == 't') { // enable/disable the torch fx torch = !torch; sampleConsole.setForegroundColor(TCODColor.white); string prompt = "IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[(int)algonum]; sampleConsole.print(1, 1, prompt); sampleConsole.setForegroundColor(TCODColor.black); } else if (key.Character == 'W' || key.Character == 'W') { light_walls = !light_walls; sampleConsole.setForegroundColor(TCODColor.white); string prompt = "IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[(int)algonum]; sampleConsole.print(1, 1, prompt); sampleConsole.setForegroundColor(TCODColor.black); recomputeFov = true; } else if (key.Character == '+' || key.Character == '-') { algonum += key.Character == '+' ? 1 : -1; if (algonum >= TCODFOVTypes.RestrictiveFov) algonum = TCODFOVTypes.RestrictiveFov; else if (algonum < 0) algonum = TCODFOVTypes.BasicFov; sampleConsole.setForegroundColor(TCODColor.white); string prompt = "IJKL : move around\nT : torch fx " + (torch ? "off" : "on ") + " : light walls " + (light_walls ? "off" : "on ") + "\n+-: algo " + algo_names[(int)algonum]; sampleConsole.print(1, 1, prompt); sampleConsole.setForegroundColor(TCODColor.black); recomputeFov = true; } }
private void setupStaticData() { random = new TCODRandom(); render_cols = new TCODColor[4]; render_cols[0] = new TCODColor(50, 40, 150); render_cols[1] = new TCODColor(240, 85, 5); render_cols[2] = new TCODColor(50, 35, 240); render_cols[3] = new TCODColor(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 = new TCODConsole(SAMPLE_SCREEN_WIDTH / 2, SAMPLE_SCREEN_HEIGHT / 2); off_screenshot = new TCODConsole(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT); line_bk = new TCODConsole(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT); noise = new TCODNoise(2, noise_hurst, noise_lacunarity); }
void render_noise(bool first, TCODKey key) { if (first) { TCODSystem.setFps(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; TCODColor col = new TCODColor(); 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 = new TCODColor((byte)(c / 2), (byte)(c / 2), c); sampleConsole.setCharBackground(x, y, col, TCODBackgroundFlag.Set); } } /* draw a transparent rectangle */ sampleConsole.setBackgroundColor(TCODColor.grey); sampleConsole.rect(2, 2, (noise_func <= noiseFunctions.Wavelet ? 16 : 24), (noise_func <= noiseFunctions.Wavelet ? 4 : 7), false, TCODBackgroundFlag.Multiply); /* draw the text */ for (noiseFunctions curfunc = noiseFunctions.Perlin; curfunc <= noiseFunctions.WaveletTurbulence; curfunc++) { if (curfunc == noise_func) { sampleConsole.setForegroundColor(TCODColor.white); sampleConsole.setBackgroundColor(TCODColor.blue); sampleConsole.print(2, 2 + (int)(curfunc), noise_funcName[(int)curfunc]); } else { sampleConsole.setForegroundColor(TCODColor.grey); sampleConsole.print(2, 2 + (int)(curfunc), noise_funcName[(int)curfunc]); } } /* draw parameters */ sampleConsole.setForegroundColor(TCODColor.white); sampleConsole.print(2, 11, "Y/H : zome (" + noise_zoom.ToString("0.0") + ")"); if (noise_func > noiseFunctions.Wavelet) { sampleConsole.print(2, 12, "E/D : hurst (" + noise_hurst.ToString("0.0") + ")"); sampleConsole.print(2, 13, "R/F : lacunarity (" + noise_lacunarity.ToString("0.0") + ")"); sampleConsole.print(2, 14, "T/G : octaves (" + noise_octaves.ToString("0.0") + ")"); } /* handle keypress */ if (key.KeyCode == TCODKeyCode.NoKey) 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; } }