Example #1
0
void CheckKeyboardInput(const INPUT_RECORD &InputRecord)
{				

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

	// If we have the exit map open, we don't want to allow the user to type in
	// commands because it will screw up the placing of our destination exit.
	// We only want the user to right click to delete the exit if they change their mind.
	// By placing a return here, we won't go through this function if our exit map is open.
	if(g_bExitMapOpen) return;

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

	// If the user hits the escape key
	if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)
	{												
		exit(0);					// Quit the program				
	}								// If the user hits the I key
	else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'I')
	{										
		g_ItemIndex = 0;							// Reset the current index for the item list
		g_pCursorTile = &g_vItems[g_ItemIndex];		// Set the cursor tile to the first item
		g_Map.SetCurrentType(ITEM_TYPE);			// Set the type of list to an item type
	}								// If the user hits the M key
	else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'M')
	{	
		g_MonsterIndex = 0;							// Reset the current index for the monster list
		g_Map.SetCurrentType(MONSTER_TYPE);			// Set the type of list to an monster type
		g_pCursorTile = &g_vMonsters[g_MonsterIndex];  // Set the cursor tile to the first monster
	}								// If the user hits the N key
	else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'N')
	{										
		g_ItemIndex = 0;							// Reset the current index for the npc list
		g_pCursorTile = &g_vNpcs[g_ItemIndex];		// Set the cursor tile to the first npc
		g_Map.SetCurrentType(NPC_TYPE);				// Set the type of list to an npc type
	}								// If the user hits the E key
	else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'E')
	{	
		CHAR_INFO image = {'E', FOREGROUND_RED};	// Create an image for exits

		g_pCursorTile = &g_vTiles[g_vTiles.size() - 1];	// Set the cursor tile to the last tile
		g_pCursorTile->SetChar(image);				// Set the image of our exit tile
		g_Map.SetCurrentType(EXIT_TYPE);			// Set the type of list to an exit type
	}								// If the user hits the space bar
	else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_SPACE)
	{	
		if(g_Map.GetCurrentType() == ITEM_TYPE)		// If we have items selected
		{
			// Use the modulus operator to restrict our index to the size of the item list,
			// then set the cursor tile to the current tile in the item list.
			g_ItemIndex = (g_ItemIndex + 1) % (int)g_vItems.size();
			g_pCursorTile = &g_vItems[g_ItemIndex];
		}
		else if(g_Map.GetCurrentType() == MONSTER_TYPE)	// If the user has the monsters selected
		{
			// Use the modulus operator to restrict our index to the size of the monster list,
			// then set the cursor tile to the current tile in the monster list.
			g_MonsterIndex = (g_MonsterIndex + 1) % (int)g_vMonsters.size();
			g_pCursorTile = &g_vMonsters[g_MonsterIndex];
		}
		else if(g_Map.GetCurrentType() == NPC_TYPE)		// If the user has the npcs selected
		{
			// Use the modulus operator to restrict our index to the size of the npc list,
			// then set the cursor tile to the current tile in the npc list.
			g_NpcIndex = (g_NpcIndex + 1) % (int)g_vNpcs.size();
			g_pCursorTile = &g_vNpcs[g_NpcIndex];
		}
	}	
	// Check if we want to load a new map (Pass in true to LoadOrSaveAMap())
	else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'L')
	{												
		LoadOrSaveAMap(true);						
	}
	// Check if we want to save the current map (Pass in false to LoadOrSaveAMap())
	else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'S')
	{												
		LoadOrSaveAMap(false);
	}


//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////
	
	// So that we don't have to place 1 exit at a time, we added the feature of being
	// able to hold down shift to place many exits before we choose the destination
	// exit.  This makes it so if you want to make a whole side of a map an exit to another
	// map (like out in the forest or open spaces) we can hold down shift and click
	// every character along that side.  Before we place the last exit for that side, we
	// left go of shift and then choose the last exit, which will bring up the prompt
	// to choose the destination point.  If you want the destination map to have the same
	// exit point, just open the exit map and do the same thing for that side, and then
	// choose a point on the first map to end up on, like in the middle of that side.

	// If shift is pressed, let's set our flag to true
	else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT)
		g_bShiftKeyDown = true;

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////


}
Example #2
0
void CheckKeyboardInput(const INPUT_RECORD &InputRecord)
{
    // If the user hits the escape key
    if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)
    {
        exit(0);					// Quit the program
    }								// If the user hits the I key
    else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'I')
    {
        g_ItemIndex = 0;							// Reset the current index for the item list
        g_pCursorTile = &g_vItems[g_ItemIndex];		// Set the cursor tile to the first item
        g_Map.SetCurrentType(ITEM_TYPE);			// Set the type of list to an item type
    }								// If the user hits the M key
    else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'M')
    {
        g_MonsterIndex = 0;							// Reset the current index for the monster list
        g_Map.SetCurrentType(MONSTER_TYPE);			// Set the type of list to an monster type
        g_pCursorTile = &g_vMonsters[g_MonsterIndex];  // Set the cursor tile to the first monster
    }								// If the user hits the N key
    else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'N')
    {
        g_ItemIndex = 0;							// Reset the current index for the npc list
        g_pCursorTile = &g_vNpcs[g_ItemIndex];		// Set the cursor tile to the first npc
        g_Map.SetCurrentType(NPC_TYPE);				// Set the type of list to an npc type
    }								// If the user hits the E key
    else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'E')
    {
        CHAR_INFO image = {'E', FOREGROUND_RED};	// Create an image for exits

        g_pCursorTile->SetChar(image);				// Set the image of our exit tile
        g_pCursorTile = &g_vTiles[g_vTiles.size() - 1];	// Set the cursor tile to the last tile
        g_Map.SetCurrentType(EXIT_TYPE);			// Set the type of list to an exit type
    }								// If the user hits the space bar
    else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_SPACE)
    {
        if(g_Map.GetCurrentType() == ITEM_TYPE)		// If we have items selected
        {
            // Use the modulus operator to restrict our index to the size of the item list,
            // then set the cursor tile to the current tile in the item list.
            g_ItemIndex = (g_ItemIndex + 1) % (int)g_vItems.size();
            g_pCursorTile = &g_vItems[g_ItemIndex];
        }
        else if(g_Map.GetCurrentType() == MONSTER_TYPE)	// If the user has the monsters selected
        {
            // Use the modulus operator to restrict our index to the size of the monster list,
            // then set the cursor tile to the current tile in the monster list.
            g_MonsterIndex = (g_MonsterIndex + 1) % (int)g_vMonsters.size();
            g_pCursorTile = &g_vMonsters[g_MonsterIndex];
        }
        else if(g_Map.GetCurrentType() == NPC_TYPE)		// If the user has the npcs selected
        {
            // Use the modulus operator to restrict our index to the size of the npclist,
            // then set the cursor tile to the current tile in the npc list.
            g_NpcIndex = (g_NpcIndex + 1) % (int)g_vNpcs.size();
            g_pCursorTile = &g_vNpcs[g_NpcIndex];
        }
    }


//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

    // Now that we can load and save, let's add the keyboard functionality to
    // allow the user to do that.  This is done with the 'L' and 'S' key.

    // Check if we want to load a new map (pass in true to LoadOrSaveAMap())
    else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'L')
    {
        LoadOrSaveAMap(true);
    }
    // Check if we want to save the current map (Pass in false to LoadOrSaveAMap())
    else if(InputRecord.Event.KeyEvent.wVirtualKeyCode == 'S')
    {
        LoadOrSaveAMap(false);
    }

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////


}