/******************************************************************************/ /*! \file TargetsArcEvent.cs \author Kevin Carey Target event in which a number of targets start from below the range and "jump" up in an arc pattern Copyright © 2007 DigiPen(USA) Corporation. All rights reserved. */ /******************************************************************************/ using System; using System.Collections.Generic; using Microsoft.Xna.Framework; namespace Shooting_Range { // TargetsArcEvent // A number of targets start from below the range and "jump" up in an arc pattern class TargetsArcEvent : IEvent { // Constructor public TargetsArcEvent(List objectList, Sound sound, Statistics stats) { // Set the member variables m_ObjectList = objectList; m_Sound = sound; m_Stats = stats; } // IEvent Init function public void Init(int round) { // Init variables m_Timer = new TimeSpan(0, 0, 4); m_End = false; m_IsActive = true; m_Count = 0; // Update the stats m_Stats.TotalTargets += m_ObjectList.Count; // For each object in the list for (int i = 0; i < m_ObjectList.Count; ++i) { // Set it to inactive m_ObjectList[i].IsActive = false; // Set its gravity m_ObjectList[i].PhysicsData.Gravity = 0.2f; // If the index is even if (i % 2 == 0) { // Position it on the left going towards the right m_ObjectList[i].Move(new Vector3(-80.0f, -100.0f, 0.0f) - m_ObjectList[i].Position); m_ObjectList[i].PhysicsData.VelocityDirection = new Vector3(2.0f, 7.0f, 0.0f); } // If the index is odd else { // Position it on the right going towards the left m_ObjectList[i].Move(new Vector3(80.0f, -100.0f, 0.0f) - m_ObjectList[i].Position); m_ObjectList[i].PhysicsData.VelocityDirection = new Vector3(-2.0f, 7.0f, 0.0f); } } } // IEvent Update function public void Update(TimeSpan deltaTime) { // Decrement the timer m_PreviousTime = m_Timer; m_Timer -= deltaTime; // If the event is done if (m_Timer < new TimeSpan(0, 0, 0)) { // Set the flags m_End = true; m_IsActive = false; } // If all objects have not been activated yet else if (m_Count < m_ObjectList.Count) { // If the timer is at a point to start the next target if ((m_Timer.Seconds != m_PreviousTime.Seconds) || (m_Timer.Milliseconds < 500 && m_PreviousTime.Milliseconds >= 500)) { // Start the next target m_ObjectList[m_Count].IsActive = true; // Increment the counter ++m_Count; } } } // IEvent HandleCollision function public void HandleCollision(Object bullet, Object obj) { // Make the bullet inactive bullet.IsActive = false; // Make the object inactive obj.IsActive = false; // Update stats ++m_Stats.TargetsHit; ++m_Stats.ShotsHit; // Play sound m_Sound.Play("Hit"); } // IEvent Shutdown function public void Shutdown() { // For each object in the list for (int i = 0; i < m_ObjectList.Count; ++i) { // If the object is still active if (m_ObjectList[i].IsActive) { // Update the stats ++m_Stats.TargetsNotHit; // Make the object inactive m_ObjectList[i].IsActive = false; } } } // IEvent End function public bool End() { return m_End; } // IEvent Fail function public bool Fail() { // Failure is impossible. Return false return false; } // IEvent ResetFail function public void ResetFail() { // Failure is impossible. Do nothing return; } // IEvent IsActive flag public bool IsActive { get { return m_IsActive; } } // IEvent Timer public TimeSpan Timer { get { return m_Timer; } } // Members private TimeSpan m_Timer; private TimeSpan m_PreviousTime; private bool m_End; private bool m_IsActive; private List m_ObjectList; private int m_Count; private Sound m_Sound; private Statistics m_Stats; } }