//Metod för utritning av backpack
        private void DrawBackpack()
        {
            //För Itemstats
            Vector2 pos = new Vector2();

            Model.Item statsItem = null;

            //Skapar en rektangel för backpacken.
            Rectangle backpackRect = new Rectangle(0, 0, m_textures[BACKPACK].Width, m_textures[BACKPACK].Height);
            Rectangle closeCross   = GetCloseButton(m_player.BackPack.Position.X, m_player.BackPack.Position.Y, BACKPACK);

            //Kollar det här så objektens position hela tiden uppdateras.
            if (m_player.BackPack.IsOpen)
            {
                m_spriteBatch.Draw(m_textures[BACKPACK], new Vector2(m_player.BackPack.Position.X, m_player.BackPack.Position.Y), backpackRect, Color.White);

                if (m_inputHandler.MouseIsOver(new Rectangle((int)m_player.BackPack.Position.X, (int)m_player.BackPack.Position.Y, m_textures[BACKPACK].Bounds.Width, m_textures[BACKPACK].Bounds.Height)))
                {
                    m_inputHandler.MouseIsOverInterface = true;
                }
                if (m_inputHandler.DidGetTargetedByLeftClick(closeCross))
                {
                    m_player.BackPack.IsOpen = false;
                }
            }

            //Skapar en rektangel för item i backpacken.
            Rectangle itemRect = new Rectangle(0, 0, 32, 32);
            int       x        = 12;
            int       y        = 45;

            foreach (Model.Item item in m_player.BackPack.BackpackItems)
            {
                ////Om inte detta körs så blir det lite buggat. inget man ser om man inte ritar ut objektlagret items.
                item.ThisItem.Bounds.X = (int)m_player.BackPack.Position.X + m_camera.GetScreenRectangle.X + x;
                item.ThisItem.Bounds.Y = (int)m_player.BackPack.Position.Y + m_camera.GetScreenRectangle.Y + y;

                Vector2 itemPosition = new Vector2(m_player.BackPack.Position.X + x, m_player.BackPack.Position.Y + y);

                //Kontrollerar att backpacken är öppen.
                if (m_player.BackPack.IsOpen)
                {
                    if (m_inputHandler.DidGetTargetedByLeftClick(m_camera.VisualizeRectangle(item.ThisItem.Bounds)))
                    {
                        m_player.BackpackTarget = item;
                    }

                    //Om typen är en armor.
                    if (item.GetType() == Model.GameModel.ARMOR)
                    {
                        if (item.Type == Model.Armor.HEAD_ARMOR)
                        {
                            m_spriteBatch.Draw(m_textures[HEADARMOR], itemPosition, itemRect, Color.White, 0f, Vector2.Zero, 1.5f, SpriteEffects.None, 0f);
                        }
                    }
                    //Om typen är ett questitem.
                    else if (item.GetType() == Model.GameModel.QUEST_ITEM)
                    {
                        if (item.Type == Model.QuestItem.ENEMY_HEAD)
                        {
                            m_spriteBatch.Draw(m_textures[BOSS_HEAD], itemPosition, itemRect, Color.White, 0f, Vector2.Zero, 1.5f, SpriteEffects.None, 0f);
                        }
                    }
                }

                //Itemplacering i bagen
                x += 50;

                if (x >= m_textures[BACKPACK].Width)
                {
                    y += 50;
                    x  = 0;
                }

                //Kollar om spelaren har musen över ett item. isf så ska stats visas.
                if (m_inputHandler.MouseIsOver(m_camera.VisualizeRectangle(item.ThisItem.Bounds)))
                {
                    pos       = itemPosition;
                    statsItem = item;
                }
            }

            //Om spelaren håller över ett item (kollas i foreachloopen) och backpacken är öppen ritas stats ut.
            if (statsItem != null && m_player.BackPack.IsOpen)
            {
                DrawItemStats(statsItem, pos);
            }

            //Försöker ta bort ett objekt från backpacken och lägga på marken om spealren högerklickar på item i backpacken.
            if (m_player.BackPack.IsOpen)
            {
                for (int i = 0; i < m_player.BackPack.BackpackItems.Count; i++)
                {
                    if (m_inputHandler.DidGetTargetedByRightClick(m_camera.VisualizeRectangle(m_player.BackPack.BackpackItems[i].ThisItem.Bounds)) && m_player.BackPack.BackpackItems[i].GetType() != Model.GameModel.QUEST_ITEM)
                    {
                        m_player.BackPack.BackpackItems[i].ThisItem.Bounds = m_player.ThisUnit.Bounds;
                        m_worldItems.Add(m_player.BackPack.BackpackItems[i]);
                        m_player.BackPack.BackpackItems.Remove(m_player.BackPack.BackpackItems[i]);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Method for drawing the backpack
        /// </summary>
        private void DrawBackpack()
        {
            //For item stats
            Vector2 pos = new Vector2();

            Model.Item statsItem = null;

            //Backpack rectangle
            Rectangle backpackRect = new Rectangle(0, 0, GetTexture(Texture.BACKPACK).Width, GetTexture(Texture.BACKPACK).Height);
            Rectangle closeCross   = GetCloseButton(_player.BackPack.Position.X, _player.BackPack.Position.Y, Texture.BACKPACK);

            if (_player.BackPack.IsOpen)
            {
                _spriteBatch.Draw(GetTexture(Texture.BACKPACK), new Vector2(_player.BackPack.Position.X, _player.BackPack.Position.Y), backpackRect, Color.White);

                if (_inputHandler.MouseIsOver(new Rectangle((int)_player.BackPack.Position.X, (int)_player.BackPack.Position.Y, GetTexture(Texture.BACKPACK).Bounds.Width, GetTexture(Texture.BACKPACK).Bounds.Height)))
                {
                    _inputHandler.MouseIsOverInterface = true;
                }

                if (_inputHandler.DidGetTargetedByLeftClick(closeCross))
                {
                    _player.BackPack.IsOpen = false;
                }
            }

            //Rectangle for items within the backpack
            Rectangle itemRect = new Rectangle(0, 0, 32, 32);
            int       x        = 12;
            int       y        = 45;

            foreach (Model.Item item in _player.BackPack.BackpackItems)
            {
                //Bugfix. Doesnt show if the objectlayer items is not drawn
                item.ThisItem.Bounds.X = (int)_player.BackPack.Position.X + _camera.GetScreenRectangle.X + x;
                item.ThisItem.Bounds.Y = (int)_player.BackPack.Position.Y + _camera.GetScreenRectangle.Y + y;

                Vector2 itemPosition = new Vector2(_player.BackPack.Position.X + x, _player.BackPack.Position.Y + y);

                //If backpack is open
                if (_player.BackPack.IsOpen)
                {
                    if (_inputHandler.DidGetTargetedByLeftClick(_camera.VisualizeRectangle(item.ThisItem.Bounds)))
                    {
                        _player.BackpackTarget = item;
                    }

                    //If type is Armor
                    if (item.GetType() == Model.GameModel.ARMOR)
                    {
                        if (item.Type == Model.Armor.HEAD_ARMOR)
                        {
                            _spriteBatch.Draw(GetTexture(Texture.HEADARMOR), itemPosition, itemRect, Color.White, 0f, Vector2.Zero, 1.5f, SpriteEffects.None, 0f);
                        }
                    }
                    //If type is Questitem.
                    else if (item.GetType() == Model.GameModel.QUEST_ITEM)
                    {
                        if (item.Type == Model.QuestItem.ENEMY_HEAD)
                        {
                            _spriteBatch.Draw(GetTexture(Texture.BOSS_HEAD), itemPosition, itemRect, Color.White, 0f, Vector2.Zero, 1.5f, SpriteEffects.None, 0f);
                        }
                    }
                }

                //Itemplacement in backpack
                x += 50;

                if (x >= GetTexture(Texture.BACKPACK).Width)
                {
                    y += 50;
                    x  = 0;
                }

                //If cursor is hovering item
                if (_inputHandler.MouseIsOver(_camera.VisualizeRectangle(item.ThisItem.Bounds)))
                {
                    pos       = itemPosition;
                    statsItem = item;
                }
            }

            //If player is hovering an item and the backpack is open
            if (statsItem != null && _player.BackPack.IsOpen)
            {
                _common.DrawItemStats(statsItem, pos);
            }

            //Removes the item from the backpack and drops it on the ground @ rightclick
            if (_player.BackPack.IsOpen)
            {
                for (int i = 0; i < _player.BackPack.BackpackItems.Count; i++)
                {
                    if (_inputHandler.DidGetTargetedByRightClick(_camera.VisualizeRectangle(_player.BackPack.BackpackItems[i].ThisItem.Bounds)) && _player.BackPack.BackpackItems[i].GetType() != Model.GameModel.QUEST_ITEM)
                    {
                        _player.BackPack.BackpackItems[i].ThisItem.Bounds = _player.ThisUnit.Bounds;
                        _worldItems.Add(_player.BackPack.BackpackItems[i]);
                        _player.BackPack.BackpackItems.Remove(_player.BackPack.BackpackItems[i]);
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Method for drawing NPCs
        /// </summary>
        /// <param name="elapsedTime">Elapsed time in milleseconds</param>
        private void DrawNPC(float elapsedTime)
        {
            foreach (Model.NonPlayerCharacter friend in _nonPlayerCharacters)
            {
                //Checks wheter the NPC occurs within the camera screen
                if (friend.ThisUnit.Bounds.Intersects(_camera.GetScreenRectangle))
                {
                    friend.CanAddToQuest = true;

                    //Setting the NPC as target on click
                    if (_inputHandler.DidGetTargetedByLeftClick(_camera.VisualizeRectangle(friend.ThisUnit.Bounds)) ||
                        _inputHandler.DidGetTargetedByRightClick(_camera.VisualizeRectangle(friend.ThisUnit.Bounds)))
                    {
                        _player.Target = friend;
                    }

                    Vector2 interactPosition = _camera.VisualizeCordinates(friend.ThisUnit.Bounds.X + 10, friend.ThisUnit.Bounds.Y - 24);
                    int     bubble           = -1;

                    //Drawing dialog box if the NPC ID excists in the XML file for Dialogs
                    if (_conversation.DialogueList.Exists(Message => Message.id == friend.UnitId))
                    {
                        friend.CanInterract = true;
                        bubble = Convert.ToInt32(Texture.INTERACT);
                    }
                    else if ((_questSystem.QuestList.Exists(Quest => _questSystem.ActiveNpc == friend.UnitId && Quest.Id == _questSystem.CurrentQuest.Id)))
                    {
                        friend.CanInterract = true;

                        if (_questSystem.CurrentQuest.Status == Model.QuestSystem.END)
                        {
                            bubble = Convert.ToInt32(Texture.INTERACT_Q_COMPLETE);
                        }
                        else if (_questSystem.CurrentQuest.Status == Model.QuestSystem.PRE)
                        {
                            bubble = Convert.ToInt32(Texture.INTERACT_Q);
                        }
                        else
                        {
                            bubble = Convert.ToInt32(Texture.INTERACT);
                        }
                    }
                    else
                    {
                        friend.CanInterract = false;
                    }

                    if (friend.CanInterract)
                    {
                        _spriteBatch.Draw(_textures[bubble], new Rectangle((int)interactPosition.X, (int)interactPosition.Y, 30, 30), Color.White);
                    }

                    //Drawing NPC
                    Vector2 npcPosition = _camera.VisualizeCordinates(friend.ThisUnit.Bounds.X + 8, friend.ThisUnit.Bounds.Y + 8);
                    AnimationSystem.Texture animation = 0;

                    if (friend.Type == Model.NonPlayerCharacter.OLD_MAN)
                    {
                        animation = AnimationSystem.Texture.OLD_MAN;
                    }
                    else
                    {
                        animation = AnimationSystem.Texture.CITY_GUARD;
                    }

                    //Drawing target circle
                    DrawTargetCircle(_player, friend);
                    _animationSystem.UpdateAndDraw(elapsedTime, Color.White, npcPosition, friend.UnitState, animation);
                }
                else
                {
                    friend.CanAddToQuest = false;
                }
            }
        }
示例#4
0
        //Metod för utritning av friendly NPCs
        private void DrawFriendlyNPC(float a_elapsedTime)
        {
            foreach (Model.Friend friend in m_friends)
            {
                //Kollar att npcn är med på skärmen
                if (friend.ThisUnit.Bounds.Intersects(m_camera.GetScreenRectangle))
                {
                    friend.CanAddToQuest = true;

                    //Om man klickar på FNPC sätts den till spelarens target
                    if (m_inputHandler.DidGetTargetedByLeftClick(m_camera.VisualizeRectangle(friend.ThisUnit.Bounds)) ||
                        m_inputHandler.DidGetTargetedByRightClick(m_camera.VisualizeRectangle(friend.ThisUnit.Bounds)))
                    {
                        m_player.Target = friend;
                    }

                    Vector2 interactPosition = m_camera.VisualizeCordinates(friend.ThisUnit.Bounds.X + 10, friend.ThisUnit.Bounds.Y - 24);
                    int     bubble           = -1;

                    //Ritar ut pratbubbla om NPCns ID ingår i XML filen för konversationer
                    if (m_conversation.m_dialogueList.Exists(Message => Message.id == friend.UnitId))
                    {
                        friend.CanInterract = true;
                        bubble = INTERACT;
                    }
                    else if ((m_questSystem.QuestList.Exists(Quest => m_questSystem.ActiveNpc == friend.UnitId && Quest.Id == m_questSystem.CurrentQuest.Id)))
                    {
                        friend.CanInterract = true;

                        if (m_questSystem.CurrentQuest.Status == Model.QuestSystem.END)
                        {
                            bubble = INTERACT_Q_COMPLETE;
                        }
                        else if (m_questSystem.CurrentQuest.Status == Model.QuestSystem.PRE)
                        {
                            bubble = INTERACT_Q;
                        }
                        else
                        {
                            bubble = INTERACT;
                        }
                    }
                    else
                    {
                        friend.CanInterract = false;
                    }

                    if (friend.CanInterract)
                    {
                        m_spriteBatch.Draw(m_textures[bubble], new Rectangle((int)interactPosition.X, (int)interactPosition.Y, 30, 30), Color.White);
                    }

                    //Ritar NPC
                    Vector2 npcPosition = m_camera.VisualizeCordinates(friend.ThisUnit.Bounds.X + 8, friend.ThisUnit.Bounds.Y + 8);
                    int     animation   = 0;

                    if (friend.Type == Model.Friend.OLD_MAN)
                    {
                        animation = AnimationSystem.NPC_OLD_MAN;
                    }
                    else
                    {
                        animation = AnimationSystem.CITY_GUARD;
                    }

                    //Ritar target ringen.
                    DrawTargetCircle(m_player, friend);
                    m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, npcPosition, friend.UnitState, animation);
                }
                else
                {
                    friend.CanAddToQuest = false;
                }
            }
        }