Пример #1
0
        private static byte[][] createUndergroundMap(int w, int h, int depth)
        {
            LevelGen mnoise1 = new LevelGen(w, h, 16);
            LevelGen mnoise2 = new LevelGen(w, h, 16);
            LevelGen mnoise3 = new LevelGen(w, h, 16);

            LevelGen nnoise1 = new LevelGen(w, h, 16);
            LevelGen nnoise2 = new LevelGen(w, h, 16);
            LevelGen nnoise3 = new LevelGen(w, h, 16);

            LevelGen wnoise1 = new LevelGen(w, h, 16);
            LevelGen wnoise2 = new LevelGen(w, h, 16);
            LevelGen wnoise3 = new LevelGen(w, h, 16);

            LevelGen noise1 = new LevelGen(w, h, 32);
            LevelGen noise2 = new LevelGen(w, h, 32);

            byte[] map  = new byte[w * h];
            byte[] data = new byte[w * h];
            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    int i = x + y * w;

                    double val = Math.Abs(noise1.values[i] - noise2.values[i]) * 3 - 2;

                    double mval = Math.Abs(mnoise1.values[i] - mnoise2.values[i]);
                    mval = Math.Abs(mval - mnoise3.values[i]) * 3 - 2;

                    double nval = Math.Abs(nnoise1.values[i] - nnoise2.values[i]);
                    nval = Math.Abs(nval - nnoise3.values[i]) * 3 - 2;

                    double wval = Math.Abs(wnoise1.values[i] - wnoise2.values[i]);
                    wval = Math.Abs(nval - wnoise3.values[i]) * 3 - 2;

                    double xd = x / (w - 1.0) * 2 - 1;
                    double yd = y / (h - 1.0) * 2 - 1;
                    if (xd < 0)
                    {
                        xd = -xd;
                    }
                    if (yd < 0)
                    {
                        yd = -yd;
                    }
                    double dist = xd >= yd ? xd : yd;
                    dist = dist * dist * dist * dist;
                    dist = dist * dist * dist * dist;
                    val  = val + 1 - dist * 20;

                    if (val > -2 && wval < -2.0 + (depth) / 2 * 3)
                    {
                        if (depth > 2)
                        {
                            map[i] = Tile.lava.id;
                        }
                        else
                        {
                            map[i] = Tile.water.id;
                        }
                    }
                    else if (val > -2 && (mval < -1.7 || nval < -1.4))
                    {
                        map[i] = Tile.dirt.id;
                    }
                    else
                    {
                        map[i] = Tile.rock.id;
                    }
                }
            }

            {
                int r = 2;
                for (int i = 0; i < w * h / 400; i++)
                {
                    int x = random.nextInt(w);
                    int y = random.nextInt(h);
                    for (int j = 0; j < 30; j++)
                    {
                        int xx = x + random.nextInt(5) - random.nextInt(5);
                        int yy = y + random.nextInt(5) - random.nextInt(5);
                        if (xx >= r && yy >= r && xx < w - r && yy < h - r)
                        {
                            if (map[xx + yy * w] == Tile.rock.id)
                            {
                                map[xx + yy * w] = (byte)((Tile.ironOre.id & 0xff) + depth - 1);
                            }
                        }
                    }
                }
            }

            if (depth < 3)
            {
                int count = 0;
                for (int i = 0; i < w * h / 100; i++)
                {
                    int x = random.nextInt(w - 20) + 10;
                    int y = random.nextInt(h - 20) + 10;

                    var stop = false;
                    for (int yy = y - 1; yy <= y + 1; yy++)
                    {
                        for (int xx = x - 1; xx <= x + 1; xx++)
                        {
                            if (map[xx + yy * w] != Tile.rock.id)
                            {
                                stop = true;
                                break; //continue stairsLoop;
                            }
                        }
                        if (stop)
                        {
                            break;
                        }
                    }

                    if (stop)
                    {
                        continue;
                    }

                    map[x + y * w] = Tile.stairsDown.id;
                    count++;
                    if (count == 4)
                    {
                        break;
                    }
                }
            }

            return(new byte[][] { map, data });
        }
