本文整理汇总了C++中world::despawn_entity方法的典型用法代码示例。如果您正苦于以下问题:C++ world::despawn_entity方法的具体用法?C++ world::despawn_entity怎么用?C++ world::despawn_entity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类world
的用法示例。
在下文中一共展示了world::despawn_entity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/*
* Called by the world that's holding the entity every tick (50ms).
* A return value of true will cause the world to destroy the entity.
*/
bool
e_pickup::tick (world &w)
{
if (!valid)
return false;
if (entity::tick (w))
return true;
if (!pickable ())
return false;
// fetch closest player
std::pair<player *, double> closest;
int i = 0;
e_pickup *me = this;
w.get_players ().all (
[&i, me, &closest] (player *pl)
{
if (pl->is_dead ())
return;
double dist = calc_distance_squared (me->pos, pl->pos);
if (i == 0)
closest = {pl, dist};
else
{
if (dist < closest.second)
closest = {pl, dist};
}
++ i;
});
if ((i == 0) || (closest.second > 2.25))
return false;
player *pl = closest.first;
if (!pl) return false;
int r = pl->inv.add (this->data);
if (r == 0)
{
w.get_players ().send_to_all_visible (
packets::play::make_collect_item (this->eid, pl->get_eid ()),
this);
}
this->data.set_amount (r);
pl->send (packets::play::make_sound_effect ("random.pop",
this->pos.x, this->pos.y, this->pos.z, 0.2f, 98));
if (this->data.empty ())
{
this->valid = false;
w.despawn_entity (this);
return true;
}
return false;
}