#region File Description
//-----------------------------------------------------------------------------
// GameAreaEvent.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RobotGameData;
#endregion
namespace RobotGameData.GameEvent
{
///
/// When a particular scene node comes into a particular area,
/// this event is executed.
///
public class GameAreaEvent : GameEventBase
{
#region Fields
protected Vector3 actionPosition = Vector3.Zero;
protected float actionRadius = 0.0f;
#endregion
///
/// Constructor.
///
/// event type
/// position
/// area radius
/// event owner
/// owner visible flag
public GameAreaEvent(Vector3 position, float radius,
GameSceneNode owner, bool visibledOwner)
{
SetAction(position, radius, owner, visibledOwner);
}
///
/// Set area event
///
/// The position of this event
/// The radius of this event
/// The scene owner of this event
///
/// Visibility of the scene owner before start this event
///
public void SetAction(Vector3 position, float radius,
GameSceneNode owner, bool visibledOwner)
{
this.actionPosition = position;
this.actionRadius = radius;
this.owner = owner;
this.owner.Enabled = false;
this.owner.Visible = visibledOwner;
}
///
/// If the distance between the "targetPosition" and the selected
/// action position is short, the status of the game changes so that
/// an event might occur. In this case, it returns "true".
///
public bool IsExecuteAction(Vector3 targetPosition)
{
float distance = Vector3.Distance(targetPosition, this.actionPosition);
if (distance <= this.actionRadius)
return true;
return false;
}
///
/// It activates event.
/// scene owner gets reset and starts activating.
///
public override void ExecuteAction()
{
this.owner.Reset(true);
this.owner.Enabled = true;
this.owner.Visible = true;
waitingAction = false;
finishedAction = true;
}
}
}