Files
Sprite-Stacker/SpriteStacker/Model-HR-SD-A172-010.cs

106 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SpriteStacker
{
public static class Camera
{
public static int LocX = 300;
public static int LocY = 300;
public static float Rotation = 0;
public static float scale = 10;
}
public class Voxel
{
Color VoxelColor;
public Voxel(Color voxelColor)
{
VoxelColor = voxelColor;
}
public Color GetColor() { return VoxelColor; }
public Color[] GetShadedColors(int[] Shadows)
{
Color[] sides = new Color[6];
for (int i = 0; i < 6; i++)
{
sides[i] = Color.FromArgb(Math.Max(Math.Min(VoxelColor.R + Shadows[i], 255), 0), Math.Max(Math.Min(VoxelColor.G + Shadows[i], 255), 0), Math.Max(Math.Min(VoxelColor.B + Shadows[i], 255), 0));
}
return sides;
}
public Color[] GetShadedColors()
{
Color[] sides = new Color[6];
int[] Shadows = new int[6] { 0, 10, 0, 10, 20, -20 };
for (int i = 0; i < 6; i++)
{
sides[i] = Color.FromArgb(Math.Max(Math.Min(VoxelColor.R + Shadows[i], 255), 0), Math.Max(Math.Min(VoxelColor.G + Shadows[i], 255), 0), Math.Max(Math.Min(VoxelColor.B + Shadows[i], 255), 0));
}
return sides;
}
}
public class Model
{
public List<Bitmap> LayerImages = new List<Bitmap>();
List<Voxel[,]> ModelData = new List<Voxel[,]>();
int Width;
int Length;
public Model(int Width, int Length)
{
this.Width = Width;
this.Length = Length;
AddLayer();
}
public void AddLayers(int layerCount)
{
for (int i = 0; i < layerCount; i++)
{
AddLayer();
}
}
public void AddLayer()
{
LayerImages.Add(new Bitmap(Width, Length));
ModelData.Add(new Voxel[Width,Length]);
}
public void DrawSpriteStack(Graphics G)
{
for (int i = 0; i < ModelData.Count; i++)
{
G.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
G.ResetTransform();
G.TranslateTransform(Camera.LocX,Camera.LocY - (i*Camera.scale));
G.RotateTransform(Camera.Rotation);
G.DrawImage(LayerImages[i], new Rectangle(new Point(-(int)(Width * Camera.scale)/2, -(int)(Length * Camera.scale) / 2),new Size((int)(Width * Camera.scale), (int)(Length * Camera.scale))));
}
}
public void DrawLayersToImages()
{
for (int i = 0; i < ModelData.Count; i++)
{
Bitmap newImage = new Bitmap(Width, Length);
for (int x = 0; x < ModelData[i].GetLength(0); x++)
{
for (int y = 0; y < ModelData[i].GetLength(1); y++)
{
if (ModelData[i][x, y] != null)
{
newImage.SetPixel(x, y, ModelData[i][x, y].GetColor());
}
}
}
LayerImages[i] = newImage;
}
}
public void SetData(int LocX, int LocY, int Layer, Voxel voxel)
{
if (Layer >= ModelData.Count) AddLayer();
ModelData[Layer][LocX,LocY] = voxel;
}
}
}