示例#1
0
        //Metod för utritning av spelare
        private void DrawPlayer(float a_elapsedTime)
        {
            if (m_player.IsAlive())
            {
                DrawWeapon(a_elapsedTime, m_player.UnitState, m_player.WeaponState, m_player);
            }
            else
            {
                m_player.UnitState = Model.Unit.IS_DEAD;
            }
            //Ritar spelare
            Vector2 playerPosition = m_camera.VisualizeCordinates(m_player.ThisUnit.Bounds.X, m_player.ThisUnit.Bounds.Y);

            m_animationSystem.UpdateAndDraw(a_elapsedTime, Color.White, playerPosition, m_player.UnitState, AnimationSystem.PLAYER);

            //Börjat leka med armor.
            if (m_player.HasHelm)
            {
                DrawArmor(a_elapsedTime, m_player, m_player.UnitState, AnimationSystem.ARMOR_HEAD);
            }
        }
示例#2
0
        /// <summary>
        /// Method for drawing the player
        /// </summary>
        /// <param name="elapsedTime">Elapsed time in milleseconds</param>
        private void DrawPlayer(float elapsedTime)
        {
            if (_player.IsAlive())
            {
                DrawWeapon(elapsedTime, _player.UnitState, _player.WeaponState, _player);
            }
            else
            {
                _player.UnitState = Model.State.IS_DEAD;
            }

            //Drawing player
            Vector2 playerPosition = _camera.VisualizeCordinates(_player.ThisUnit.Bounds.X, _player.ThisUnit.Bounds.Y);

            _animationSystem.UpdateAndDraw(elapsedTime, Color.White, playerPosition, _player.UnitState, AnimationSystem.Texture.PLAYER);

            //Armor
            if (_player.HasHelm)
            {
                DrawArmor(elapsedTime, _player, _player.UnitState, AnimationSystem.Texture.ARMOR_HEAD);
            }
        }
 internal void UpdateItemSystem(float a_elapsedTime, Model.Player a_player)
 {
     if (a_player.IsAlive())
     {
         //Kan göra 1 item target om man får någonannan lösning på att kolla vilken metod som ska köras i itemsystem.
         //Kollar att spelaren har ett itemtarget, isf läggs det till i backpacken.
         if (a_player.ItemTarget != null && a_player.ItemTarget.WasLooted)
         {
             AddToBackPack(a_player, a_player.ItemTarget);
         }
         //Kollar om spealren har ett backpack target, isf använder / equippar spelaren det.
         if (a_player.BackpackTarget != null)
         {
             EquipOrUse(a_player);
         }
         //Kollar om spelaren har ett charpanel Target, isf läggs det till i backpacken igen.
         if (a_player.CharPanelTarget != null)
         {
             UnEquip(a_player, a_player.CharPanelTarget);
         }
     }
 }
