Beispiel #1
0
 void addGeneration()
 {
     generation++;
     if (generation % 5 == 0)
     {
         if (mathf.Random(0, 100) < 60)
         {
             generator = generators[(int)mathf.Random(2, generators.Length - 1)];
         }
         else
         {
             generator = generators[0];
         }
     }
 }
Beispiel #2
0
            public Mosaic()
            {
                var   mosaic_image = g_images_mosaic[0];
                float sw = mosaic_image.GetWidth(), sh = mosaic_image.GetHeight();
                float ww = (float)Window.FromPixels(Graphics.GetWidth()), wh = (float)Window.FromPixels(Graphics.GetHeight());

                if (Window.GetPixelScale() > 2)
                {
                    mosaic_image = g_images_mosaic[1];
                }
                int SIZE_X = (int)math.Floor(ww / 32f + 2f);
                int SIZE_Y = (int)math.Floor(wh / 32f + 3f);
                int SIZE   = SIZE_X * SIZE_Y;

                batch  = Graphics.NewSpriteBatch(mosaic_image, SIZE, Mesh.Usage.Stream);
                COLORS = new Int4[] {
                    new Int4(240, 240, 240, 255), new Int4(232, 104, 162, 255), new Int4(69, 155, 168, 255), new Int4(67, 93, 119, 255),
                    new Int4(240, 240, 240, 255), new Int4(232, 104, 162, 255), new Int4(69, 155, 168, 255), new Int4(67, 93, 119, 255),
                    new Int4(220, 239, 113, 255),
                };

                Quad[] QUADS = new Quad[] {
                    Graphics.NewQuad(0, 0, 32, 32, sw, sh),
                    Graphics.NewQuad(0, 32, 32, 32, sw, sh),
                    Graphics.NewQuad(32, 32, 32, 32, sw, sh),
                    Graphics.NewQuad(32, 0, 32, 32, sw, sh),
                };

                int   exclude_left     = (int)math.Floor(ww / 2f / 32f);
                int   exclude_right    = exclude_left + 3;
                int   exclude_top      = (int)math.Floor(wh / 2f / 32f);
                int   exclude_bottom   = exclude_top + 3;
                int   exclude_width    = exclude_right - exclude_left + 1;
                int   exclude_height   = exclude_bottom - exclude_top + 1;
                int   exclude_area     = exclude_width * exclude_height;
                float exclude_center_x = exclude_left + 1.5f;
                float exclude_center_y = exclude_top + 1.5f;

                int COLORS_LENGHT = COLORS.Length;

                generators = new RCIGDelegate[]
                {
                    (grid_x, grid_y) => (int)mathf.Random(0, COLORS_LENGHT - 1),
                    (grid_x, grid_y) => math.Abs((generation + grid_x - grid_y)) % COLORS_LENGHT,
                    (grid_x, grid_y) => (grid_x + generation) % COLORS_LENGHT,
                    (grid_x, grid_y) => ((int)math.Abs(math.Floor(generation + math.Sqrt(grid_x * grid_x + grid_y * grid_y)))) % COLORS_LENGHT,
                    (grid_x, grid_y) =>
                    {
                        var dx = grid_x - exclude_center_x;
                        var dy = grid_y - exclude_center_y;
                        return(((int)math.Abs(math.Floor(generation - math.Sqrt(dx * dx + dy * dy)))) % COLORS_LENGHT);
                    },
                    (grid_x, grid_y) =>
                    {
                        var dx = math.Abs(grid_x - exclude_center_x) - generation;
                        var dy = math.Abs(grid_y - exclude_center_y) - generation;
                        return(((int)math.Abs(math.Floor(math.Max(dx, dy)))) % COLORS_LENGHT);
                    },
                };
                generator = generators[0];

                for (int y = 1; y < SIZE_Y; y++)
                {
                    for (int x = 1; x < SIZE_X; x++)
                    {
                        if (!(exclude_left <= x && x <= exclude_right && exclude_top <= y && y <= exclude_bottom))
                        {
                            var gen = COLORS[generator(x, y)];
                            var p   = new Piece(x, y, (x - 1) * 32, (y - 1) * 32, (float)(mathf.Random(0, 100) / 100 * math.PI), 1, QUADS[(x + y) % 4], gen, gen);
                            pices.Add(p);
                        }
                    }
                }

                var GLYPHS = new Dictionary <char, Quad>()
                {
                    { 'N', Graphics.NewQuad(0, 64, 32, 32, sw, sh) },
                    { 'O', Graphics.NewQuad(32, 64, 32, 32, sw, sh) },
                    { 'G', Graphics.NewQuad(0, 96, 32, 32, sw, sh) },
                    { 'A', Graphics.NewQuad(32, 96, 32, 32, sw, sh) },
                    { 'M', Graphics.NewQuad(64, 96, 32, 32, sw, sh) },
                    { 'E', Graphics.NewQuad(96, 96, 32, 32, sw, sh) },

                    { 'U', Graphics.NewQuad(64, 0, 32, 32, sw, sh) },
                    { 'P', Graphics.NewQuad(96, 0, 32, 32, sw, sh) },
                    { 'o', Graphics.NewQuad(64, 32, 32, 32, sw, sh) },
                    { 'S', Graphics.NewQuad(96, 32, 32, 32, sw, sh) },
                    { 'T', Graphics.NewQuad(64, 64, 32, 32, sw, sh) },
                    { 'R', Graphics.NewQuad(96, 64, 32, 32, sw, sh) },
                };

                Int4 INITIAL_TEXT_COLOR    = new Int4(240, 240, 240, 255);
                put_text_delegate put_text = (string str, int offset, int x, int y) => {
                    int idx = offset + SIZE_X * y + x;

                    int i = 0;
                    foreach (var c in str)
                    {
                        if (' ' != c)
                        {
                            if (idx + i < pices.Count)
                            {
                                var piece = pices[idx + i];
                                piece.quad       = GLYPHS[c];
                                piece.r          = 0;
                                piece.rv         = 0;
                                piece.color_prev = INITIAL_TEXT_COLOR;
                                piece.color_next = INITIAL_TEXT_COLOR;
                            }
                        }

                        i++;
                    }
                };

                int text_center_x       = (int)math.Floor(ww / 2f / 32f) - 10;
                int no_game_text_offset = SIZE_X * exclude_bottom - exclude_area;

                put_text("No GAME", no_game_text_offset, text_center_x - 5, 1);
                put_text("SUPER TOAST", 0, text_center_x, exclude_top - 3);
            }