Add project files.
This commit is contained in:
125
SpriteStacker/Model.cs
Normal file
125
SpriteStacker/Model.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
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 = 0;
|
||||
public static int LocY = 50;
|
||||
public static float Rotation = 0;
|
||||
public static float scale = 10;
|
||||
public static int Width;
|
||||
public static int Height;
|
||||
}
|
||||
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 SetBitmapLayers(Bitmap[] images)
|
||||
{
|
||||
LayerImages = images.ToList();
|
||||
ModelData.Clear();
|
||||
for(int i = 0;i < LayerImages.Count; i++)
|
||||
{
|
||||
Width = LayerImages[i].Width;
|
||||
Length = LayerImages[i].Height;
|
||||
ModelData.Add(new Voxel[Width, Length]);
|
||||
for (int x = 0; x < LayerImages[i].Width; x++)
|
||||
{
|
||||
for(int y = 0; y < LayerImages[i].Height; y++)
|
||||
{
|
||||
ModelData[i][x,y] = new Voxel(LayerImages[i].GetPixel(x,y));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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.Width/2,Camera.LocY - (i*Camera.scale) + Camera.Height/2);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user