using Godot; namespace RogueTank.Util; public static class PixelArt { public static Texture2D MakeSolidTexture(int w, int h, Color color) { var img = Image.Create(w, h, false, Image.Format.Rgba8); img.Fill(color); return ImageTexture.CreateFromImage(img); } public static Texture2D MakeTankTexture(int size, Color body, Color turret) { var img = Image.Create(size, size, false, Image.Format.Rgba8); img.Fill(Colors.Transparent); // Body var margin = Mathf.Max(1, size / 8); var bodyRect = new Rect2I(margin, margin * 2, size - margin * 2, size - margin * 3); FillRect(img, bodyRect, body); // Tracks FillRect(img, new Rect2I(margin / 2, margin * 2, margin, size - margin * 3), body.Darkened(0.25f)); FillRect(img, new Rect2I(size - margin - margin / 2, margin * 2, margin, size - margin * 3), body.Darkened(0.25f)); // Turret var t = Mathf.Max(2, size / 4); FillRect(img, new Rect2I(size / 2 - t / 2, size / 2 - t / 2, t, t), turret); // Barrel FillRect(img, new Rect2I(size / 2 - 1, margin, 2, size / 2 - margin), turret.Lightened(0.1f)); return ImageTexture.CreateFromImage(img); } public static Texture2D MakeBulletTexture(int w, int h, Color color) { var img = Image.Create(w, h, false, Image.Format.Rgba8); img.Fill(Colors.Transparent); FillRect(img, new Rect2I(0, 0, w, h), color); return ImageTexture.CreateFromImage(img); } public static Texture2D MakePickupTexture(int size, Color color) { var img = Image.Create(size, size, false, Image.Format.Rgba8); img.Fill(Colors.Transparent); // simple diamond var c = size / 2; for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { var dx = Mathf.Abs(x - c); var dy = Mathf.Abs(y - c); if (dx + dy <= c) img.SetPixel(x, y, color); } } return ImageTexture.CreateFromImage(img); } private static void FillRect(Image img, Rect2I rect, Color c) { for (int y = rect.Position.Y; y < rect.Position.Y + rect.Size.Y; y++) { for (int x = rect.Position.X; x < rect.Position.X + rect.Size.X; x++) img.SetPixel(x, y, c); } } }