当前位置: 首页>>代码示例>>C++>>正文


C++ CItem::GetActionKey方法代码示例

本文整理汇总了C++中CItem::GetActionKey方法的典型用法代码示例。如果您正苦于以下问题:C++ CItem::GetActionKey方法的具体用法?C++ CItem::GetActionKey怎么用?C++ CItem::GetActionKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CItem的用法示例。


在下文中一共展示了CItem::GetActionKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CheckForItem

void CMap::CheckForItem(int x, int y)
{
	// Go through all of the items to check if we have a match
	for(int i = 0; i < (int)m_vItems.size(); i++)
	{
		CItem *pItem = &m_vItems[i];

		// Check if the player position is the same as the current item
		if(x == pItem->GetIndex().X && y == pItem->GetIndex().Y)
		{
			// Create a new item and then copy the current item's data to the new item
			CItem newItem;
			memcpy(&newItem, pItem, sizeof(CItem));

			// Check if this item has a special key with it
			g_ActionKeys.HandleKey(pItem->GetActionKey());

			// If our inventory isn't full, let's add it, otherwise do nothing
			if(g_Player.GetInventorySize() < kMaxItems)
			{
				// Let's add the new item and then delete it from the map
				g_Player.AddItem(newItem);
				m_vItems.erase(m_vItems.begin() + i);
			}
			return;
		}
	}
}
开发者ID:88er,项目名称:tutorials,代码行数:28,代码来源:Map.cpp

示例2: DeleteTakenItems

void CMap::DeleteTakenItems()
{
	// There are going to be items on the ground that we want to pick up, but
	// we don't want these items to still be there when we come back to that map.
	// To make sure they are gone when we come back, we assign an action key to
	// each item that we put on the map.  Then, when we load a map and HandleMaps()
	// is called, this function is called to delete taken items.  What we do is just
	// go through the items on the map and check to see if their action key is
	// already set to true (or 1 - we use numbers instead of bools for more functionality).
	// If the item's action key is already set, then we delete it from the map.
	// Whenever we pick up an item it's action key is set.  When creating your maps
	// you need to be sure and give an item an action key, or else this won't work.

	// Go through backwards for all of the items and see if they were taken already
	for(int i = (int)m_vItems.size()-1; i >= 0 ; i--)
	{
		// Get the current item
		CItem *pItem = &m_vItems[i];

		// Check if the item's action key was already set (meaning taken), if so, erase it
		if(g_ActionKeys.GetActionKey(pItem->GetActionKey()) != 0)
			m_vItems.erase(m_vItems.begin() + i);
	}
}
开发者ID:Allenjonesing,项目名称:tutorials,代码行数:24,代码来源:Map.cpp


注:本文中的CItem::GetActionKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。