internal void UpdateSimulation(float a_elapsedTime)
        {
            //Setting last player location, preventing collission issues
            m_player.SetLastLocation();

            #region Left,Right,Up,Down input controll and status settings

            //Right
            if (m_gameView.DidPressKey(View.InputHandler.Input.MoveRight))
            {
                m_player.Obj.Bounds.X += Convert.ToInt32(a_elapsedTime * m_player.Speed.X);

                if (m_gameModel.Player.PowerUpOneIsActive)
                {
                    m_player.UnitState = Model.State.ID.FLYING_RIGHT;
                }
                else
                {
                    m_player.UnitState = Model.State.ID.MOVING_RIGHT;
                }
            }
            //Left
            else if (m_gameView.DidPressKey(View.InputHandler.Input.MoveLeft))
            {
                m_player.Obj.Bounds.X -= Convert.ToInt32(a_elapsedTime * m_player.Speed.X);

                if (m_gameModel.Player.PowerUpOneIsActive)
                {
                    m_player.UnitState = Model.State.ID.FLYING_LEFT;
                }
                else
                {
                    m_player.UnitState = Model.State.ID.MOVING_LEFT;
                }
            }
            //Up
            else if (m_gameView.DidPressKey(View.InputHandler.Input.ClimbUp) && (m_player.CanClimb || m_player.PowerUpOneIsActive))
            {
                m_player.Obj.Bounds.Y -= Convert.ToInt32(a_elapsedTime * m_player.Speed.X);

                m_player.IsClimbing = true;
                if (!m_gameModel.Player.PowerUpOneIsActive)
                {
                    m_player.UnitState = Model.State.ID.CLIMBING;
                }
            }
            //Down
            else if (m_gameView.DidPressKey(View.InputHandler.Input.ClimbDown) && (m_player.CanClimb || m_player.PowerUpOneIsActive))
            {
                m_player.Obj.Bounds.Y += Convert.ToInt32(a_elapsedTime * m_player.Speed.X);

                m_player.IsClimbing = true;
                if (!m_gameModel.Player.PowerUpOneIsActive)
                {
                    m_player.UnitState = Model.State.ID.CLIMBING;
                }
            }
            //Non-movment states
            else if (!m_player.PowerUpOneIsActive)
            {
                if (m_player.UnitState == Model.State.ID.MOVING_LEFT ||
                    m_player.UnitState == Model.State.ID.FLYING_LEFT)
                {
                    m_player.UnitState = Model.State.ID.FACING_LEFT;
                }
                else if (m_player.UnitState == Model.State.ID.MOVING_RIGHT ||
                         m_player.UnitState == Model.State.ID.FLYING_RIGHT)
                {
                    m_player.UnitState = Model.State.ID.FACING_RIGHT;
                }
                else if (m_player.UnitState == Model.State.ID.CLIMBING)
                {
                    m_player.UnitState = Model.State.ID.FACING_AWAY;
                }
                else if (m_player.UnitState == Model.State.ID.CLIMBING_DOWN)
                {
                    m_player.UnitState = Model.State.ID.FACING_AWAY;
                }
                else if (m_player.UnitState == Model.State.ID.JUMPING_RIGHT)
                {
                    m_player.UnitState = Model.State.ID.FACING_RIGHT;
                }
                else if (m_player.UnitState == Model.State.ID.JUMPING_LEFT)
                {
                    m_player.UnitState = Model.State.ID.FACING_LEFT;
                }
            }

            #endregion

            #region Jump/powerup input controll and status settings

            if (m_gameView.DidPressKey(View.InputHandler.Input.Jump) && !m_player.IsJumping && !m_player.IsFalling)
            {
                m_player.IsJumping = true;
            }
            //Jump-states
            if (m_player.IsJumping == true)
            {
                if (m_player.UnitState == Model.State.ID.FACING_LEFT)
                {
                    m_player.UnitState = Model.State.ID.JUMPING_LEFT;
                }
                else if (m_player.UnitState == Model.State.ID.FACING_RIGHT)
                {
                    m_player.UnitState = Model.State.ID.JUMPING_RIGHT;
                }
                else if (m_player.UnitState == Model.State.ID.MOVING_LEFT)
                {
                    m_player.UnitState = Model.State.ID.JUMPING_LEFT;
                }
                else if (m_player.UnitState == Model.State.ID.MOVING_RIGHT)
                {
                    m_player.UnitState = Model.State.ID.JUMPING_RIGHT;
                }
            }
            //Power-up states
            if (m_player.PowerUpOneIsActive)
            {
                if (m_player.UnitState == Model.State.ID.JUMPING_LEFT ||
                    m_player.UnitState == Model.State.ID.FACING_LEFT)
                {
                    m_player.UnitState = Model.State.ID.FLYING_LEFT;
                }
                if (m_player.UnitState == Model.State.ID.JUMPING_RIGHT ||
                    m_player.UnitState == Model.State.ID.FACING_RIGHT)
                {
                    m_player.UnitState = Model.State.ID.FLYING_RIGHT;
                }
            }

            #endregion

            //Updating gameengine
            m_gameModel.UpdateSimulation(a_elapsedTime);
        }
예제 #2
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);
        }