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; } } } }
public static void DrawTilemapTile(string tex, uint sx, uint sy, int id, uint s = 16) { if (id < 0) { return; } uint i = (uint)id; texture t = cache.GetTexture(tex); t.Draw(sx, sy, (i % (t.Width / s)) * s, (i / (t.Width / s)) * s, s, s); }
public static texture ReadImage(ref BinaryReader r, uint w, uint h) { texture t = new texture(w, h); for (int i = 0; i < w * h; i++) { uint x = (uint)(i % w); uint y = (uint)(i / w); t.SetPixel(x, y, Color.FromArgb(r.ReadByte(), r.ReadByte(), r.ReadByte())); } return(t); }
public static texture GetTexture(string name, bool cache = true) { if (Texturecache.ContainsKey(name) && cache) { return(Texturecache[name]); } var tex = new texture(name); if (cache) { Texturecache.Add(name, tex); } return(tex); }
static void DrawButton(uint x, uint y, uint n) { bool hover = new Rectangle((int)(55 + x), (int)(299 + y), 16, 18).Contains(s_input.GetMousePos()); cache.GetTexture("gui/button").Draw(55 + x, 299 + y, selected == n ? (uint)16 : (uint)0, 0, 16, 18); texture t = cache.GetTexture("gui/tool_icons"); t.Draw(55 + x, 299 + y + (selected == n ? (uint)3 : (uint)0), (n % (t.Width / 16)) * 16, (n / (t.Width / 16)) * 16, 16, 16); if (hover) { hovered = (int)n; } }
public static void Init() { font = new texture("gui/font"); }