Exemplo n.º 1
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);
        }
        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);
        }