/*
* Entity.cs
* Authors: Karl Orosz
* Copyright (c) 2007-2008 Cornell University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
namespace StarJack
{
///
/// Base class for each entity
///
public class Entity
{
public static string mContentDirect = @"\Content\Texture";
private static string mRootDirectory;
public static string RootDirectory
{
get { return mRootDirectory; }
set { mRootDirectory = value; }
}
///
/// The objects name
///
protected string mName;
public string Name
{
get { return mName; }
set { mName = value; }
}
protected Color mColor = Color.White;
public virtual Color Color { get { return mColor; }set{mColor = value;} }
///
/// This is the sub folder or group of textures the entity will look for.
///
protected string mGroup;
public virtual string Group
{
get { return mGroup; }
set
{
mGroupTextures = GroupTextureManager.GetGroupTexture(value);
if (mGroupTextures == null)
{
mGroup = null;
}
else
{
mGroup = value;
}
}
}
protected Dictionary mGroupTextures;
public Dictionary GroupTextures
{
get { return mGroupTextures; }
}
protected Animation mAnimation;
public Animation MyAnimation
{
get { return mAnimation; }
set { mAnimation = value; }
}
private TextureInfo mTexture;
public TextureInfo Texture
{
get { return mTexture; }
set
{
mTexture = value;
}
}
public string TextureName
{
get { if (mTexture == null) { return null; } return mTexture.Name; }
set
{
if (mGroup != null)
{
if (mGroupTextures != null && mGroupTextures.Count > 0)
{
if (mGroupTextures.ContainsKey(value))
{
mTexture = mGroupTextures[value];
}
}
else
{
mTexture = new TextureInfo(value, mGroup);
}
}
else { mTexture = new TextureInfo(value); }
}
}
protected Rectangle mDrawSpace;
public Rectangle DrawSpace
{
get { return mDrawSpace; }
set { mDrawSpace = value; }
}
///
/// X Position of the entity
///
public virtual int X
{
get { return mDrawSpace.X; }
set { mDrawSpace.X = value; }
}
///
/// Y position of the entity
///
public virtual int Y
{
get { return mDrawSpace.Y; }
set { mDrawSpace.Y = value; }
}
protected float mDepth = Room.Depth.Tile;
public virtual float Depth
{
get { return mDepth; }
set { mDepth = value; }
}
///
/// Sets the width of the entity
///
public virtual int Width
{
get { return mDrawSpace.Width; }
set { mDrawSpace.Width = value; }
}
///
/// Sets the height of the entity
///
public virtual int Height
{
get { return mDrawSpace.Height; }
set { mDrawSpace.Height = value; }
}
//If objects collide with this tile
bool collision = false;
public bool Collision
{
get { return collision; }
set { collision = value; }
}
protected float mRotation;
public float Rotation
{
get { return mRotation; }
set { mRotation = value; }
}
public Entity(string name, String group)
{
mDrawSpace = new Rectangle(0, 0, 0, 0);
mName = name;
mGroup = group;
TextureName = name;
}
public Entity(string name)
{
mDrawSpace = new Rectangle(0, 0, 0, 0);
mName = name;
mColor = Color.White;
}
public Entity()
{
mColor = Color.White;
}
public virtual void LoadContent(ContentManager content)
{
if (mGroupTextures != null && mGroupTextures.Count > 0)
{
foreach (String key in mGroupTextures.Keys)
{
mGroupTextures[key].LoadContent(content);
}
}
else if (mTexture != null && mGroup == null)
{
mTexture.LoadContent(content);
}
}
public virtual void Update(GameTime time)
{
if (mAnimation != null && mAnimation.State != Animation.PlayState.None)
{
mAnimation.Update(time);
}
}
public virtual void Draw(SpriteBatch pSpriteBatch)
{
if (mAnimation != null && mAnimation.State == Animation.PlayState.Playing)
{
//pSpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.FrontToBack, SaveStateMode.None);
pSpriteBatch.Draw(mAnimation.CurrentAnimation.SpriteSheet.Asset, mDrawSpace, mAnimation.TextureSource, mColor, 0.0f, Vector2.Zero, SpriteEffects.None, Depth);
//pSpriteBatch.End();
}
else if (mTexture != null && mTexture.Asset != null)
{
//pSpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.FrontToBack, SaveStateMode.None);
pSpriteBatch.Draw(mTexture.Asset, mDrawSpace, mTexture.Source, mColor, 0.0f, Vector2.Zero, SpriteEffects.None, Depth);
//pSpriteBatch.End();
}
}
public virtual void Dispose(){
// mTexture.Asset.Dispose();
}
}
}