コード例 #1
0
ファイル: Main.cpp プロジェクト: GM2000/Secret
int main(int argc, char *argv[])
{
	camera::Loc.moveTo(0, 200, 0);

	NewWorld.loadWorld(NULL);

	//³õʼ»¯äÖȾÏß³Ì
	if (!initThread(argc, argv))
	{
		return -1;
	}

	//¼ÓÔØBlock
	initBlock();

	renderGroup Test;
	renderGroup VAO;
	location TTT(0, 0, 0);

	unsigned int i = -1;

	while (IsRenderThreadStart)
	{
		//äÖȾ
		NewWorld.refreshVAO();

		Sleep(1);
	}

#ifdef _DEBUG
	_CrtDumpMemoryLeaks();
#endif
}
コード例 #2
0
ファイル: pickup.cpp プロジェクト: BizarreCake/hCraft
	/* 
	 * 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;
	}
コード例 #3
0
ファイル: world.cpp プロジェクト: projectapex/hCraft
	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;
	}
コード例 #4
0
ファイル: shark.cpp プロジェクト: BizarreCake/hCraft
		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;
		}
コード例 #5
0
ファイル: shark.cpp プロジェクト: BizarreCake/hCraft
		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;
		}
コード例 #6
0
ファイル: worldparts.cpp プロジェクト: Fettpet/Hackerorg
/**
 * @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;
}
コード例 #7
0
ファイル: pickle3.cpp プロジェクト: aolivas/boost-python
 static
 boost::python::tuple
 getinitargs(const world& w)
 {
     using namespace boost::python;
     return boost::python::make_tuple(w.get_country());
 }
コード例 #8
0
ファイル: Main.cpp プロジェクト: ChrisMcNealy/Game-Structure
void DarkGDK ( void )
{
	dbSyncOn   ( );
	dbSyncRate ( 60 );
	dbDisableEscapeKey();
	SetCurrentDirectory("GameContents");
	dbSetWindowTitle("Gaming Level");

	int xCord = 0;
	int yCord = 0;
	int direction = 2; //up = 1, down = 2, left = 3, right = 4;
	int finished = 0; //Used to state whether the game has ended
	
	house.setWorld("stage1",xCord,yCord);	
	dbColorBackdrop(dbRGB(0,0,0));
	house.finishedPntr = &finished;

	while ( LoopGDK ( ) && !finished)
	{
		movePersonOrWorld(xCord, yCord, direction);
		//dbCenterText(510,80,dbStr(dbMouseX()));
		//dbCenterText(550,80,dbStr(dbMouseY()));
		// update the screen
		dbSync ( );
	}

	return;
}
コード例 #9
0
ファイル: main.cpp プロジェクト: netpro2k/ChipsC
// The display function
void renderScene(void)              
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	glLoadIdentity();	
	myWorld.draw();
	glutSwapBuffers();	
}
コード例 #10
0
ファイル: worldparts.cpp プロジェクト: Fettpet/Hackerorg
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);
}
コード例 #11
0
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;
    }
}
コード例 #12
0
ファイル: scoped_body.cpp プロジェクト: pmiddend/insula
insula::physics::scoped_body::scoped_body(
	world &w,
	btRigidBody &b)
:
	w(w),
	b(b)
{
	w.add(
		b);
}
コード例 #13
0
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");
}
コード例 #14
0
ファイル: worldparts.cpp プロジェクト: Fettpet/Hackerorg
/**************************************************************************************************
 *                                  getLength
 * ***********************************************************************************************/
uint getWorldPartSize(const world& w, visitedMap& map, const WormPart& p){
    NeighborContainer mustVisited;
    mustVisited.push_back(p);
    uint result(0);

    while(!mustVisited.empty()){
        WormPart cur = mustVisited[mustVisited.size()-1];
        mustVisited.pop_back();
        if((w.getWormMap().getTheHomeFor(cur.getX(), cur.getY()) != 1) && (!map[cur.getX()][cur.getY()])){
            result++;
            map[cur.getX()][cur.getY()] = true;
            NeighborContainer* buffer = w.getNeighborFields(cur);
            for(auto p: *buffer){
                mustVisited.push_back(p);
            }
        }
    }

    return result;
}
コード例 #15
0
ファイル: world.cpp プロジェクト: marcosbento/life
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;
    }
}
コード例 #16
0
ファイル: snow.cpp プロジェクト: NBY/hCraft
		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);
				}
		}