Пример #2
0
        private static byte[][] createSkyMap(int w, int h)
        {
            LevelGen noise1 = new LevelGen(w, h, 8);
            LevelGen noise2 = new LevelGen(w, h, 8);

            byte[] map  = new byte[w * h];
            byte[] data = new byte[w * h];
            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    int i = x + y * w;

                    double val = Math.Abs(noise1.values[i] - noise2.values[i]) * 3 - 2;

                    double xd = x / (w - 1.0) * 2 - 1;
                    double yd = y / (h - 1.0) * 2 - 1;
                    if (xd < 0)
                    {
                        xd = -xd;
                    }
                    if (yd < 0)
                    {
                        yd = -yd;
                    }
                    double dist = xd >= yd ? xd : yd;
                    dist = dist * dist * dist * dist;
                    dist = dist * dist * dist * dist;
                    val  = -val * 1 - 2.2;
                    val  = val + 1 - dist * 20;

                    if (val < -0.25)
                    {
                        map[i] = Tile.infiniteFall.id;
                    }
                    else
                    {
                        map[i] = Tile.cloud.id;
                    }
                }
            }

            for (int i = 0; i < w * h / 50; i++)
            {
                int x = random.nextInt(w - 2) + 1;
                int y = random.nextInt(h - 2) + 1;

                var stop = false;
                for (int yy = y - 1; yy <= y + 1; yy++)
                {
                    for (int xx = x - 1; xx <= x + 1; xx++)
                    {
                        if (map[xx + yy * w] != Tile.cloud.id)
                        {
                            stop = true; break;
                        }
                    }
                    if (stop)
                    {
                        break;
                    }
                }

                if (stop)
                {
                    continue;
                }

                map[x + y * w] = Tile.cloudCactus.id;
            }

            int count = 0;

            for (int i = 0; i < w * h; i++)
            {
                int x = random.nextInt(w - 2) + 1;
                int y = random.nextInt(h - 2) + 1;

                var stop = false;
                for (int yy = y - 1; yy <= y + 1; yy++)
                {
                    for (int xx = x - 1; xx <= x + 1; xx++)
                    {
                        if (map[xx + yy * w] != Tile.cloud.id)
                        {
                            stop = true;
                            break;
                        }
                    }
                    if (stop)
                    {
                        break;
                    }
                }
                if (stop)
                {
                    continue;
                }

                map[x + y * w] = Tile.stairsDown.id;
                count++;
                if (count == 2)
                {
                    break;
                }
            }

            return(new byte[][] { map, data });
        }
