using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using SmlEngine.Graphics;
using SmlEngine.Extensions;
namespace SmlEngine.Sprites.Base.WorldMap
{
/// <summary>
/// An animated tile for the world map.
/// </summary>
public class WorldAnimatedTile : ICloneable, IWorldDrawable
{
// To prevent confusion:
// Animated frame refers to one frame of an animated world tile.
// Rendered frame refers to one frame drawn to the screen.
#region Fields and Properties
public int id;
public WorldTile worldTile { get; private set; }
public Vector2 Position { get; private set; }
public Vector2 Size
{
get
{
return worldTile.Size;
}
}
private bool isDataSet = false;
#endregion
#region Constructors
public WorldAnimatedTile(int c_id, string c_contentPath, List<Rectangle> c_sourceRect, ContentManager cm, int frameTime)
{
worldTile = new WorldTile(c_contentPath, c_sourceRect);
worldTile.SetData(frameTime);
LoadContent(null, cm);
}
public WorldAnimatedTile(GraphicsDevice gd, string c_FilePath, List<Rectangle> c_frameRects, ContentManager cm, int frameTime)
{
worldTile = new WorldTile(c_FilePath, c_frameRects);
worldTile.SetData(frameTime);
LoadContent(gd, cm);
}
public WorldAnimatedTile() { }
#endregion
#region Methods
public void Draw(GameTime gameTime, SpriteBatch sb)
{
worldTile.Draw(gameTime, sb, Position);
}
public void Update(GameTime gameTime) { }
public Object Clone()
{
WorldAnimatedTile a = new WorldAnimatedTile();
a.worldTile = worldTile.Clone();
a.id = id;
a.Position = Position;
return a;
}
public void LoadContent(GraphicsDevice gd, ContentManager cm)
{
worldTile.LoadContent(gd, cm, true);
}
public void UnloadContent()
{
worldTile.UnloadContent();
}
public void SetData(Vector2 position)
{
if (!isDataSet)
{
Position = position;
isDataSet = true;
}
}
#endregion
}
}