/// <summary>
 /// 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.
 /// </summary>
 protected override void Initialize()
 {
     this.IsMouseVisible = true;
     particleSystem = new ParticleSystem();
     spriteFont = Content.Load<SpriteFont>(@"Game\SpriteFont1");
     damageObject = new Damage();
     screenColor = new Color(0, 0, 0, 0);
     screen = new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
     malePos = new Rectangle(0, 0, graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight);
     femalePos = new Rectangle(graphics.PreferredBackBufferWidth / 2, 0, graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight);
     menu = new Menu.Menu(this);
     ribbon = new Game.Items.Ribbon(new Rectangle(210, 570, 25, 19), "Ribbon", Content.Load<Texture2D>(@"Game\ribbon"), "Map2_A", this);
     base.Initialize();
 }
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            mouse = Mouse.GetState();
            if (gender == null)
            {
                ChooseGender();
            }

            oldState = keyState;
            keyState = Keyboard.GetState();

            if (!transition)
            {
                if (currentGameState == GameState.STARTMENU)
                {
                    startMenu.Update(this);
                }
                else if (currentGameState == GameState.FOREST)
                {
                    forestDialogue.Update();
                }

                if (keyState.IsKeyDown(Keys.Escape) && oldState.IsKeyUp(Keys.Escape) && (currentGameState == GameState.PLAY || currentGameState == GameState.PAUSE || currentGameState == GameState.INTERACT))
                {
                    if (!menu.paused)
                    {
                        menu.paused = true;
                    }
                    else
                        menu.paused = false;
                }
                if (menu.paused)
                {
                    menu.Update(this);
                }
                if (gender != null && !menu.paused)
                {
                    warpManager.Update(this, gameTime);
                    UpdateActiveNpcs();
                    if (testBoss.IsOnMap())
                    {
                        testBoss.Update(this, gameTime);
                    }
                    particleSystem.Update(gameTime);
                    camera.Pos = character.position;
                    if (currentGameState == GameState.PLAY)
                    {
                        character.Update(this, map, gameTime, oldState, GraphicsDevice);
                    }
                    for (int i = 0; i < keys.Count; i++)
                    {
                        if (character.positionRectangle.Intersects(keys[i].position) && map.mapName.Remove(map.mapName.Length - 1) == keys[i].mapName)
                        {
                            keys[i].PickUp(character);
                            keys.RemoveAt(i);
                        }
                    }

                    if (ribbon != null)
                    {
                        if (character.positionRectangle.Intersects(ribbon.position) && ribbon.IsOnMap() && !ribbon.added)
                        {
                            ribbon.PickUp(this);
                        }
                    }
                    character.npcsInRectangle = 0;
                    for (int i = 0; i < activeNpcs.Count; i++)
                    {
                        if (activeNpcs[i].position.Intersects(character.interactRect))
                        {
                            character.npcsInRectangle++;
                        }
                    }
                    for (int i = 0; i < activeNpcs.Count; i++)
                    {
                        if (!activeNpcs[i].isInteracting && activeNpcs[i].IsOnMap() && !character.showInventory)
                        {
                            activeNpcs[i].Update(character, map, this, gameTime);
                        }

                        if (activeNpcs[i].quest != null)
                        {
                            if (activeNpcs[i].quest.accepted)
                            {
                                if (ribbon == null)
                                {
                                    ribbon = new Game.Items.Ribbon(new Rectangle(210, 570, 25, 19), "Ribbon", Content.Load<Texture2D>(@"Game\ribbon"), "Map2_A", this);
                                }
                            }
                        }

                        activeNpcs[i].UpdateDialogue(this);

                        if (keyState.IsKeyDown(Keys.A) && oldState.IsKeyUp(Keys.A) && activeNpcs[i].canInteract
                            && !activeNpcs[i].mob && !character.inCombat && character.npcsInRectangle < 2)
                        {
                            if (activeNpcs[i].isInteracting)
                            {
                                activeNpcs[i].isInteracting = false;
                                activeNpcs[i].dialogue.isTalking = false;
                                activeNpcs[i].dialogue.ResetDialogue();
                                currentGameState = GameState.PLAY;
                            }
                            else
                            {
                                if (activeNpcs[i].quest != null)
                                {
                                    if (character.HasItem(activeNpcs[i].quest.item))
                                    {
                                        activeNpcs[i].quest.Return(this);
                                    }
                                    if (!activeNpcs[i].quest.completed)
                                    {
                                        activeNpcs[i].isInteracting = true;
                                        activeNpcs[i].dialogue.isTalking = true;
                                        currentGameState = GameState.INTERACT;
                                    }
                                }
                                else
                                {
                                    activeNpcs[i].isInteracting = true;
                                    activeNpcs[i].dialogue.isTalking = true;
                                    currentGameState = GameState.INTERACT;
                                }
                            }
                        }
                        if (activeNpcs[i].health <= 0)
                        {
                            if (activeNpcs[i].key != null)
                            {
                                activeNpcs[i].key.position = activeNpcs[i].position;
                                activeNpcs[i].key.position.Width = activeNpcs[i].key.texture.Width;
                                activeNpcs[i].key.position.Height = activeNpcs[i].key.texture.Height;
                                activeNpcs[i].key.label.position.X = activeNpcs[i].key.position.X;
                                activeNpcs[i].key.label.position.Y = activeNpcs[i].key.position.Y - (activeNpcs[i].key.label.position.Height + 2);
                                keys.Add(activeNpcs[i].key);
                                activeNpcs[i].key = null;
                            }
                        }
                    }
                    for (int i = 0; i < Mobs.Count; i++)
                    {
                        Mobs[i].Update(character, map, this, gameTime);
                        if (Mobs[i].remove)
                        {
                            Mobs.RemoveAt(i);
                        }
                    }
                    Mobs = SortNpcsAfterY(Mobs.ToArray()).ToList();
                }
            }
            else
            {
                Transition(5);
            }

            music.Update(gameTime);

            base.Update(gameTime);
        }