예제 #1
0
        public static void WriteChar(ref uint x, uint y, char c, Color col, int alpha = -1)
        {
            int index;
            int cy, cx;

            var unknown = !chars.Contains(c) && !wideChars.Contains(c);
            var wide    = wideChars.Contains(c);

            if (wide)
            {
                index = Array.IndexOf(wideChars, c);
                cx    = index % CHARSACROSS;
                cy    = WIDELINE;
            }
            else
            {
                index = Array.IndexOf(chars, c);
                cx    = index % CHARSACROSS;
                cy    = index / CHARSACROSS;
            }

            var w = wide ? 6 : 5;

            if (cx < 0)
            {
                unknown = true;
            }

            if (c != ' ')
            {
                for (var fx = 0; fx < w; fx++)
                {
                    for (var fy = 0; fy < 6; fy++)
                    {
                        var color = unknown
                        ? ((fx + fy) % 2 == 0 ? Color.White : Color.Black)
                        : font.GetPixel((uint)(cx * w + fx), (uint)(cy * 6 + fy));

                        if (color.ToArgb() != Color.Black.ToArgb() && y + fy > 0 && IsOnScreen((int)x + fx, (int)y + fy))
                        {
                            if (alpha == -1)
                            {
                                s_screen.SetPixel((uint)(x + fx), (uint)(y + fy), col);
                            }
                            else
                            {
                                var a = s_screen.GetPixel((uint)(x + fx), (uint)(y + fy));
                                var b = Color.FromArgb(255, 255, 255);

                                s_screen.SetPixel((uint)(x + fx), (uint)(y + fy), s_screen.MixColor(a, b, alpha));
                            }
                        }
                    }
                }
            }

            x += (uint)w;
        }
예제 #2
0
        public static void GenerateFromImage(texture t)
        {
            if (t.Height != t.Width)
            {
                log.ThrowFatal("image not 1:1!");
            }

            size            = (int)t.Height;
            g_game.datetime = new DateTime(1990, 1, 1, 7, 27, 0, 0);
            g_game.money    = g_game.MONEY_START;
            Init();

            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    Color c = t.GetPixel((uint)x, (uint)y);

                    terrain[x, y] = 0;
                    if (c == Color.FromArgb(0, 0, 255))
                    {
                        water[x, y] = true;
                    }
                    else
                    {
                        water[x, y] = false;
                    }

                    if (c == Color.FromArgb(0, 255, 255))
                    {
                        g_game.cameraX = x; g_game.cameraY = y;
                    }

                    if (c == Color.FromArgb(255, 0, 0))
                    {
                        buildings[x, y] = 2;
                    }
                    else if (c == Color.FromArgb(255, 255, 0))
                    {
                        buildings[x, y] = 2; water[x, y] = true;
                    }
                    else if (c == Color.FromArgb(0, 0, 0))
                    {
                        buildings[x, y] = 0;
                    }
                    else if (c == Color.FromArgb(0, 255, 0))
                    {
                        buildings[x, y] = 4;
                    }
                    else
                    {
                        buildings[x, y] = -1;
                    }
                }
            }
        }