128 lines
2.6 KiB
C#
128 lines
2.6 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Drawing;
|
|||
|
|
|||
|
namespace SpritePacker
|
|||
|
{
|
|||
|
public class Sprite
|
|||
|
{
|
|||
|
private Rectangle area;
|
|||
|
private string filename;
|
|||
|
|
|||
|
public Rectangle Area
|
|||
|
{
|
|||
|
get { return area; }
|
|||
|
set { area = value; }
|
|||
|
}
|
|||
|
public string Filename
|
|||
|
{
|
|||
|
get { return filename; }
|
|||
|
set { filename = value; }
|
|||
|
}
|
|||
|
|
|||
|
public Sprite(string inFilename)
|
|||
|
{
|
|||
|
Filename = inFilename;
|
|||
|
// TODO: Fill in the area automagically based on the given image
|
|||
|
throw new NotImplementedException("Todo: Fill in the area automagically based on the given image");
|
|||
|
}
|
|||
|
|
|||
|
public static int GetLargestSize(List<Sprite> sprList)
|
|||
|
{
|
|||
|
int largestSoFar = 0;
|
|||
|
foreach(Sprite spr in sprList)
|
|||
|
{
|
|||
|
if (spr.Area.Width > largestSoFar)
|
|||
|
largestSoFar = spr.Area.Width;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public List<Sprite> GetIntersectors(List<Sprite> spriteList)
|
|||
|
{
|
|||
|
List<Sprite> result = new List<Sprite>();
|
|||
|
foreach(Sprite spr in spriteList)
|
|||
|
{
|
|||
|
if (spr.IntersectsWith(this))
|
|||
|
result.Add(spr);
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
public List<Sprite> GetIntersectorsX(List<Sprite> spriteList)
|
|||
|
{
|
|||
|
List<Sprite> result = new List<Sprite>();
|
|||
|
foreach(Sprite spr in spriteList)
|
|||
|
{
|
|||
|
if (spr.IntersectsWithX(this))
|
|||
|
result.Add(spr);
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
public List<Sprite> GetIntersectorsY(List<Sprite> spriteList)
|
|||
|
{
|
|||
|
List<Sprite> result = new List<Sprite>();
|
|||
|
foreach(Sprite spr in spriteList)
|
|||
|
{
|
|||
|
if (spr.IntersectsWithY(this))
|
|||
|
result.Add(spr);
|
|||
|
}
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
public bool IntersectsWith(List<Sprite> otherSprites)
|
|||
|
{
|
|||
|
foreach (Sprite spr in otherSprites)
|
|||
|
{
|
|||
|
if (IntersectsWith(spr))
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
public bool IntersectsWith(Sprite otherSprite)
|
|||
|
{
|
|||
|
return otherSprite.Area.IntersectsWith(Area);
|
|||
|
}
|
|||
|
|
|||
|
public bool IntersectsWithX(List<Sprite> otherSprites)
|
|||
|
{
|
|||
|
foreach (Sprite spr in otherSprites)
|
|||
|
{
|
|||
|
if (IntersectsWithX(spr))
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
public bool IntersectsWithY(List<Sprite> otherSprites)
|
|||
|
{
|
|||
|
foreach (Sprite spr in otherSprites)
|
|||
|
{
|
|||
|
if (IntersectsWithY(spr))
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public bool IntersectsWithX(Sprite otherSprite)
|
|||
|
{
|
|||
|
if(Area.Right > otherSprite.Area.X &&
|
|||
|
Area.X < otherSprite.Area.Right)
|
|||
|
return true;
|
|||
|
else
|
|||
|
return false;
|
|||
|
}
|
|||
|
public bool IntersectsWithY(Sprite otherSprite)
|
|||
|
{
|
|||
|
if(Area.Bottom > otherSprite.Area.Y &&
|
|||
|
Area.Y < otherSprite.Area.Bottom)
|
|||
|
return true;
|
|||
|
else
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public override string ToString()
|
|||
|
{
|
|||
|
return string.Format("Sprite {0} at {1}", Filename, Area);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|