void HandleGameInput() { // Store the position of the player before we possibly move POINT lastPosition = g_Player.GetLastPosition(); if(g_Input.IsKeyDown(VK_ESCAPE)) // If escape was pressed g_Menu.BringUpMenu(); // Bring up the main menu else if(g_Input.IsKeyDown(VK_UP)) // If up arrow key was pressed g_Player.Move(kUp); // Move the character up else if(g_Input.IsKeyDown(VK_DOWN)) // If down arrow key was pressed g_Player.Move(kDown); // Move the character down else if(g_Input.IsKeyDown(VK_LEFT)) // If left arrow key was pressed g_Player.Move(kLeft); // Move the character left else if(g_Input.IsKeyDown(VK_RIGHT)) // If right arrow key was pressed g_Player.Move(kRight); // Move the character right //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // If we hit space let's toggle on and off the stats at the botton of the screen else if(g_Input.IsKeyDown(VK_SPACE)) g_Map.ToggleStatsFlag(); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Store the new current position of the player POINT curPosition = g_Player.GetPosition(); // Check if the player moved by testing the current position against the last position if(lastPosition.x != curPosition.x || lastPosition.y != curPosition.y) { // We want to draw the screen again if the character moved g_Map.SetDrawFlag(true); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Since we need to pick up items, we need to check for them just like exits, etc. g_Map.CheckForItem(curPosition.x, curPosition.y); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // If we run into an NPC, we need to know so we can display dialog g_Map.CheckForNpc(curPosition.x, curPosition.y); // Set the previous position of the player g_Player.SetLastPosition(curPosition); // Here we check to see if the player moved into an exit. If so, exit! g_Map.CheckForExit(curPosition.x, curPosition.y); } }
void HandleGameInput() { // Store the position of the player before we possibly move POINT lastPosition = g_Player.GetLastPosition(); if(g_Input.IsKeyDown(VK_ESCAPE)) // If escape was pressed g_Menu.BringUpMenu(); // Bring up the main menu else if(g_Input.IsKeyDown(VK_UP)) // If up arrow key was pressed g_Player.Move(kUp); // Move the character up else if(g_Input.IsKeyDown(VK_DOWN)) // If down arrow key was pressed g_Player.Move(kDown); // Move the character down else if(g_Input.IsKeyDown(VK_LEFT)) // If left arrow key was pressed g_Player.Move(kLeft); // Move the character left else if(g_Input.IsKeyDown(VK_RIGHT)) // If right arrow key was pressed g_Player.Move(kRight); // Move the character right else if(g_Input.IsKeyDown(VK_SPACE)) // If space bar was pressed g_Map.ToggleStatsFlag(); // Turn on and off the stats menu // Store the new current position of the player POINT curPosition = g_Player.GetPosition(); // Check if the player moved by testing the current position against the last position if(lastPosition.x != curPosition.x || lastPosition.y != curPosition.y) { //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // This function updates our party to take the last position of the // party member in front of them. If we have 3 players in our party // there will be a domino effect each time the main player moves. The // second player will take the last step of the first player, and the // third player will take the last step of the second player. They follow // you every step of the way... What a loyal party :) g_Player.MoveParty(); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // We want to draw the screen again if the character moved g_Map.SetDrawFlag(true); // Since we need to pick up items, we need to check for them just like exits, etc. g_Map.CheckForItem(curPosition.x, curPosition.y); // If we run into an NPC, we need to know so we can display dialog g_Map.CheckForNpc(curPosition.x, curPosition.y); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Now that we have monsters moving around we need to check to see if we // ran into them so we know when to attack. Notice that this takes no // parameters. This is because we do a loop inside that goes through all // of our party members and checks if they ran into the monster. g_Map.CheckForMonster(); //////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** //////////////////// // Set the previous position of the player g_Player.SetLastPosition(curPosition); // Here we check to see if the player moved into an exit. If so, exit! g_Map.CheckForExit(curPosition.x, curPosition.y); } }