本文整理汇总了C++中world类的典型用法代码示例。如果您正苦于以下问题:C++ world类的具体用法?C++ world怎么用?C++ world使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了world类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:BizarreCake,项目名称:hCraft,代码行数:62,代码来源:pickup.cpp
示例2: _try_door_nolock
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;
}
开发者ID:projectapex,项目名称:hCraft,代码行数:10,代码来源:world.cpp
示例3: _try_block
static int
_try_block (world &w, int x, int y, int z)
{
int prev_id = w.get_final_block (x, y, z).id;
if (!w.in_bounds (x, y, z) || !_is_water (prev_id))
return -1;
w.queue_update (x, y, z, BT_SHARK);
return prev_id;
}
开发者ID:BizarreCake,项目名称:hCraft,代码行数:10,代码来源:shark.cpp
示例4: _sur_water
static int
_sur_water (world &w, int x, int y, int z)
{
int id;
if (_is_water (id = w.get_final_block (x - 1, y, z).id)) return id;
if (_is_water (id = w.get_final_block (x + 1, y, z).id)) return id;
if (_is_water (id = w.get_final_block (x, y, z - 1).id)) return id;
if (_is_water (id = w.get_final_block (x, y, z + 1).id)) return id;
return 0;
}
开发者ID:BizarreCake,项目名称:hCraft,代码行数:12,代码来源:shark.cpp
示例5: countWorldParts
/**
* @brief countWorldParts: This function count how many parts are in the World
* @param w: The World
* @param blockedWorms: The Worms, that block fields
* @return The Count of seperated Parts in the Map
*/
uint Tools::countWorldParts(const world& w, const WormContainer& blockedWorms){
visitedMap map;
uint result(0);
createVisitedMap(w, map, blockedWorms);
for(uint x=0; x< w.getSizeX(); ++x){
for(uint y=0; y < w.getSizeY(); ++y){
if(map[x][y] == false){
result++;
getWorldPartSize(w,map, WormPart(x,y));
}
}
}
return result;
}
开发者ID:Fettpet,项目名称:Hackerorg,代码行数:21,代码来源:worldparts.cpp
示例6: getinitargs
static
boost::python::tuple
getinitargs(const world& w)
{
using namespace boost::python;
return boost::python::make_tuple(w.get_country());
}
开发者ID:aolivas,项目名称:boost-python,代码行数:7,代码来源:pickle3.cpp
示例7: getWorldPartSize
uint Tools::getWorldPartSize(const world &w, const uint &worms, const WormPart& p){
visitedMap map;
WormContainer wCon;
wCon.push_back(w.getWorm(worms));
createVisitedMap(w, map, wCon);
return getWorldPartSize(w, map, p);
}
开发者ID:Fettpet,项目名称:Hackerorg,代码行数:8,代码来源:worldparts.cpp
示例8: take_damage
void unit::take_damage(int damage, world &w, bool net_src)
{
object::take_damage(damage, w, net_src);
if (hp <= 0 && m_render.is_valid() && m_render->visible)
{
w.spawn_explosion(get_pos(), 30.0f);
m_render->visible = false;
}
}
开发者ID:undefined-darkness,项目名称:open-horizon,代码行数:9,代码来源:units.cpp
示例9:
insula::physics::scoped_body::scoped_body(
world &w,
btRigidBody &b)
:
w(w),
b(b)
{
w.add(
b);
}
开发者ID:pmiddend,项目名称:insula,代码行数:10,代码来源:scoped_body.cpp
示例10: runtime_error
soil_generator::soil_generator(world& w, const ptree& conf)
: terrain_generator_i(w, conf)
, surfacemap_(w.find_area_generator("surface"))
, grass_(find_material("grass"))
, dirt_(find_material("dirt"))
, rock_(find_material("cobblestone"))
, sand_(find_material("sand"))
{
if (surfacemap_ < 0)
throw std::runtime_error("soil_generator requires a surface map");
}
开发者ID:Cosmotronic,项目名称:hexahedra,代码行数:11,代码来源:soil_generator.cpp
示例11:
void
world::write(const world& w, std::ostream& o)
{
for(size_t col = 0; col < w.cols_; ++col)
{
for(size_t row = 0; row < w.rows_; ++row)
{
o << (w.has_cell(row, col) ? 'o' : ' ');
}
o << std::endl;
}
}
开发者ID:marcosbento,项目名称:life,代码行数:12,代码来源:world.cpp
示例12: dis
void
snow::tick (world &w, int x, int y, int z, int extra, 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_SNOW_BLOCK)
return;
int below = w.get_final_block (x, y - 1, z).id;
if (w.get_final_block (x, y - 1, z).id != BT_AIR)
{
if (below == BT_SNOW_BLOCK || below == BT_SNOW_COVER)
w.queue_update (x, y, z, BT_AIR);
else
w.queue_update (x, y, z, BT_SNOW_COVER);
}
else
{
w.queue_update (x, y, z, BT_AIR);
int nx = x, nz = z;
std::uniform_int_distribution<> dis (1, 4);
int d = dis (rnd);
switch (d)
{
case 1: ++ nx; break;
case 2: -- nx; break;
case 3: ++ nz; break;
case 4: -- nz; break;
}
if (w.get_final_block (nx, y - 1, nz) == BT_AIR)
w.queue_update (nx, y - 1, nz, BT_SNOW_BLOCK);
else
w.queue_update (x, y - 1, z, BT_SNOW_BLOCK);
}
}
开发者ID:NBY,项目名称:hCraft,代码行数:39,代码来源:snow.cpp
示例13: w_next
world
world::evolve(const world& w)
{
world w_next(w);
// TODO could this be a bit more object oriented, please?
for(size_t col = 0; col < w.cols_; ++col)
{
for(size_t row = 0; row < w.rows_; ++row)
{
size_t n = w.neighbours(row, col);
if(w.has_cell(row, col))
{
if(n < 2)
{
w_next.put_cell(row, col, false);
}
else if(n == 2 || n == 3)
{
w_next.put_cell(row, col, true);
}
else
{
w_next.put_cell(row, col, false);
}
}
else
{
if(n == 3)
{
w_next.put_cell(row, col, true);
}
}
}
}
return w_next;
}
开发者ID:marcosbento,项目名称:life,代码行数:38,代码来源:world.cpp
示例14: createVisitedMap
/**
* @brief createVisitedMap
* @param w: The Current World: needed for size and blocked fields
* @param map: The Result Map
* @param worms: Worms that block fields
*/
void createVisitedMap(const world& w, visitedMap& map, const WormContainer& worms){
map.clear();
for(uint x=0; x<w.getSizeX(); ++x){
visitedMapInnerContainer innerContainer;
for(uint y=0; y<w.getSizeY(); ++y){
if(w.getWormMap().getTheHomeFor(x,y) == 1){
innerContainer.push_back(true);
} else{
bool found(false);
for(const Worm& wurm: worms){
if(wurm.contains(WormPart(x,y))) {
innerContainer.push_back(true);
found = true;
break;
}
}
if(!found)
innerContainer.push_back(false);
}
}
map.push_back(innerContainer);
}
}
开发者ID:Fettpet,项目名称:Hackerorg,代码行数:29,代码来源:worldparts.cpp
示例15: draw
void panel::draw(const aircraft& a, const world& w)
{
sdl_helper::normal_line_color(0.0, 0.3, 0.4, 0.2, sdl_helper::WHITE);
sdl_helper::normal_line_color(0.4, 0.2, 0.8, 0.2, sdl_helper::WHITE);
sdl_helper::normal_line_color(0.8, 0.2, 1.2, 0.3, sdl_helper::WHITE);
std::map<int, panel_element*>::iterator iter;
for (iter = elements.begin(); iter != elements.end(); iter++)
{
iter->second->draw(a, w);
}
w.draw_moving_map(0.75, 0.75, 0.23, 0.23, a);
}
开发者ID:aaylward,项目名称:isim,代码行数:14,代码来源:panel.cpp
示例16: _door_tick
void
_door_tick (world &w, int x, int y, int z, int data, std::minstd_rand& rnd)
{
int id = data & 0xFFF;
int meta = (data >> 12) & 0xF;
int elapsed = data >> 16;
if (elapsed == 0)
{
_try_door_lock (w, x - 1, y, z, w.get_block (x - 1, y, z));
_try_door_lock (w, x + 1, y, z, w.get_block (x + 1, y, z));
_try_door_lock (w, x, y, z - 1, w.get_block (x, y, z - 1));
_try_door_lock (w, x, y, z + 1, w.get_block (x, y, z + 1));
if (y > 0) _try_door_lock (w, x, y - 1, z, w.get_block (x, y - 1, z));
if (y < 255) _try_door_lock (w, x, y + 1, z, w.get_block (x, y + 1, z));
}
++ elapsed;
if (elapsed == (5 * 4)) // 4 seconds
w.queue_update (x, y, z, id, meta, BE_DOOR);
else
w.queue_physics (x, y, z, id | (meta << 12) | (elapsed << 16),
nullptr, DOOR_TICK_RATE, nullptr, _door_tick);
}
开发者ID:projectapex,项目名称:hCraft,代码行数:24,代码来源:world.cpp
示例17: vec2
void testbed::perform_logic_step(world& world) {
auto inputs = world.get_message_queue<messages::crosshair_intent_message>();
for (auto& it : inputs) {
bool draw = false;
if (it.intent == intent_type::CROSSHAIR_PRIMARY_ACTION) {
keep_drawing = it.pressed_flag;
draw = true;
}
if (draw || (it.intent == intent_type::MOVE_CROSSHAIR && keep_drawing)) {
auto ent = world.create_entity("drawn_sprite");
ingredients::sprite_scalled(ent, it.crosshair_world_pos, vec2(10, 10), assets::texture_id::BLANK);
}
}
auto key_inputs = world.get_message_queue<messages::unmapped_intent_message>();
for (auto& it : key_inputs) {
if (it.intent == intent_type::SWITCH_CHARACTER && it.pressed_flag) {
++current_character;
current_character %= characters.size();
ingredients::inject_window_input_to_character(characters[current_character], world_camera);
}
}
for (auto& tested : draw_bodies) {
auto& s = tested->get<components::physics_definition>();
auto& lines = renderer::get_current().logic_lines;
auto vv = s.fixtures[0].debug_original;
for (int i = 0; i < vv.size(); ++i) {
auto& tt = tested->get<components::transform>();
auto pos = tt.pos;
lines.draw_cyan((pos + vv[i]).rotate(tt.rotation, pos), (pos + vv[(i + 1) % vv.size()]).rotate(tt.rotation, pos));
}
}
}
开发者ID:envamp,项目名称:Augmentations,代码行数:43,代码来源:testbed.cpp
示例18: movePersonOrWorld
void movePersonOrWorld(int &xCord, int &yCord, int &direction) { //This function checks to see which direction you are planning for your character or world to move in, according to your arrow keys. It then checks to see if there are any collisions, or space bar events, and if not, it updates your new position.
if(dbUpKey()==1)
{
direction = 1;
if(dbSpriteFrame(1) < 13) //If our frame for the character is not within its proper regions (In this case, is on a frame that's below our up animation):
{
dbSetSpriteFrame(1,13); //Set the first sprite frame to 13, so we can play through the upwards animation correctly.
}
if(dbShiftKey() == 1)
{
dbPlaySprite(1, 13, 16, 75); //play through our animations (from 13 to 16) with a 75 millisecond delay since we're running.
if(house.checkSpriteCollision(xCord,yCord-3) == 0)
{
yCord -= 3;
}
}
else
{
dbPlaySprite(1, 13, 16, 150); //play through our animations (from 13 to 16) with a 150 millisecond delay because we're walking.
if(house.checkSpriteCollision(xCord,yCord-1) == 0)
{
yCord --;
}
}
}
else if(dbDownKey()==1)
{
direction = 2; //we set our direction variable to 2, which represents the downward motion.
if(dbSpriteFrame(1) > 4) //Like before, if our sprite 1 frame is out of its desired regions, then set it to the correct location.
{
dbSetSpriteFrame(1, 4);
}
if(dbShiftKey() == 1)
{
dbPlaySprite(1, 1, 4, 75);
if(house.checkSpriteCollision(xCord,yCord+3) == 0)
{
yCord += 3;
}
}
else
{
dbPlaySprite(1, 1, 4, 150);
if(house.checkSpriteCollision(xCord,yCord+1) == 0)
{
yCord ++;
}
}
}
else if(dbLeftKey()==1)
{
direction = 3; //Set our variable to 3 which represents leftward motion.
if(dbSpriteFrame(1) < 5 || dbSpriteFrame(1) > 8)
{
dbSetSpriteFrame(1,5);
}
if(dbShiftKey() == 1)
{
dbPlaySprite(1, 5, 8, 75);
if(house.checkSpriteCollision(xCord-3,yCord) == 0)
{
xCord -= 3;
}
}
else
{
dbPlaySprite(1, 5, 8, 150);
if(house.checkSpriteCollision(xCord-1,yCord) == 0)
{
xCord --;
}
}
}
else if(dbRightKey()==1)
{
direction = 4; //Set our variable to 4 which represents rightward motion.
if(dbSpriteFrame(1) < 9 || dbSpriteFrame(1) > 12)
{
dbSetSpriteFrame(1,9);
}
if(dbShiftKey() == 1)
{
dbPlaySprite(1, 9, 12, 75);
if(house.checkSpriteCollision(xCord+3,yCord) == 0)
{
xCord += 3;
}
}
else
{
dbPlaySprite(1, 9, 12, 150);
if(house.checkSpriteCollision(xCord+1,yCord) == 0)
{
xCord ++;
}
}
}
if(dbKeyState(57) == 1){ //If we pressed the space bar, check to see if we have an event associated with that object.
//.........这里部分代码省略.........
开发者ID:ChrisMcNealy,项目名称:Game-Structure,代码行数:101,代码来源:Main.cpp
示例19:
void
sand::on_neighbour_modified (world &w, int x, int y, int z,
int nx, int ny, int nz)
{
w.queue_physics_once (x, y, z, 0, nullptr, this->tick_rate ());
}
开发者ID:hCraft,项目名称:hCraft,代码行数:6,代码来源:sand.cpp
示例20: if
void
sand::tick (world &w, int x, int y, int z, int extra, void *ptr)
{
if (y <= 0)
{ w.queue_update (x, y, z, BT_AIR); return; }
if (w.get_final_block (x, y, z).id != BT_SAND)
return;
int below = w.get_final_block (x, y - 1, z).id;
if (below == BT_AIR)
{
w.queue_update (x, y, z, BT_AIR);
w.queue_update (x, y - 1, z, BT_SAND);
}
else
{
if (w.get_final_block (x - 1, y - 1, z).id == BT_AIR && w.get_final_block (x - 1, y, z).id == BT_AIR)
{
w.queue_update (x, y, z, BT_AIR);
w.queue_update (x - 1, y - 1, z, BT_SAND);
}
else if (w.get_final_block (x + 1, y - 1, z).id == BT_AIR && w.get_final_block (x + 1, y, z).id == BT_AIR)
{
w.queue_update (x, y, z, BT_AIR);
w.queue_update (x + 1, y - 1, z, BT_SAND);
}
else if (w.get_final_block (x, y - 1, z - 1).id == BT_AIR && w.get_final_block (x, y, z - 1).id == BT_AIR)
{
w.queue_update (x, y, z, BT_AIR);
w.queue_update (x, y - 1, z - 1, BT_SAND);
}
else if (w.get_final_block (x, y - 1, z + 1).id == BT_AIR && w.get_final_block (x, y, z + 1).id == BT_AIR)
{
w.queue_update (x, y, z, BT_AIR);
w.queue_update (x, y - 1, z + 1, BT_SAND);
}
}
}
开发者ID:hCraft,项目名称:hCraft,代码行数:38,代码来源:sand.cpp
注:本文中的world类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论