/*
* EntityDistractor.cs
* Author: Mike DeMauro
* 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 tAC_Engine.Graphics.Entities;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Random=Util.Random;
using Util;
namespace StellarProspector
{
///
/// Represents a distractor to test how a person's focus changes when distractor
/// are or are not along the stimuli.
///
internal class EntityDistractor : EntitySpawnable
{
#region Fields
// The logger to use for event codes
private Logger mLogger;
#endregion
#region Properties
///
/// Sets the Logger to use for event codes
///
public Logger Logger { set { mLogger = value; } }
#endregion
#region Creation
///
/// Create a new EntityDistractor
///
/// The ContentManager used to load content.
/// The name of the texture to load.
public EntityDistractor(ContentManager content, string textureName)
: base(content, textureName)
{
mMinWaitTime = Settings.DistractorWaitMin;
mMaxWaitTime = Settings.DistractorWaitMax;
}
#endregion
#region Spawn
///
/// Spawn the EntityDistractor at a random position within the given sector's bounds.
///
/// The sector to spawn in
/// If the stimulus can spawn outside the given sector
public override void Spawn(int sectorNum, bool errorEnabled)
{
mRadialDistance = Random.Next(mMinSpawnRadius + (int)m_Radius, mMaxSpawnRadius - (int)m_Radius);
double randomAngle = Random.NextDouble() * mSectorAngle;
double bufferAngle = Math.Atan((float)m_Radius / mRadialDistance);
if (randomAngle < bufferAngle)
{
randomAngle = bufferAngle;
}
else if (randomAngle > mSectorAngle - bufferAngle)
{
randomAngle = mSectorAngle - bufferAngle;
}
mTheta = -mSectorAngle * sectorNum - randomAngle;
X = (int)(mRadialDistance * Math.Cos(mTheta) - m_TextureCenter.X + mOrigin.Y);
Y = (int)(mRadialDistance * Math.Sin(mTheta) - m_TextureCenter.Y + mOrigin.X);
Visible = true;
mLifeTime = Random.NextDouble() * mMaxLifeTime;
base.Spawn(sectorNum, errorEnabled);
}
///
/// Sets visible to false and state to Dead.
///
public override void Die()
{
Visible = false;
base.Die();
mLogger.Write((int)EventCodes.DistractorDisappear, "SP_DistractorDisappear");
}
#endregion
}
}