Пример #3
0
        private static byte[][] createTopMap(int w, int h)
        {
            LevelGen mnoise1 = new LevelGen(w, h, 16);
            LevelGen mnoise2 = new LevelGen(w, h, 16);
            LevelGen mnoise3 = new LevelGen(w, h, 16);

            LevelGen noise1 = new LevelGen(w, h, 32);
            LevelGen noise2 = new LevelGen(w, h, 32);

            byte[] map  = new byte[w * h];
            byte[] data = new byte[w * h];
            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    int i = x + y * w;

                    double val  = Math.Abs(noise1.values[i] - noise2.values[i]) * 3 - 2;
                    double mval = Math.Abs(mnoise1.values[i] - mnoise2.values[i]);
                    mval = Math.Abs(mval - mnoise3.values[i]) * 3 - 2;

                    double xd = x / (w - 1.0) * 2 - 1;
                    double yd = y / (h - 1.0) * 2 - 1;
                    if (xd < 0)
                    {
                        xd = -xd;
                    }
                    if (yd < 0)
                    {
                        yd = -yd;
                    }
                    double dist = xd >= yd ? xd : yd;
                    dist = dist * dist * dist * dist;
                    dist = dist * dist * dist * dist;
                    val  = val + 1 - dist * 20;

                    if (val < -0.5)
                    {
                        map[i] = Tile.water.id;
                    }
                    else if (val > 0.5 && mval < -1.5)
                    {
                        map[i] = Tile.rock.id;
                    }
                    else
                    {
                        map[i] = Tile.grass.id;
                    }
                }
            }

            for (int i = 0; i < w * h / 2800; i++)
            {
                int xs = random.nextInt(w);
                int ys = random.nextInt(h);
                for (int k = 0; k < 10; k++)
                {
                    int x = xs + random.nextInt(21) - 10;
                    int y = ys + random.nextInt(21) - 10;
                    for (int j = 0; j < 100; j++)
                    {
                        int xo = x + random.nextInt(5) - random.nextInt(5);
                        int yo = y + random.nextInt(5) - random.nextInt(5);
                        for (int yy = yo - 1; yy <= yo + 1; yy++)
                        {
                            for (int xx = xo - 1; xx <= xo + 1; xx++)
                            {
                                if (xx >= 0 && yy >= 0 && xx < w && yy < h)
                                {
                                    if (map[xx + yy * w] == Tile.grass.id)
                                    {
                                        map[xx + yy * w] = Tile.sand.id;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            /*
             * for (int i = 0; i < w * h / 2800; i++) { int xs = random.nextInt(w); int ys = random.nextInt(h); for (int k = 0; k < 10; k++) { int x = xs + random.nextInt(21) - 10; int y = ys + random.nextInt(21) - 10; for (int j = 0; j < 100; j++) { int xo = x + random.nextInt(5) - random.nextInt(5); int yo = y + random.nextInt(5) - random.nextInt(5); for (int yy = yo - 1; yy <= yo + 1; yy++) for (int xx = xo - 1; xx <= xo + 1; xx++) if (xx >= 0 && yy >= 0 && xx < w && yy < h) { if (map[xx + yy * w] == Tile.grass.id) { map[xx + yy * w] = Tile.dirt.id; } } } } }
             */

            for (int i = 0; i < w * h / 400; i++)
            {
                int x = random.nextInt(w);
                int y = random.nextInt(h);
                for (int j = 0; j < 200; j++)
                {
                    int xx = x + random.nextInt(15) - random.nextInt(15);
                    int yy = y + random.nextInt(15) - random.nextInt(15);
                    if (xx >= 0 && yy >= 0 && xx < w && yy < h)
                    {
                        if (map[xx + yy * w] == Tile.grass.id)
                        {
                            map[xx + yy * w] = Tile.tree.id;
                        }
                    }
                }
            }

            for (int i = 0; i < w * h / 400; i++)
            {
                int x   = random.nextInt(w);
                int y   = random.nextInt(h);
                int col = random.nextInt(4);
                for (int j = 0; j < 30; j++)
                {
                    int xx = x + random.nextInt(5) - random.nextInt(5);
                    int yy = y + random.nextInt(5) - random.nextInt(5);
                    if (xx >= 0 && yy >= 0 && xx < w && yy < h)
                    {
                        if (map[xx + yy * w] == Tile.grass.id)
                        {
                            map[xx + yy * w]  = Tile.flower.id;
                            data[xx + yy * w] = (byte)(col + random.nextInt(4) * 16);
                        }
                    }
                }
            }

            for (int i = 0; i < w * h / 100; i++)
            {
                int xx = random.nextInt(w);
                int yy = random.nextInt(h);
                if (xx >= 0 && yy >= 0 && xx < w && yy < h)
                {
                    if (map[xx + yy * w] == Tile.sand.id)
                    {
                        map[xx + yy * w] = Tile.cactus.id;
                    }
                }
            }

            int count = 0;

            for (int i = 0; i < w * h / 100; i++)
            {
                int x = random.nextInt(w - 2) + 1;
                int y = random.nextInt(h - 2) + 1;

                var stop = false;
                for (int yy = y - 1; yy <= y + 1; yy++)
                {
                    for (int xx = x - 1; xx <= x + 1; xx++)
                    {
                        if (map[xx + yy * w] != Tile.rock.id)
                        {
                            stop = true;
                            break;
                        }
                    }
                    if (stop)
                    {
                        break;
                    }
                }

                if (stop)
                {
                    continue;
                }

                map[x + y * w] = Tile.stairsDown.id;
                count++;
                if (count == 4)
                {
                    break;
                }
            }

            return(new byte[][] { map, data });
        }