本文整理汇总了C++中world::queue_physics方法的典型用法代码示例。如果您正苦于以下问题:C++ world::queue_physics方法的具体用法?C++ world::queue_physics怎么用?C++ world::queue_physics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类world
的用法示例。
在下文中一共展示了world::queue_physics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
static bool
_try_door_nolock (world &w, int x, int y, int z, block_data bd)
{
if (bd.ex != BE_DOOR) return false;
w.queue_update_nolock (x, y, z, BT_AIR);
w.queue_physics (x, y, z, bd.id | (bd.meta << 12), nullptr, DOOR_TICK_RATE, nullptr, _door_tick);
return true;
}
示例2: if
void
shark::tick (world &w, int x, int y, int z, int data, void *ptr,
std::minstd_rand& rnd)
{
if (y <= 0)
{ w.queue_update (x, y, z, BT_AIR); return; }
if (w.get_final_block (x, y, z).id != BT_SHARK)
return;
int below = w.get_final_block (x, y - 1, z).id;
if (below == BT_AIR || (_is_water (below) && (w.get_final_block (x, y + 1, z).id == BT_AIR)))
{
w.queue_update (x, y, z, _sur_water (w, x, y, z));
w.queue_update (x, y - 1, z, BT_SHARK);
}
else
{
int nx = x, ny = y, nz = z;
// find closest player
player *target = nullptr;
w.get_players ().all (
[x, y, z, &target] (player *pl)
{
double dx = x - pl->pos.x;
double dy = y - pl->pos.y;
double dz = z - pl->pos.z;
double dm = dx*dx + dy*dy + dz*dz;
if (dm > 6*6)
return;
if (!target)
target = pl;
else
{
double pdx = x - target->pos.x;
double pdy = y - target->pos.y;
double pdz = z - target->pos.z;
if (dm < (pdx*pdx + pdy*pdy + pdz*pdz))
target = pl;
}
});
if (!target)
{
// move around in a random fashion
std::uniform_int_distribution<> dis (0, 5);
switch (dis (rnd))
{
case 0: -- ny; break;
case 1: ++ ny; break;
case 2: -- nz; break;
case 3: ++ nz; break;
case 4: -- nx; break;
case 5: ++ nx; break;
}
}
else
{
if (x < target->pos.x)
{
if (_is_water (w.get_final_block (x + 1, ny, nz).id))
++ nx;
}
else if (x > target->pos.x)
{
if (_is_water (w.get_final_block (x - 1, ny, nz).id))
-- nx;
}
if (y < target->pos.y)
{
if (_is_water (w.get_final_block (nx, y + 1, nz).id))
++ ny;
}
else if (y > target->pos.y)
{
if (_is_water (w.get_final_block (nx, y - 1, nz).id))
-- ny;
}
if (z < target->pos.z)
{
if (_is_water (w.get_final_block (nx, ny, z + 1).id))
++ nz;
}
else if (z > target->pos.z)
{
if (_is_water (w.get_final_block (nx, ny, z - 1).id))
-- nz;
}
}
int prev = _try_block (w, nx, ny, nz);
if (prev == -1)
w.queue_physics (x, y, z, 0, nullptr, this->tick_rate ());
else
w.queue_update (x, y, z, prev, 0, 0, 0, nullptr, nullptr, false);
}
//.........这里部分代码省略.........