public void TestConstructors() { TCODRandom a = new TCODRandom(); TCODRandom c = new TCODRandom(42); a.Dispose(); c.Dispose(); }
public void SplitRecursive(TCODRandom randomizer, int nb, int minHSize, int minVSize, float maxHRatio, float maxVRatio) { if (randomizer == null) { TCOD_bsp_split_recursive(new IntPtr(m_data), IntPtr.Zero, nb, minHSize, minVSize, maxHRatio, maxVRatio); } else { TCOD_bsp_split_recursive(new IntPtr(m_data), randomizer.m_instance, nb, minHSize, minVSize, maxHRatio, maxVRatio); } }
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> /// TCODNameGenerator, and it's unmanaged cousin, both have global scope /// </summary> static TCODNameGenerator() { m_random = new TCODRandom(); }
/// <summary> /// Create noise object. /// </summary> /// <param name="dimensions">Number of dimensions</param> /// <param name="hurst">Hurst</param> /// <param name="lacunarity">Lacunarity</param> /// <param name="random">Random Generator</param> public TCODNoise(int dimensions, double hurst, double lacunarity, TCODRandom random) { m_dimensions = dimensions; m_instance = TCOD_noise_new(dimensions, (float)hurst, (float)lacunarity, random.m_instance); }
/// <summary> /// Create noise object. /// </summary> /// <param name="dimensions">Number of dimensions</param> /// <param name="random">Random Generator</param> public TCODNoise(int dimensions, TCODRandom random) { m_dimensions = dimensions; m_instance = TCOD_noise_new(dimensions, NoiseDefaultHurst, NoiseDefaultLacunarity, random.m_instance); }
public void Init() { r = new TCODRandom(); }
public void SplitRecursive(TCODRandom randomizer, int nb, int minHSize, int minVSize, float maxHRatio, float maxVRatio) { if (randomizer == null) TCOD_bsp_split_recursive(new IntPtr(m_data), IntPtr.Zero, nb, minHSize, minVSize, maxHRatio, maxVRatio); else TCOD_bsp_split_recursive(new IntPtr(m_data), randomizer.m_instance, nb, minHSize, minVSize, maxHRatio, maxVRatio); }
// the class building the dungeon from the bsp nodes bool traverse_node(TCODBSP node) { TCODRandom rnd = new TCODRandom(); if (node.IsLeaf()) { // calculate the room size int minx = node.x + 1; int maxx = node.x + node.w - 1; int miny = node.y + 1; int maxy = node.y + node.h - 1; int x, y; if (!roomWalls) { if (minx > 1) minx--; if (miny > 1) miny--; } if (maxx == SAMPLE_SCREEN_WIDTH - 1) maxx--; if (maxy == SAMPLE_SCREEN_HEIGHT - 1) maxy--; if (randomRoom) { minx = rnd.GetRandomInt(minx, maxx - minRoomSize + 1); miny = rnd.GetRandomInt(miny, maxy - minRoomSize + 1); maxx = rnd.GetRandomInt(minx + minRoomSize - 1, maxx); maxy = rnd.GetRandomInt(miny + minRoomSize - 1, maxy); } // resize the node to fit the room // printf("node %dx%d %dx%d => room %dx%d %dx%d\n",node->x,node->y,node->w,node->h,minx,miny,maxx-minx+1,maxy-miny+1); node.x = minx; node.y = miny; node.w = maxx - minx + 1; node.h = maxy - miny + 1; // dig the room for (x = minx; x <= maxx; x++) { for (y = miny; y <= maxy; y++) { bsp_map[x,y] = ' '; } } } else { // printf("lvl %d %dx%d %dx%d\n",node->level, node->x,node->y,node->w,node->h); // resize the node to fit its sons TCODBSP left = node.GetLeft(); TCODBSP right = node.GetRight(); node.x = System.Math.Min(left.x, right.x); node.y = System.Math.Min(left.y, right.y); node.w = System.Math.Max(left.x + left.w, right.x + right.w) - node.x; node.h = System.Math.Max(left.y + left.h, right.y + right.h) - node.y; // create a corridor between the two lower nodes if (node.horizontal) { // vertical corridor if (left.x + left.w - 1 < right.x || right.x + right.w - 1 < left.x) { // no overlapping zone. we need a Z shaped corridor int x1 = rnd.GetRandomInt(left.x, left.x + left.w - 1); int x2 = rnd.GetRandomInt(right.x, right.x + right.w - 1); int y = rnd.GetRandomInt(left.y + left.h, right.y); vline_up(bsp_map, x1, y - 1); hline(bsp_map, x1, y, x2); vline_down(bsp_map, x2, y + 1); } else { // straight vertical corridor int minx = System.Math.Max(left.x, right.x); int maxx = System.Math.Min(left.x + left.w - 1, right.x + right.w - 1); int x = rnd.GetRandomInt(minx, maxx); vline_down(bsp_map, x, right.y); vline_up(bsp_map, x, right.y - 1); } } else { // horizontal corridor if (left.y + left.h - 1 < right.y || right.y + right.h - 1 < left.y) { // no overlapping zone. we need a Z shaped corridor int y1 = rnd.GetRandomInt(left.y, left.y + left.h - 1); int y2 = rnd.GetRandomInt(right.y, right.y + right.h - 1); int x = rnd.GetRandomInt(left.x + left.w, right.x); hline_left(bsp_map, x - 1, y1); vline(bsp_map, x, y1, y2); hline_right(bsp_map, x + 1, y2); } else { // straight horizontal corridor int miny = System.Math.Max(left.y, right.y); int maxy = System.Math.Min(left.y + left.h - 1, right.y + right.h - 1); int y = rnd.GetRandomInt(miny, maxy); hline_left(bsp_map, right.x - 1, y); hline_right(bsp_map, right.x, y); } } } return true; }
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); }