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 sprList) { int largestSoFar = 0; foreach(Sprite spr in sprList) { if (spr.Area.Width > largestSoFar) largestSoFar = spr.Area.Width; } } public List GetIntersectors(List spriteList) { List result = new List(); foreach(Sprite spr in spriteList) { if (spr.IntersectsWith(this)) result.Add(spr); } return result; } public List GetIntersectorsX(List spriteList) { List result = new List(); foreach(Sprite spr in spriteList) { if (spr.IntersectsWithX(this)) result.Add(spr); } return result; } public List GetIntersectorsY(List spriteList) { List result = new List(); foreach(Sprite spr in spriteList) { if (spr.IntersectsWithY(this)) result.Add(spr); } return result; } public bool IntersectsWith(List 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 otherSprites) { foreach (Sprite spr in otherSprites) { if (IntersectsWithX(spr)) return true; } return false; } public bool IntersectsWithY(List 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); } } }