当前位置: 首页>>代码示例>>C++>>正文


C++ Snake::add_element方法代码示例

本文整理汇总了C++中Snake::add_element方法的典型用法代码示例。如果您正苦于以下问题:C++ Snake::add_element方法的具体用法?C++ Snake::add_element怎么用?C++ Snake::add_element使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Snake的用法示例。


在下文中一共展示了Snake::add_element方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **argv)
{
	std::cout << "Starting SNAKE 2.0" << std::endl;

	srand (time(NULL));

	graphics::init_shadowmap_rotation_matrices();
	graphics::set_window_title(WINDOW_TITLE);
	graphics::set_window_size(WINDOW_WIDTH, WINDOW_HEIGHT);
	graphics::init_sdl();
	if(graphics::init_gl() == -1)
	{
		graphics::destroy();
    	return -1;
	}

	graphics::Light light, light2;
	light.position = math::vec3f(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2, -0.2f);
	light2.position = math::vec3f(WINDOW_WIDTH / 2 + 200, WINDOW_HEIGHT / 2 - 200, -0.2f);
	light.color = math::vec3f(0.0f, 1.0f, 1.0f);
	light2.color = math::vec3f(1.0f, 0.2f, 0.5f);
	light.range = 3;
	light2.range = 3;

	graphics::add_light(&light, 1);
	graphics::add_light(&light2, 1);

	io::init();
	io::add_keyhandler(key_handler);

	fps_timer.start();

	Map map("levels/1/maps/1.map");
	Map map2("levels/1/maps/2.map");

	while(!map.set_food_tile(rand() % (map.get_width() - 1), rand() % (map.get_height() - 1), 1)) {};
	game.add_map(&map, 1);
	game.add_map(&map2, 0);

	portal1.mapx = 13;
	portal1.mapy = 5;

	portal2.mapx = 32;
	portal2.mapy = 17;

	portal1.parent_map = &map;
	portal2.parent_map = &map2;


	printf("&map2: %p\n", &map2);
	//map.add_portals(portal1, portal2, 0);
	//map2.add_portals(portal1, portal2, 0);

	snake.add_element();
	game.add_snake(&snake, 1);
	game.init();

	light_timer.start();

	bool quit = false;
	while(!quit)
    {
    	cap_timer.start();

        while(SDL_PollEvent(&sdl_event) != 0)
        {
        	io::keyboard_update(sdl_event);

      		if(sdl_event.type == SDL_QUIT)
       		{
				quit = true;
       		}
       	}

       	int fps_ticks = fps_timer.get_ticks();
       	float avg_fps = counted_frames / (fps_ticks / 1000.f);
	    if(avg_fps > 2000000) avg_fps = 0;
	    // std::cout << "fps: " << avg_fps << std::endl;


	    if(!quit)
	    {
	       	graphics::clear();

	       	quit = !game.update();
	       	// std::cout << "updated!" << std::endl;
	     	game.render();
	     	// std::cout << "rendered" << std::endl;

	    	graphics::render();
	    	// std::cout << "flipped" << std::endl;
	    }

    	++counted_frames;
    	
    	int frame_ticks = cap_timer.get_ticks();
	    
	    if(frame_ticks < TICKS_PER_FRAME)
	    {
	        SDL_Delay(TICKS_PER_FRAME - frame_ticks);
//.........这里部分代码省略.........
开发者ID:M-Clausen,项目名称:SNAKE2.0,代码行数:101,代码来源:main.cpp


注:本文中的Snake::add_element方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。