本文整理汇总了C++中Tile::addThing方法的典型用法代码示例。如果您正苦于以下问题:C++ Tile::addThing方法的具体用法?C++ Tile::addThing怎么用?C++ Tile::addThing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tile
的用法示例。
在下文中一共展示了Tile::addThing方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadHouseItems
bool Houses::LoadHouseItems(Game* game)
{
xmlDocPtr doc;
doc = xmlParseFile((g_config.DATA_DIR + "houseitems.xml").c_str());
if (doc)
{
xmlNodePtr root, tileNode, itemNode;
root = xmlDocGetRootElement(doc);
if (xmlStrcmp(root->name, (const xmlChar*)"houseitems"))
{
xmlFreeDoc(doc);
return false;
}
tileNode = root->children;
while (tileNode)
{
if (strcmp((const char*)tileNode->name, "tile") == 0)
{
int x = atoi((const char*) xmlGetProp(tileNode, (const xmlChar*) "x"));
int y = atoi((const char*) xmlGetProp(tileNode, (const xmlChar*) "y"));
char z = atoi((const char*) xmlGetProp(tileNode, (const xmlChar*) "z"));
Tile *tile = game->getTile(x, y, z);
if (tile)
{
itemNode = tileNode->children;
while (itemNode)
{
if (strcmp((const char*)itemNode->name, "item") == 0)
{
int itemid = atoi((const char*) xmlGetProp(itemNode, (const xmlChar*) "id"));
Item* item = Item::CreateItem(itemid);
if (item)
{
item->unserialize(itemNode);
item->pos = Position(x, y, z);
tile->addThing(item);
Container *container = dynamic_cast<Container*>(item);
if (container)
LoadContainer(itemNode, container);
}
}
itemNode = itemNode->next;
}
}
}
tileNode = tileNode->next;
}
xmlFreeDoc(doc);
return true;
}
return false;
}
示例2: placeCreature
bool Map::placeCreature(Position &pos, Creature* c)
{
Tile* tile = getTile(pos.x, pos.y, pos.z);
bool success = tile && c->canMovedTo(tile);
//bool success = tile!=NULL;
if(!success)
{
for(int cx =pos.x - 1; cx <= pos.x + 1 && !success; cx++) {
for(int cy = pos.y - 1; cy <= pos.y + 1 && !success; cy++){
#ifdef __DEBUG__
std::cout << "search pos x: " << cx <<" y: "<< cy << std::endl;
#endif
tile = getTile(cx, cy, pos.z);
success = tile && c->canMovedTo(tile);
if(success) {
pos.x = cx;
pos.y = cy;
}
}
}
if(!success){
Player *player = dynamic_cast<Player*>(c);
if(player) {
pos.x = c->masterPos.x;
pos.y = c->masterPos.y;
pos.z = c->masterPos.z;
tile = getTile(pos.x, pos.y, pos.z);
success = tile && player->canMovedTo(tile);
}
}
}
if(!success || !tile) {
#ifdef __DEBUG__
std::cout << "Failed to place creature onto map!" << std::endl;
#endif
return false;
}
std::cout << "POS: " << c->pos << std::endl;
tile->addThing(c);
c->pos = pos;
return true;
}