#region USING
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace GhostArena3D
{
   public class GhostArena3D : Microsoft.Xna.Framework.Game
   {
      #region Fields
      
      GraphicsDeviceManager graphics;
      
      ScreenManager screenManager;
      InputSystem input;
      
      private AudioEngine audio;
      private WaveBank wavebank;
      public SoundBank soundbank;
      
      #endregion

      #region Initialize

      public GhostArena3D()
      {
         graphics = new GraphicsDeviceManager(this);
         Content.RootDirectory = "Content";
         
         graphics.PreferMultiSampling = true;
         graphics.PreferredBackBufferWidth = 1024;
         graphics.PreferredBackBufferHeight = 768;
         graphics.SynchronizeWithVerticalRetrace = false;
         this.IsFixedTimeStep = false;
         
         input = new InputSystem(this);
         input.Enabled = false;

         input.AddAction("Move", Control.LeftStick, ActionType.Move, null);
         input.AddAction("Move Forward", Control.DPadUp, ActionType.MoveForward, null);
         input.AddAction("Move Backward", Control.DPadDown, ActionType.MoveBackward, null);
         input.AddAction("Move Left", Control.DPadLeft, ActionType.MoveLeft, null);
         input.AddAction("Move Right", Control.DPadRight, ActionType.MoveRight, null);
         input.AddAction("Fire", Control.RightTrigger, ActionType.Fire, null);
         input.AddAction("Rotate", Control.RightStick, ActionType.Rotate, null);

         Components.Add(input);
         
         audio = new AudioEngine("Content/Sounds/GhostArenaGameAudio.xgs");
         wavebank = new WaveBank(audio, "Content/Sounds/Wave Bank.xwb");
         soundbank = new SoundBank(audio, "Content/Sounds/Sound Bank.xsb");

         this.Services.AddService(typeof(IInputSystem), input);
         
         screenManager = new ScreenManager(this, graphics);

         Components.Add(screenManager);

         screenManager.AddScreen(new BackgroundScreen());
         screenManager.AddScreen(new MainMenuScreen());
      }

      #endregion
      
      #region Update and Draw


      protected override void Update(GameTime gameTime)
      {
         audio.Update();

         base.Update(gameTime);
      }


      protected override void Draw(GameTime gameTime)
      {
         graphics.GraphicsDevice.Clear(Color.Black);

         base.Draw(gameTime);
      }
      
      #endregion
   }
   
   #region Entry
   
   static class Program
   {
      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      static void Main(string[] args)
      {
         using (GhostArena3D game = new GhostArena3D())
         {
            game.Run();
         }
      }
   }
   
   #endregion
}
