|
|
using System.Diagnostics;
|
|
|
|
|
|
using Num = System.Numerics;
|
|
|
using Microsoft.Xna.Framework;
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
|
namespace isometricparkfna
|
|
|
{
|
|
|
public class ImageMap
|
|
|
{
|
|
|
public Texture2D ImageMapTexture;
|
|
|
|
|
|
public int TileWidth;
|
|
|
public int TileHeight;
|
|
|
|
|
|
public ImageMap(int tileWidth, int tileHeight, Texture2D ImageMapTexture)
|
|
|
{
|
|
|
this.TileHeight = tileHeight;
|
|
|
this.TileWidth = tileWidth;
|
|
|
this.ImageMapTexture = ImageMapTexture;
|
|
|
Debug.Assert(ImageMapTexture != null);
|
|
|
Debug.Assert(tileHeight != null);
|
|
|
Debug.Assert(tileWidth != null);
|
|
|
Logging.Info("Constructed ImageMap.");
|
|
|
}
|
|
|
|
|
|
public Rectangle GetSourceRectangle(int tileIndex)
|
|
|
{
|
|
|
int tileY = tileIndex / (ImageMapTexture.Width / TileWidth);
|
|
|
int tileX = tileIndex % (ImageMapTexture.Width / TileWidth);
|
|
|
|
|
|
return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight);
|
|
|
}
|
|
|
public Num.Vector2 GetSourceUVStart(int tileIndex)
|
|
|
{
|
|
|
int tileX = tileIndex % (ImageMapTexture.Width / TileWidth);
|
|
|
int tileY = tileIndex / (ImageMapTexture.Width / TileWidth);
|
|
|
|
|
|
int imageMapX = (tileX) * TileWidth;
|
|
|
int imageMapY = (tileY) * TileHeight;
|
|
|
|
|
|
|
|
|
return new Num.Vector2( ((float)imageMapX)/ImageMapTexture.Width,
|
|
|
((float)imageMapY)/ImageMapTexture.Height);
|
|
|
|
|
|
}
|
|
|
public Num.Vector2 GetSourceUVEnd(int tileIndex)
|
|
|
{
|
|
|
int tileX = tileIndex % (ImageMapTexture.Width / TileWidth);
|
|
|
int tileY = tileIndex / (ImageMapTexture.Width / TileWidth);
|
|
|
|
|
|
int imageMapX = (tileX+1) * TileWidth;
|
|
|
int imageMapY = (tileY+1) * TileHeight;
|
|
|
|
|
|
|
|
|
return new Num.Vector2( ((float)imageMapX)/ImageMapTexture.Width,
|
|
|
((float)imageMapY)/ImageMapTexture.Height);
|
|
|
|
|
|
}
|
|
|
|
|
|
public Rectangle GetExtendedSourceRectangle(int tileIndex, int height)
|
|
|
{
|
|
|
int tileY = tileIndex / (ImageMapTexture.Width / TileWidth);
|
|
|
int tileX = tileIndex % (ImageMapTexture.Width / TileWidth);
|
|
|
|
|
|
return new Rectangle(tileX * TileWidth, tileY * TileHeight, TileWidth, TileHeight*height);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|