コード例 #17
0
ファイル: world.cpp プロジェクト: marcosbento/life
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;
}
コード例 #18
0
ファイル: worldparts.cpp プロジェクト: Fettpet/Hackerorg
/**
 * @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);
    }
}
コード例 #19
0
ファイル: panel.cpp プロジェクト: aaylward/isim
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);
}
コード例 #20
0
ファイル: world.cpp プロジェクト: marcosbento/life
void
world::randomize(world& w, world::size_t nr_cells)
{
    std::srand(std::time(0));

    for(size_t i = 0; i < nr_cells; ++i)
    {
        // TODO consider using C++ 11 approach, with uniform_int_distribution
        size_t row = std::rand() % w.cols_;
        size_t col = std::rand() % w.rows_;

        w.put_cell(row, col, true);
    }
}
コード例 #21
0
ファイル: world.cpp プロジェクト: projectapex/hCraft
	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);
	}
コード例 #22
0
ファイル: main.cpp プロジェクト: netpro2k/ChipsC
void init()                  
{
	glClearColor(0, 0, 0, 0) ;
	//texture properties
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	
	glShadeModel(GL_SMOOTH) ;
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_DEPTH_TEST);
	myWorld.setup();

}
コード例 #23
0
ファイル: testbed.cpp プロジェクト: envamp/Augmentations
	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));
			}
		}
	}
コード例 #24
0
ファイル: Main.cpp プロジェクト: ChrisMcNealy/Game-Structure
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.
			house.getEvent(direction,xCord,yCord);
		}
	house.updateWorld(xCord,yCord); //Now let's update the world with our new information.
}
コード例 #25
0
ファイル: sand.cpp プロジェクト: hCraft/hCraft
		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 ());
		}
コード例 #26
0
ファイル: sand.cpp プロジェクト: hCraft/hCraft
		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);
						}
				}
		}
コード例 #27
0
ファイル: main.cpp プロジェクト: netpro2k/ChipsC
void keys(int key, int x, int y)
{
	myWorld.checkNewPosition(key);
}
コード例 #28
0
ファイル: shark.cpp プロジェクト: BizarreCake/hCraft
		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);
				}
		}
コード例 #29
0
void unit_vehicle::update(int dt, world &w)
{
    if (hp <= 0)
        return;

    if (m_first_update)
    {
        m_first_update = false;

        if (!m_follow.expired())
        {
            auto f = m_follow.lock();
            vec3 diff = get_pos() - f->get_pos();
            if (diff.length() < m_params.formation_radius)
                m_formation_offset = f->get_rot().rotate_inv(diff);
            else
                m_formation_offset.set(0, 0, -15.0f);
        }

        m_ground = (get_pos().y - w.get_height(get_pos().x, get_pos().z)) < 5.0f;
        if (m_ground)
        {
            //ToDo: gear anim
        }
        else
        {
            if (m_params.speed_min > 0.01f)
                m_vel = get_rot().rotate(vec3::forward() * m_params.speed_cruise);
            m_dpos = vec3();
        }

        return;
    }

    float kdt = dt * 0.001f;

    vec3 target_dir;
    bool has_target = false;

    if (m_target.expired())
    {
        if (m_ai > ai_default && m_target_search != search_none)
        {
            const bool air = m_ai == ai_air_to_air || m_ai == ai_air_multirole,
            ground = m_ai == ai_air_to_ground || m_ai == ai_air_multirole;

            float min_dist = 10000.0f;
            for (int i = 0; i < w.get_planes_count() + w.get_units_count(); ++i)
            {
                object_ptr t;
                if (i < w.get_planes_count())
                {
                    auto p = w.get_plane(i);
                    if (is_ally(p, w))
                        continue;

                    t = p;
                }
                else
                {
                    if (m_target_search == search_player)
                        continue;

                    auto u = w.get_unit(i - w.get_planes_count());
                    if (is_ally(u))
                        continue;

                    t = u;
                }

                if (!t->is_targetable(air, ground))
                    continue;

                const float dist = (t->get_pos() - get_pos()).length();
                if(dist >= min_dist)
                    continue;

                m_target = t;
                min_dist = dist;
            }
        }
    }
    else
    {
        if (m_target.lock()->hp <= 0)
            m_target.reset();
    }

    bool not_path_not_follow = false;

    if (!m_path.empty())
    {
        has_target = true;
        target_dir = m_path.front() - get_pos();
        if (target_dir.length() < m_vel.length() * kdt * m_params.target_radius)
        {
            if (m_path_loop)
                m_path.push_back(m_path.front());
            m_path.pop_front();
            if (m_path.empty())
                has_target = false;
            else
                target_dir = m_path.front() - get_pos();
        }
    }
    else if (!m_follow.expired())
    {
        has_target = true;
        auto f = m_follow.lock();
        target_dir = f->get_pos() + f->get_rot().rotate(m_formation_offset) - (get_pos() + get_vel() * kdt);
        //+ f->get_vel() * kdt //player's plane is already updated, ToDo
    }
    else
        not_path_not_follow = true;

    if (!m_target.expired())
    {
        auto t = m_target.lock();
        const auto dir = t->get_pos() + t->get_rot().rotate(vec3(0, 0, -20.0)) - (get_pos() + get_vel() * kdt);

        if (not_path_not_follow)
        {
            target_dir = dir;
            has_target = true;
        }

        for (auto &wp: m_weapons)
        {
            if (wp.cooldown > 0)
            {
                wp.cooldown -= dt;
                continue;
            }

            if (dir.length() > wp.params.lockon_range)
                continue;

            wp.cooldown = wp.params.reload_time;
            auto m = w.add_missile(wp.params.id.c_str(), wp.mdl);
            if (!m)
                continue;

            m->phys->pos = get_pos();
            m->phys->rot = get_rot();
            m->phys->vel = get_vel();

            m->phys->target_dir = dir;
            m->target = m_target;
        }
    }

    if (has_target)
    {
        const float eps=1.0e-6f;
        const float target_dist = target_dir.length();
        const vec3 v=target_dir / target_dist;
        const float xz_sqdist=v.x*v.x+v.z*v.z;

        const auto rot = get_rot();
        const auto pyr = rot.get_euler();

        const nya_math::angle_rad new_yaw=(xz_sqdist>eps*eps)? (atan2(v.x,v.z)) : pyr.y;
        nya_math::angle_rad new_pitch=(fabsf(v.y)>eps)? (-atan2(v.y,sqrtf(xz_sqdist))) : 0.0f;
        nya_math::angle_rad new_roll;
        if (!m_follow.expired())
            new_roll = m_follow.lock()->get_rot().get_euler().z;

        vec3 pos = get_pos() + m_vel * kdt;
        const float h = w.get_height(pos.x, pos.z);
        if ((new_pitch > 0.0f && pos.y <= h + m_params.height_min) || (new_pitch < 0.0f && pos.y >= h + m_params.height_max))
            new_pitch = 0.0f;

        const auto ideal_rot = quat(new_pitch, new_yaw, new_roll);

        const float angle_diff = rot.rotate(vec3::forward()).angle(target_dir).get_deg();
        if (fabsf(angle_diff) > 0.001f)
        {
            const float turn_k = nya_math::clamp((180.0f / angle_diff) * m_params.turn_speed * kdt, 0.0, 1.0);
            m_render->mdl.set_rot(quat::slerp(rot, ideal_rot, turn_k));
        }

        float speed = m_vel.length();
        float want_speed = target_dist / kdt;
        if (!m_follow.expired())
        {
            const float target_speed = m_follow.lock()->get_vel().length();
            float decel_time = (speed - target_speed) / m_params.decel;
            if (target_dist / (speed + m_params.accel * kdt) < decel_time)
                want_speed = target_speed;
        }

        want_speed = nya_math::clamp(want_speed, m_params.speed_min, std::min(m_params.speed_max, m_speed_limit));
        speed = tend(speed, want_speed, m_params.accel * kdt, m_params.decel * kdt);
        m_vel = get_rot().rotate(vec3(0.0, 0.0, speed));
    }
    else if (m_params.speed_min < 0.01f)
    {
        float speed = m_vel.length();
        if (speed > 0.0f)
        {
            speed = tend(speed, 0.0f, m_params.accel * kdt, m_params.decel * kdt);
            m_vel = get_rot().rotate(vec3(0.0, 0.0, speed));
        }
    }

    vec3 pos = get_pos() + m_vel * kdt;

    const float h = w.get_height(pos.x, pos.z);
    pos.y = nya_math::clamp(pos.y, h + m_params.height_min, h + m_params.height_max); //ToDo

    set_pos(pos);
}
コード例 #30
0
ファイル: testbed.cpp プロジェクト: envamp/Augmentations
	void testbed::initialize(world& world) {
		auto window_rect = window::glwindow::get_current()->get_screen_rect();
		world.get_system<gui_system>().resize(vec2i(window_rect.w, window_rect.h));

		resource_manager.destroy_everything();
		world.delete_all_entities();

		resource_manager.create(assets::texture_id::TEST_CROSSHAIR, std::wstring(L"hypersomnia/gfx/crosshair.png"));
		resource_manager.create(assets::texture_id::TEST_PLAYER, L"hypersomnia/gfx/walk_1.png");
		resource_manager.create(assets::texture_id::TEST_BACKGROUND, L"hypersomnia/gfx/snow_textures/snow3.png");
		resource_manager.create(assets::texture_id::CRATE, L"hypersomnia/gfx/crate2_destroyed.png");
		resource_manager.create(assets::texture_id::CAR_INSIDE, L"hypersomnia/gfx/crate2.png");
		resource_manager.create(assets::texture_id::CAR_FRONT, L"hypersomnia/gfx/crate2.png");

		resource_manager.create(assets::texture_id::MOTORCYCLE_FRONT, L"hypersomnia/gfx/motorcycle_front.png");
		resource_manager.create(assets::texture_id::MOTORCYCLE_INSIDE, L"hypersomnia/gfx/motorcycle_inside.png");

		resource_manager.create(assets::texture_id::TRUCK_FRONT, L"hypersomnia/gfx/truck_front.png");
		resource_manager.create(assets::texture_id::TRUCK_INSIDE, L"hypersomnia/gfx/truck_inside.png");

		resource_manager.create(assets::texture_id::TEST_SPRITE, L"hypersomnia/gfx/frog.png");

		auto& assault_rifle_gui = resource_manager.create(assets::texture_id::ASSAULT_RIFLE, L"hypersomnia/gfx/assault_rifle.png").gui_sprite_def;
		assault_rifle_gui.flip_horizontally = true;
		assault_rifle_gui.flip_vertically = true;

		resource_manager.create(assets::texture_id::SHOTGUN, L"hypersomnia/gfx/shotgun.png");
		auto& magazine_gui = resource_manager.create(assets::texture_id::SAMPLE_MAGAZINE, L"hypersomnia/gfx/magazine.png").gui_sprite_def;
		magazine_gui.rotation_offset = -270;

		auto& suppressor_gui =  resource_manager.create(assets::texture_id::SAMPLE_SUPPRESSOR, L"hypersomnia/gfx/suppressor.png").gui_sprite_def;
		suppressor_gui.flip_horizontally = true;

		resource_manager.create(assets::texture_id::PINK_CHARGE, L"hypersomnia/gfx/pink_charge.png");
		resource_manager.create(assets::texture_id::PINK_SHELL, L"hypersomnia/gfx/pink_shell.png");

		auto& backpack_gui = resource_manager.create(assets::texture_id::BACKPACK, L"hypersomnia/gfx/backpack.png").gui_sprite_def;
		backpack_gui.rotation_offset = -90.f;
		backpack_gui.gui_bbox_expander = vec2(0, 2);

		augs::image attachment_circle_filled;
		attachment_circle_filled.create_filled_circle(16);

		augs::image attachment_circle_border;
		attachment_circle_border.create_circle(16);

		resource_manager.create(assets::texture_id::ATTACHMENT_CIRCLE_FILLED, attachment_circle_filled);
		resource_manager.create(assets::texture_id::ATTACHMENT_CIRCLE_BORDER, attachment_circle_border);

		resource_manager.create(assets::texture_id::CONTAINER_OPEN_ICON, L"hypersomnia/gfx/container_open_icon.png");
		resource_manager.create(assets::texture_id::CONTAINER_CLOSED_ICON, L"hypersomnia/gfx/container_closed_icon.png");

		resource_manager.create(assets::texture_id::GUI_CURSOR, L"hypersomnia/gfx/gui_cursor.png");
		resource_manager.create(assets::texture_id::GUI_CURSOR_ADD, L"hypersomnia/gfx/gui_cursor_add.png");
		resource_manager.create(assets::texture_id::GUI_CURSOR_ERROR, L"hypersomnia/gfx/gui_cursor_error.png");
		resource_manager.create(assets::texture_id::BLANK, L"hypersomnia/gfx/blank.png");
		resource_manager.create(assets::texture_id::SECONDARY_HAND_ICON, L"hypersomnia/gfx/secondary_hand_icon.png");
		resource_manager.create(assets::texture_id::PRIMARY_HAND_ICON, L"hypersomnia/gfx/primary_hand_icon.png");
		resource_manager.create(assets::texture_id::SHOULDER_SLOT_ICON, L"hypersomnia/gfx/shoulder_slot_icon.png");
		resource_manager.create(assets::texture_id::ARMOR_SLOT_ICON, L"hypersomnia/gfx/armor_slot_icon.png");
		resource_manager.create(assets::texture_id::CHAMBER_SLOT_ICON, L"hypersomnia/gfx/chamber_slot_icon.png");
		resource_manager.create(assets::texture_id::DETACHABLE_MAGAZINE_ICON, L"hypersomnia/gfx/detachable_magazine_slot_icon.png");
		resource_manager.create(assets::texture_id::GUN_BARREL_SLOT_ICON, L"hypersomnia/gfx/gun_barrel_slot_icon.png");

		

		auto& font = resource_manager.create(assets::font_id::GUI_FONT);
		font.open("hypersomnia/Kubasta.ttf", 16, L" ABCDEFGHIJKLMNOPRSTUVWXYZQabcdefghijklmnoprstuvwxyzq0123456789.!@#$%^&*()_+-=[];'\\,./{}:\"|<>?");

		resource_manager.create_sprites_indexed(
			assets::texture_id::TORSO_MOVING_FIRST,
			assets::texture_id::TORSO_MOVING_LAST,
			L"hypersomnia/gfx/sprite");

		resource_manager.create(assets::atlas_id::GAME_WORLD_ATLAS,
			resources::manager::atlas_creation_mode::FROM_ALL_TEXTURES
			| resources::manager::atlas_creation_mode::FROM_ALL_FONTS);

		resource_manager.create(assets::shader_id::DEFAULT_VERTEX, L"hypersomnia/shaders/default.vsh", graphics::shader::type::VERTEX);
		resource_manager.create(assets::shader_id::DEFAULT_FRAGMENT, L"hypersomnia/shaders/default.fsh", graphics::shader::type::FRAGMENT);
		resource_manager.create(assets::program_id::DEFAULT, assets::shader_id::DEFAULT_VERTEX, assets::shader_id::DEFAULT_FRAGMENT);

		resource_manager.create_inverse_with_flip(assets::animation_id::TORSO_MOVE,
			assets::texture_id::TORSO_MOVING_FIRST,
			assets::texture_id::TORSO_MOVING_LAST,
			20.0f);

		auto& player_response = resource_manager.create(assets::animation_response_id::TORSO_SET);
		player_response[messages::animation_response_message::MOVE] = assets::animation_id::TORSO_MOVE;

		world_camera = world.create_entity("camera");
		auto crate = world.create_entity("crate");
		auto crate2 = world.create_entity("crate2");
		auto crate3 = world.create_entity("crate3");
		auto crate4 = world.create_entity("crate4");

		for (int x = -4 * 1; x < 4 * 1; ++x)
		{
			auto frog = world.create_entity("frog");
			ingredients::sprite(frog, vec2(100 + x * 40, 400), assets::texture_id::TEST_SPRITE, augs::white, render_layer::DYNAMIC_BODY);
			ingredients::crate_physics(frog);
		}

		auto car = prefabs::create_car(world, components::transform(-300, -600, -90));
		auto car2 = prefabs::create_car(world, components::transform(-800, -600, -90));
		auto car3 = prefabs::create_car(world, components::transform(-1300, -600, -90));

		auto motorcycle = prefabs::create_motorcycle(world, components::transform(0, -600, -90));

		ingredients::camera(world_camera, window_rect.w, window_rect.h);

		auto bg_size = assets::get_size(assets::texture_id::TEST_BACKGROUND);

		for (int x = -4*10; x < 4 * 10; ++x)
			for (int y = -4 * 10; y < 4 * 10; ++y)
			{
				auto background = world.create_entity();
				ingredients::sprite(background, vec2(x, y) * (bg_size + vec2(1500, 550)), assets::texture_id::TEST_BACKGROUND, augs::white, render_layer::GROUND);
				//ingredients::static_crate_physics(background);

				auto street = world.create_entity();
				ingredients::sprite_scalled(street, vec2(x, y) * (bg_size + vec2(1500, 700)) - vec2(1500, 700), 
					vec2(3000, 3000),
					assets::texture_id::TEST_BACKGROUND, augs::gray1, render_layer::UNDER_GROUND);
			}

		const int num_characters = 5;

		for (int i = 0; i < num_characters; ++i) {
			auto crosshair = world.create_entity("crosshair");
			auto character = world.create_entity(typesafe_sprintf("player%x", i));

			ingredients::wsad_character_crosshair(crosshair);
			ingredients::wsad_character(character, crosshair);

			character->get<components::transform>().pos = vec2(i * 100, 0);

			ingredients::wsad_character_physics(character);

			ingredients::character_inventory(character);

			characters.push_back(character);
		}

		ingredients::inject_window_input_to_character(characters[current_character], world_camera);

		ingredients::sprite_scalled(crate, vec2(200, 300), vec2i(100, 100)/3, assets::texture_id::CRATE, augs::white, render_layer::DYNAMIC_BODY);
		ingredients::crate_physics(crate);
		
		ingredients::sprite_scalled(crate2, vec2(400, 400), vec2i(300, 300), assets::texture_id::CRATE, augs::white, render_layer::DYNAMIC_BODY);
		ingredients::crate_physics(crate2);
		
		ingredients::sprite_scalled(crate4, vec2(500, 0), vec2i(100, 100), assets::texture_id::CRATE, augs::white, render_layer::DYNAMIC_BODY);
		ingredients::crate_physics(crate4);

		prefabs::create_sample_suppressor(world, vec2(300, -500));

		prefabs::create_sample_rifle(world, vec2(100, -500));
		prefabs::create_sample_rifle(world, vec2(100, -500 + 50));
		prefabs::create_sample_rifle(world, vec2(100, -500 + 100));
		prefabs::create_sample_magazine(world, vec2(100, -650));
		prefabs::create_sample_magazine(world, vec2(100 - 50, -650));
		prefabs::create_sample_magazine(world, vec2(100 - 100, -650));
		prefabs::create_pink_charge(world, vec2(100, 100));
		prefabs::create_pink_charge(world, vec2(100, -400));
		prefabs::create_pink_charge(world, vec2(150, -400));
		prefabs::create_pink_charge(world, vec2(200, -400));

		auto backpack = prefabs::create_sample_backpack(world, vec2(200, -650));
		prefabs::create_sample_backpack(world, vec2(200, -750));

		input_system::context active_context;
		active_context.map_key_to_intent(window::event::keys::W, intent_type::MOVE_FORWARD);
		active_context.map_key_to_intent(window::event::keys::S, intent_type::MOVE_BACKWARD);
		active_context.map_key_to_intent(window::event::keys::A, intent_type::MOVE_LEFT);
		active_context.map_key_to_intent(window::event::keys::D, intent_type::MOVE_RIGHT);

		active_context.map_event_to_intent(window::event::mousemotion, intent_type::MOVE_CROSSHAIR);
		active_context.map_key_to_intent(window::event::keys::LMOUSE, intent_type::CROSSHAIR_PRIMARY_ACTION);
		active_context.map_key_to_intent(window::event::keys::RMOUSE, intent_type::CROSSHAIR_SECONDARY_ACTION);
		
		active_context.map_key_to_intent(window::event::keys::E, intent_type::USE_BUTTON);
		active_context.map_key_to_intent(window::event::keys::LSHIFT, intent_type::WALK);
		
		active_context.map_key_to_intent(window::event::keys::G, intent_type::THROW_PRIMARY_ITEM);
		active_context.map_key_to_intent(window::event::keys::H, intent_type::HOLSTER_PRIMARY_ITEM);
		
	    active_context.map_key_to_intent(window::event::keys::BACKSPACE, intent_type::SWITCH_LOOK);

		active_context.map_key_to_intent(window::event::keys::LCTRL, intent_type::START_PICKING_UP_ITEMS);
		active_context.map_key_to_intent(window::event::keys::TAB, intent_type::SWITCH_CHARACTER);

		active_context.map_key_to_intent(window::event::keys::SPACE, intent_type::SPACE_BUTTON);
		active_context.map_key_to_intent(window::event::keys::MOUSE4, intent_type::SWITCH_TO_GUI);
		active_context.map_key_to_intent(window::event::keys::LALT, intent_type::SWITCH_TO_GUI);

		auto& input = world.get_system<input_system>();
		input.add_context(active_context);

		if (input.found_recording()) {
			world.parent_overworld.configure_stepping(60.0, 500);
			world.parent_overworld.delta_timer.set_stepping_speed_multiplier(6.00);

			input.replay_found_recording();

			world.get_system<render_system>().enable_interpolation = false;
		}
		else {
			world.parent_overworld.configure_stepping(60.0, 500);
			world.parent_overworld.delta_timer.set_stepping_speed_multiplier(1.0);

			input.record_and_save_this_session();
		}

		draw_bodies.push_back(crate2);
		//draw_bodies.push_back(characters[0]);
		draw_bodies.push_back(backpack);
	}