using System; using System.Collections.Generic; using System.Linq; 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.Media; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; using tAC_Engine.Graphics.Cameras; using tAC_Engine.Graphics.Entities; using tAC_Engine.Graphics; using Util; namespace FaceOff { /// /// This is the main type for your game /// public class FaceOff : GameScreen { public static String TextureDirectory = @"Texture\"; List mMenuItems = new List(); int mItemSelected = 0; int mouseSelected = -1; GraphicsDeviceManager graphics; SpriteBatch mSpriteBatch; SpriteFont mSpriteFont; EntitySprite mCursor; EntitySprite mBackground; EntitySprite startButton; //EntitySprite tutorialButton; EntitySprite exitButton; List mComponents; private Logger mLogger; InputHandler mInputHandler; /// /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// public override void Initialize() { // TODO: Add your initialization logic here //Content.RootDirectory = RootDirectory; mLogger = GetLogger(); mLogger.Initialize(); mLogger.Write((int)EventCode.FO_START, typeof(EventCode)); mComponents = new List(); mMenuItems.Add("Start"); mMenuItems.Add("Tutorial"); mMenuItems.Add("Exit"); mInputHandler = GetInputHandler(); mInputHandler.Initialize(); //mInputHandler.BindButton(Keys.Up, Trigger.Activated, (int)EventCode.MenuUp); //mInputHandler.BindButton(Keys.Down, Trigger.Activated, (int)EventCode.MenuDown); mInputHandler.BindButton(Keys.Enter, Trigger.Activated, (int)EventCode.FO_INPUT_KEY_ENTER); mInputHandler.BindButton(Keys.Left, Trigger.Activated, (int)EventCode.FO_INPUT_KEY_LEFT); mInputHandler.BindButton(Keys.Right, Trigger.Activated, (int)EventCode.FO_INPUT_KEY_RIGHT); mInputHandler.BindButton(MouseButton.Left, Trigger.Activated, (int)EventCode.FO_INPUT_MOUSE_LEFT_DOWN); mBackground = new EntitySprite(Content, @"Texture\FaceOffScreen"); mBackground.Position = Vector2.Zero; mBackground.DrawOrder = -1; mBackground.Initialize(); mCursor = new EntitySprite(Content, @"Texture\Cursor"); mCursor.BlendMode = SpriteBlendMode.AlphaBlend; mCursor.Position = Vector2.Zero; mCursor.Initialize(); startButton = new EntitySprite(Content, @"Texture\start"); startButton.Position = new Vector2(150, 400); startButton.DrawOrder = 0; startButton.Initialize(); //tutorialButton = new EntitySprite(Content, @"Texture\tutorial"); //tutorialButton.Position = new Vector2(350, 400); //tutorialButton.DrawOrder = 0; //tutorialButton.Initialize(); exitButton = new EntitySprite(Content, @"Texture\exit"); exitButton.Position = new Vector2(550, 400); exitButton.DrawOrder = 0; exitButton.Initialize(); mComponents.Add(mBackground); mComponents.Add(startButton); //mComponents.Add(tutorialButton); mComponents.Add(exitButton); base.Initialize(); } /// /// LoadContent will be called once per game and is the place to load /// all of your content. /// protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. mSpriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here foreach (GameComponent gc in mComponents) { EntitySprite s = gc as EntitySprite; if (s != null) { s.SpriteBatch = mSpriteBatch; } } mCursor.SpriteBatch = mSpriteBatch; //SoundManager.SoundManager.UnloadAudioProject(); //SoundManager.SoundManager.LoadAudioProject(Content.RootDirectory, @"AudioProject.xgs"); base.LoadContent(); } /// /// UnloadContent will be called once per game and is the place to unload /// all content. /// protected override void UnloadContent() { // TODO: Unload any non ContentManager content here base.UnloadContent(); } /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// /// Provides a snapshot of timing values. public override void Update(GameTime gameTime) { base.Update(gameTime); mCursor.X = mInputHandler.MouseLocation.X; mCursor.Y = mInputHandler.MouseLocation.Y; // TODO: Add your update logic here while (mInputHandler.HasEvent()) { InputEvent inputEvent = mInputHandler.GetNextEvent(); EventCode foEvent = (EventCode)inputEvent.EventCode; switch (foEvent) { case EventCode.FO_INPUT_KEY_LEFT: //inputEvent.WriteToLog(mLogger, "FO_MENU_INPUT_Left"); inputEvent.WriteToLog(mLogger, Enum.GetName(typeof(EventCode), foEvent)); mItemSelected = (mItemSelected - 1 + mMenuItems.Count) % mMenuItems.Count; break; case EventCode.FO_INPUT_KEY_RIGHT: //inputEvent.WriteToLog(mLogger, "FO_MENU_INPUT_Right"); inputEvent.WriteToLog(mLogger, Enum.GetName(typeof(EventCode), foEvent)); mItemSelected = (mItemSelected + 1) % mMenuItems.Count; break; case EventCode.FO_INPUT_KEY_ENTER: inputEvent.WriteToLog(mLogger, Enum.GetName(typeof(EventCode), foEvent)); switch (mItemSelected) { case 0: //inputEvent.WriteToLog(mLogger, "FO_MENU_INPUT_Enter"); mInputHandler.Disable(); Raise(new FaceOffGame()); break; case 1: break; case 2: //inputEvent.WriteToLog(mLogger, "FO_END_QUIT"); inputEvent.WriteToLog(mLogger, Enum.GetName(typeof(EventCode), EventCode.FO_MENU_QUIT)); Done(); break; } break; case EventCode.FO_INPUT_MOUSE_LEFT_DOWN: inputEvent.WriteToLog(mLogger, Enum.GetName(typeof(EventCode), foEvent)); //inputEvent.WriteToLog(mLogger, "FO_MENU_INPUT_MouseClick"); if (mInputHandler.MouseLocation.X >= 150 && mInputHandler.MouseLocation.X <= 250 && mInputHandler.MouseLocation.Y >= 400 && mInputHandler.MouseLocation.Y <= 435) { //inputEvent.WriteToLog(mLogger, "Starting Game"); mInputHandler.Disable(); Raise(new FaceOffGame()); } else if (mInputHandler.MouseLocation.X >= 350 && mInputHandler.MouseLocation.X <= 450 && mInputHandler.MouseLocation.Y >= 400 && mInputHandler.MouseLocation.Y <= 435) { //inputEvent.WriteToLog(mLogger, "Tutorial Started"); //Tutuorial code starter goes here } else if (mInputHandler.MouseLocation.X >= 550 && mInputHandler.MouseLocation.X <= 650 && mInputHandler.MouseLocation.Y >= 400 && mInputHandler.MouseLocation.Y <= 435) { mLogger.Write((int)EventCode.FO_MENU_QUIT, typeof(EventCode)); Done(); } break; } } base.Update(gameTime); } /// /// This is called when the game should draw itself. /// /// Provides a snapshot of timing values. public override void Draw(GameTime gameTime) { base.Draw(gameTime); foreach (GameComponent gc in mComponents) { EntitySprite s = gc as EntitySprite; if (s != null) { s.Draw(gameTime); } } if (mInputHandler.MouseLocation.X >= 150 && mInputHandler.MouseLocation.X <= 250 && mInputHandler.MouseLocation.Y >= 400 && mInputHandler.MouseLocation.Y <= 435) { mItemSelected = 0; } else if (mInputHandler.MouseLocation.X >= 350 && mInputHandler.MouseLocation.X <= 450 && mInputHandler.MouseLocation.Y >= 400 && mInputHandler.MouseLocation.Y <= 435) { mItemSelected = 1; } else if (mInputHandler.MouseLocation.X >= 550 && mInputHandler.MouseLocation.X <= 650 && mInputHandler.MouseLocation.Y >= 400 && mInputHandler.MouseLocation.Y <= 435) { mItemSelected = 2; } switch (mItemSelected) { case 0: startButton.Texture = Content.Load(@"Texture\StartMouseOver"); //tutorialButton.Texture = Content.Load(@"Texture\Tutorial"); exitButton.Texture = Content.Load(@"Texture\Exit"); break; case 1: //tutorialButton.Texture = Content.Load(@"Texture\TutorialMouseOver"); startButton.Texture = Content.Load(@"Texture\Start"); exitButton.Texture = Content.Load(@"Texture\Exit"); break; case 2: exitButton.Texture = Content.Load(@"Texture\ExitMouseOver"); startButton.Texture = Content.Load(@"Texture\Start"); //tutorialButton.Texture = Content.Load(@"Texture\Tutorial"); break; } if (mCursor.Visible) { mCursor.Draw(gameTime); } } } }