示例#4
0
        internal void UpdateSimulation(float a_elapsedTime)
        {
            Model.Player player = m_gameModel.m_playerSystem.m_player;
            Vector2      moveTo = m_gameView.GetMapMousePosition();

            #region MouseMoveInteraktion


            float xSpeed = 0;
            float ySpeed = 0;

            Rectangle mouseRect = new Rectangle((int)moveTo.X, (int)moveTo.Y, 1, 1);
            if (!player.IsCastingSpell && player.IsAlive())
            {
                if (moveTo != Vector2.Zero)    //Om man håller inne (Right-mouseclick)
                {
                    player.MoveToPosition = moveTo;
                    player.Direction      = new Vector2(moveTo.X - player.ThisUnit.Bounds.Center.X, moveTo.Y - player.ThisUnit.Bounds.Center.Y);
                }
                else if (player.MoveToPosition != Vector2.Zero) //Click 2 move
                {
                    player.Direction = new Vector2(player.MoveToPosition.X - player.ThisUnit.Bounds.Center.X, player.MoveToPosition.Y - player.ThisUnit.Bounds.Center.Y);
                }

                Vector2 newCords = new Vector2();
                Vector2 facing   = new Vector2();

                if (player.Direction != Vector2.Zero && !m_gameModel.m_playerSystem.ArrivedToPosition(player.ThisUnit.Bounds, player.MoveToPosition, 5)) //Om jag rör på mig
                {
                    newCords = player.Direction;
                    newCords.Normalize();
                    newCords.X = newCords.X * 4;
                    newCords.Y = newCords.Y * 4;

                    player.ThisUnit.Bounds.X += (int)newCords.X;
                    player.ThisUnit.Bounds.Y += (int)newCords.Y;
                }
                if (player.Target != null && player.Target.ThisUnit.Bounds.Intersects(player.MaxRangeArea))  // om jag har targetat en unit så sätter jag vilket håll han ska titta åt
                {
                    facing.X = player.Target.ThisUnit.Bounds.Center.X - player.ThisUnit.Bounds.Center.X;
                    facing.Y = player.Target.ThisUnit.Bounds.Center.Y - player.ThisUnit.Bounds.Center.Y;
                }
                else
                {
                    facing = newCords;
                }

                xSpeed = Math.Abs(facing.X);
                ySpeed = Math.Abs(facing.Y);

                if (facing == new Vector2())
                {
                    player.UnitState   = View.AnimationSystem.FACING_CAMERA;
                    player.WeaponState = View.AnimationSystem.MOVING_DOWN;
                }
                if (player.Target != null && player.Target.ThisUnit.Bounds.Intersects(player.MaxRangeArea))
                {
                    if (xSpeed > ySpeed)
                    {
                        if (facing.X > 0f)
                        {
                            player.UnitState   = View.AnimationSystem.FACING_RIGHT;
                            player.WeaponState = View.AnimationSystem.MOVING_RIGHT;
                        }
                        else
                        {
                            player.UnitState   = View.AnimationSystem.FACING_LEFT;
                            player.WeaponState = View.AnimationSystem.MOVING_LEFT;
                        }
                    }
                    else
                    {
                        if (facing.Y > 0f)
                        {
                            player.UnitState   = View.AnimationSystem.FACING_CAMERA;
                            player.WeaponState = View.AnimationSystem.MOVING_DOWN;
                        }
                        else
                        {
                            player.UnitState   = View.AnimationSystem.FACING_AWAY;
                            player.WeaponState = View.AnimationSystem.MOVING_UP;
                        }
                    }
                }
                if (newCords != new Vector2() && !m_gameModel.m_playerSystem.ArrivedToPosition(player.ThisUnit.Bounds, player.MoveToPosition, 5))
                {
                    xSpeed = Math.Abs(newCords.X);
                    ySpeed = Math.Abs(newCords.Y);
                    if (xSpeed > ySpeed)
                    {
                        if (facing.X > 0f)
                        {
                            player.UnitState   = View.AnimationSystem.MOVING_RIGHT;
                            player.WeaponState = player.UnitState;
                        }
                        else
                        {
                            player.UnitState   = View.AnimationSystem.MOVING_LEFT;
                            player.WeaponState = player.UnitState;
                        }
                    }
                    else
                    {
                        if (facing.Y > 0f)
                        {
                            player.UnitState   = View.AnimationSystem.MOVING_DOWN;
                            player.WeaponState = player.UnitState;
                        }
                        else
                        {
                            player.UnitState   = View.AnimationSystem.MOVING_UP;
                            player.WeaponState = player.UnitState;
                        }
                    }
                }
            }
            else if (player.IsCastingSpell)
            {
                player.UnitState = View.AnimationSystem.IS_CASTING_HEAL;
            }
            else
            {
                player.UnitState = View.AnimationSystem.FACING_CAMERA;
            }
            #endregion

            #region ActionBarInteraktion

            if (m_gameView.DidActivateActionBar(View.InputHandler.ACTION_BAR_TWO))
            {
                m_gameModel.m_playerSystem.m_spellSystem.AddSpell(Model.SpellSystem.INSTANT_HEAL, player);
            }

            if (m_gameView.DidActivateActionBar(View.InputHandler.ACTION_BAR_ONE) && m_gameModel.m_playerSystem.m_player.Target != null)
            {
                if (m_gameModel.m_playerSystem.m_player.Target.GetType() == Model.GameModel.ENEMY_NPC)
                {
                    m_gameModel.m_playerSystem.m_spellSystem.AddSpell(Model.SpellSystem.SMITE, player);
                }
            }

            if (m_gameView.DidActivateActionBar(View.InputHandler.BACKPACK))
            {
                if (!player.BackPack.IsOpen)
                {
                    player.BackPack.IsOpen = true;
                }
                else
                {
                    player.BackPack.IsOpen = false;
                }
            }

            if (m_gameView.DidActivateActionBar(View.InputHandler.QUEST_LOG))
            {
                if (!m_gameModel.m_questSystem.IsWatchingQuestLog)
                {
                    m_gameModel.m_questSystem.IsWatchingQuestLog = true;
                }
                else
                {
                    m_gameModel.m_questSystem.IsWatchingQuestLog = false;
                }
            }

            //Öppna stäng worldmap.
            if (m_gameView.DidActivateActionBar(View.InputHandler.WORLD_MAP))
            {
                if (!player.IsLookingAtMap)
                {
                    player.IsLookingAtMap = true;
                }
                else
                {
                    player.IsLookingAtMap = false;
                }
            }

            //Öppna stäng character panel.
            if (m_gameView.DidActivateActionBar(View.InputHandler.CHARACTER_PANEL))
            {
                if (!player.CharPanel.IsOpen)
                {
                    player.CharPanel.IsOpen = true;
                }
                else
                {
                    player.CharPanel.IsOpen = false;
                }
            }
            #endregion

            if (player.Target != null)
            {
                //Gör att spelaren slutar att attackera.
                if (m_gameView.UnTarget())
                {
                    player.IsAttacking = false;
                    player.Target      = null;
                }
            }

            #region FUSK KOD
            ////bli typ odödlig.
            //if (m_gameView.DidPressAndReleaseKey('R'))
            //{
            //    if (m_gameModel.m_playerSystem.m_player.Armor < 90)
            //    {
            //        m_gameModel.m_playerSystem.m_player.Armor = 100;
            //    }
            //}
            ////FULL MANA OCH LIV.
            //if (m_gameView.DidPressAndReleaseKey('F'))
            //{
            //    m_gameModel.m_playerSystem.m_player.CurrentHp = m_gameModel.m_playerSystem.m_player.TotalHp;
            //    m_gameModel.m_playerSystem.m_player.CurrentMana = m_gameModel.m_playerSystem.m_player.TotalMana;
            //}
            ////stänga på och av hinder.
            //if (m_gameView.DidPressAndReleaseKey('T'))
            //{
            //    if (m_gameModel.m_questSystem.CurrentQuestIndex != 2)
            //    {
            //        m_gameModel.m_questSystem.CurrentQuestIndex = 2;
            //        m_gameModel.m_questSystem.CurrentQuest.Status = Model.QuestSystem.END;
            //    }
            //}

            //if (m_gameView.DidPressAndReleaseKey('G'))
            //{
            //    foreach (Model.Enemy e in m_gameModel.m_enemySystem.m_enemies)
            //    {
            //        if (e.Type == Model.Enemy.BOSS_A)
            //        {
            //            m_gameModel.m_playerSystem.m_player.ThisUnit.Bounds.Location = e.ThisUnit.Bounds.Location;
            //        }
            //    }
            //}

            //if (m_gameView.DidPressAndReleaseKey('H'))
            //{
            //    foreach (Model.Friend f in m_gameModel.m_friendSystem.m_friends)
            //    {
            //        if (f.Type == Model.Friend.CITY_GUARD)
            //        {
            //            m_gameModel.m_playerSystem.m_player.ThisUnit.Bounds.Location = f.ThisUnit.Bounds.Location;
            //        }
            //    }
            //}

            //#region GammalKeyboardMove
            ////Flyttar spelaren samt bestämmer animation
            //if (m_gameView.DidPressKey(View.InputHandler.DOWN) && player.CanMoveDown)
            //{
            //    player.ThisUnit.Bounds.Y += Convert.ToInt32(a_elapsedTime * 200);
            //    player.UnitState = View.AnimationSystem.MOVING_DOWN;
            //}
            //if (m_gameView.DidPressKey(View.InputHandler.UP) && player.CanMoveUp)
            //{
            //    player.ThisUnit.Bounds.Y -= Convert.ToInt32(a_elapsedTime * 200);
            //    player.UnitState = View.AnimationSystem.MOVING_UP;
            //}
            //if (m_gameView.DidPressKey(View.InputHandler.RIGHT) && player.CanMoveRight)
            //{
            //    player.ThisUnit.Bounds.X += Convert.ToInt32(a_elapsedTime * 200);
            //    player.UnitState = View.AnimationSystem.MOVING_RIGHT;

            //}
            //if (m_gameView.DidPressKey(View.InputHandler.LEFT) && player.CanMoveLeft)
            //{
            //    player.ThisUnit.Bounds.X -= Convert.ToInt32(a_elapsedTime * 200);
            //    player.UnitState = View.AnimationSystem.MOVING_LEFT;
            //}
            //#endregion
            #endregion

            //Uppdaterar spelmotor
            m_gameModel.UpdateSimulation(a_elapsedTime);
        }
示例#5
0
        /// <summary>
        /// Updating the player movement in relation to the user input.
        /// Updating the GameModel logic.
        /// </summary>
        /// <param name="elapsedTime">Elapsed time in milleseconds</param>
        internal void UpdateSimulation(float elapsedTime)
        {
            Model.Player player         = _gameModel.PlayerSystem.Player;
            Vector2      moveToPosition = _gameView.GetMapMousePosition();

            #region MouseMoveInteraktion

            float xSpeed = 0;
            float ySpeed = 0;

            Rectangle mouseRect = new Rectangle((int)moveToPosition.X, (int)moveToPosition.Y, 1, 1);
            if (!player.IsCastingSpell && player.IsAlive())
            {
                //Holding down right mouse button.
                if (moveToPosition != Vector2.Zero)
                {
                    player.MoveToPosition = moveToPosition;
                    player.Direction      = new Vector2(moveToPosition.X - player.ThisUnit.Bounds.Center.X, moveToPosition.Y - player.ThisUnit.Bounds.Center.Y);
                }
                //Click to move
                else if (player.MoveToPosition != Vector2.Zero)
                {
                    player.Direction = new Vector2(player.MoveToPosition.X - player.ThisUnit.Bounds.Center.X, player.MoveToPosition.Y - player.ThisUnit.Bounds.Center.Y);
                }

                Vector2 newCords = new Vector2();
                Vector2 facing   = new Vector2();

                //If player is moving.
                if (player.Direction != Vector2.Zero && !_gameModel.PlayerSystem.ArrivedToPosition(player.ThisUnit.Bounds, player.MoveToPosition, 5))
                {
                    newCords = player.Direction;
                    newCords.Normalize();
                    newCords.X = newCords.X * 4;
                    newCords.Y = newCords.Y * 4;

                    player.ThisUnit.Bounds.X += (int)newCords.X;
                    player.ThisUnit.Bounds.Y += (int)newCords.Y;
                }
                //If player targeted an unit - set the player state accordingly.
                if (player.Target != null && player.Target.ThisUnit.Bounds.Intersects(player.MaxRangeArea))
                {
                    facing.X = player.Target.ThisUnit.Bounds.Center.X - player.ThisUnit.Bounds.Center.X;
                    facing.Y = player.Target.ThisUnit.Bounds.Center.Y - player.ThisUnit.Bounds.Center.Y;
                }
                else
                {
                    facing = newCords;
                }

                xSpeed = Math.Abs(facing.X);
                ySpeed = Math.Abs(facing.Y);

                if (facing == new Vector2())
                {
                    player.UnitState   = Model.State.FACING_CAMERA;
                    player.WeaponState = Model.State.MOVING_DOWN;
                }
                if (player.Target != null && player.Target.ThisUnit.Bounds.Intersects(player.MaxRangeArea))
                {
                    if (xSpeed > ySpeed)
                    {
                        if (facing.X > 0f)
                        {
                            player.UnitState   = Model.State.FACING_RIGHT;
                            player.WeaponState = Model.State.MOVING_RIGHT;
                        }
                        else
                        {
                            player.UnitState   = Model.State.FACING_LEFT;
                            player.WeaponState = Model.State.MOVING_LEFT;
                        }
                    }
                    else
                    {
                        if (facing.Y > 0f)
                        {
                            player.UnitState   = Model.State.FACING_CAMERA;
                            player.WeaponState = Model.State.MOVING_DOWN;
                        }
                        else
                        {
                            player.UnitState   = Model.State.FACING_AWAY;
                            player.WeaponState = Model.State.MOVING_UP;
                        }
                    }
                }
                if (newCords != new Vector2() && !_gameModel.PlayerSystem.ArrivedToPosition(player.ThisUnit.Bounds, player.MoveToPosition, 5))
                {
                    xSpeed = Math.Abs(newCords.X);
                    ySpeed = Math.Abs(newCords.Y);
                    if (xSpeed > ySpeed)
                    {
                        if (facing.X > 0f)
                        {
                            player.UnitState   = Model.State.MOVING_RIGHT;
                            player.WeaponState = player.UnitState;
                        }
                        else
                        {
                            player.UnitState   = Model.State.MOVING_LEFT;
                            player.WeaponState = player.UnitState;
                        }
                    }
                    else
                    {
                        if (facing.Y > 0f)
                        {
                            player.UnitState   = Model.State.MOVING_DOWN;
                            player.WeaponState = player.UnitState;
                        }
                        else
                        {
                            player.UnitState   = Model.State.MOVING_UP;
                            player.WeaponState = player.UnitState;
                        }
                    }
                }
            }
            else if (player.IsCastingSpell)
            {
                player.UnitState = Model.State.IS_CASTING_HEAL;
            }
            else
            {
                player.UnitState = Model.State.FACING_CAMERA;
            }
            #endregion

            #region ActionBarInteraktion

            if (_gameView.DidActivateActionBar(View.InputHandler.Input.ACTION_BAR_TWO))
            {
                _gameModel.PlayerSystem.SpellSystem.AddSpell(Model.SpellSystem.INSTANT_HEAL, player);
            }

            if (_gameView.DidActivateActionBar(View.InputHandler.Input.ACTION_BAR_ONE) && _gameModel.PlayerSystem.Player.Target != null)
            {
                if (_gameModel.PlayerSystem.Player.Target.GetType() == Model.GameModel.ENEMY_NPC)
                {
                    _gameModel.PlayerSystem.SpellSystem.AddSpell(Model.SpellSystem.SMITE, player);
                }
            }

            if (_gameView.DidActivateActionBar(View.InputHandler.Input.BACKPACK))
            {
                if (!player.BackPack.IsOpen)
                {
                    player.BackPack.IsOpen = true;
                }
                else
                {
                    player.BackPack.IsOpen = false;
                }
            }

            if (_gameView.DidActivateActionBar(View.InputHandler.Input.QUEST_LOG))
            {
                if (!_gameModel.QuestSystem.IsWatchingQuestLog)
                {
                    _gameModel.QuestSystem.IsWatchingQuestLog = true;
                }
                else
                {
                    _gameModel.QuestSystem.IsWatchingQuestLog = false;
                }
            }

            #endregion

            //Opening/closing worldmap.
            if (_gameView.DidActivateActionBar(View.InputHandler.Input.WORLD_MAP))
            {
                if (!player.IsLookingAtMap)
                {
                    player.IsLookingAtMap = true;
                }
                else
                {
                    player.IsLookingAtMap = false;
                }
            }

            //Opening/closing character panel.
            if (_gameView.DidActivateActionBar(View.InputHandler.Input.CHARACTER_PANEL))
            {
                if (!player.CharPanel.IsOpen)
                {
                    player.CharPanel.IsOpen = true;
                }
                else
                {
                    player.CharPanel.IsOpen = false;
                }
            }

            //If player un-targets an enemy - stop attacking.
            if (player.Target != null)
            {
                if (_gameView.DidUnTarget(player))
                {
                    player.IsAttacking = false;
                    player.Target      = null;
                }
            }

            #region DEBUG / CHEAT
            //Immortal.
            //if (m_gameView.DidPressAndReleaseKey('R'))
            //{
            //    if (m_gameModel.mPlayerSystem.m_player.Armor < 90)
            //    {
            //        m_gameModel.mPlayerSystem.m_player.Armor = 100;
            //    }
            //}
            ////Full mana and hp.
            //if (m_gameView.DidPressAndReleaseKey('F'))
            //{
            //    m_gameModel.mPlayerSystem.m_player.CurrentHp = m_gameModel.mPlayerSystem.m_player.TotalHp;
            //    m_gameModel.mPlayerSystem.m_player.CurrentMana = m_gameModel.mPlayerSystem.m_player.TotalMana;
            //}
            ////Obstacles - on/off.
            //if (m_gameView.DidPressAndReleaseKey('T'))
            //{
            //    if (m_gameModel.mQuestSystem.CurrentQuestIndex != 2)
            //    {
            //        m_gameModel.mQuestSystem.CurrentQuestIndex = 2;
            //        m_gameModel.mQuestSystem.CurrentQuest.Status = Model.QuestSystem.END;
            //    }
            //}

            //if (m_gameView.DidPressAndReleaseKey('G'))
            //{
            //    foreach (Model.Enemy e in m_gameModel.mEnemySystem.m_enemies)
            //    {
            //        if (e.Type == Model.Enemy.BOSS_A)
            //        {
            //            m_gameModel.mPlayerSystem.m_player.ThisUnit.Bounds.Location = e.ThisUnit.Bounds.Location;
            //        }
            //    }
            //}

            //if (m_gameView.DidPressAndReleaseKey('H'))
            //{
            //    foreach (Model.Friend f in m_gameModel.m_friendSystem.m_friends)
            //    {
            //        if (f.Type == Model.Friend.CITY_GUARD)
            //        {
            //            m_gameModel.mPlayerSystem.m_player.ThisUnit.Bounds.Location = f.ThisUnit.Bounds.Location;
            //        }
            //    }
            //}
            #endregion

            #region KeyBoardMovement (Not currently used)
            if (_gameView.DidPressKey(View.InputHandler.Input.DOWN) && player.CanMoveDown)
            {
                player.ThisUnit.Bounds.Y += Convert.ToInt32(elapsedTime * 200);
                player.UnitState          = Model.State.MOVING_DOWN;
            }
            if (_gameView.DidPressKey(View.InputHandler.Input.UP) && player.CanMoveUp)
            {
                player.ThisUnit.Bounds.Y -= Convert.ToInt32(elapsedTime * 200);
                player.UnitState          = Model.State.MOVING_UP;
            }
            if (_gameView.DidPressKey(View.InputHandler.Input.RIGHT) && player.CanMoveRight)
            {
                player.ThisUnit.Bounds.X += Convert.ToInt32(elapsedTime * 200);
                player.UnitState          = Model.State.MOVING_RIGHT;
            }
            if (_gameView.DidPressKey(View.InputHandler.Input.LEFT) && player.CanMoveLeft)
            {
                player.ThisUnit.Bounds.X -= Convert.ToInt32(elapsedTime * 200);
                player.UnitState          = Model.State.MOVING_LEFT;
            }
            #endregion

            //Updating game logic.
            _gameModel.Update(elapsedTime);
        }