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


C++ Tetris::update方法代码示例

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


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

示例1: main

int main(int argc, char *argv[]) {
  ALLEGRO_DISPLAY *display;
  unsigned int ticks = 0;

  if (!al_init()) {
    std::cerr << "[ERROR] Error initializing Allegro" << std::endl;
  }

  display = al_create_display(SCREEN_WIDTH, SCREEN_HEIGHT);

  if (!display) {
    std::cerr << "[ERROR] Error creating Allegro display" << std::endl;
  }

  al_install_audio();
  al_install_keyboard();

  al_init_primitives_addon();
  al_init_acodec_addon();
  al_init_font_addon();
  al_init_ttf_addon();
  al_init_image_addon();

  al_reserve_samples(10);

  srand(time(NULL));

  ALLEGRO_TIMER *timer = al_create_timer(1.0 / FPS);
  ALLEGRO_EVENT_QUEUE *timerQueue = al_create_event_queue();
  al_register_event_source(timerQueue, al_get_timer_event_source(timer));

  al_start_timer(timer);

  Tetris *game = new Tetris(SCREEN_WIDTH, SCREEN_HEIGHT, timerQueue);

  while (game->update(ticks)) {
    game->render();

    ++ticks;
  }

  delete game;

  al_destroy_display(display);
  al_destroy_timer(timer);
  al_destroy_event_queue(timerQueue);

  return 0;
}
开发者ID:jsvana,项目名称:gamejam,代码行数:49,代码来源:main.cpp

示例2: main

int main()
{
	const int FRAMES_PER_SECOND = 25;
    const int SKIP_TICKS = 1000 / FRAMES_PER_SECOND;
	const int MAX_FRAMESKIP = 10;

    unsigned long next_game_tick = GetTickCount();
	int loops = 0;

	Tetris game;
	printf("Game initializing\n");
	game.init();
	
	printf("Game initialized\n");
	View view;
	view.init(game);

    //int sleep_time = 0;
	int quit = 0;

    bool game_is_running = true;
    while( game_is_running ) 
	{
		while( GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) 
		{
			quit = view.getInput();
			next_game_tick += SKIP_TICKS;
			loops++;
		}
		if(quit == 1)
		{
			game.pause();
			quit = 0;
		}
		else if(quit == 2)
		{
			game_is_running = false;
			quit = 0;
		}
		game.update();
        view.update();
    }
	return 0;
}
开发者ID:Royce37,项目名称:OSTetris,代码行数:44,代码来源:main.cpp

示例3: start


//.........这里部分代码省略.........
                        case SDLK_LEFT:
                            moveLeft = true;
                            break;
                        case SDLK_RIGHT:
                            moveRight = true;
                            break;
                        case SDLK_RETURN:
                            projectionMod = !projectionMod;
                        default:
                            break;
                    }
                }
                if (e.type == SDL_KEYUP) {
                    switch( e.key.keysym.sym ) {
                        case SDLK_UP:
                            moveUp = false;
                            break;
                        case SDLK_DOWN:
                            moveDown = false;
                            break;
                        case SDLK_LEFT:
                            moveLeft = false;
                            break;
                        case SDLK_RIGHT:
                            moveRight = false;
                            break;
                        default:
                            break;
                    }
                }
				tetris.handleInput(e);
            }
            
            tetris.update();
            
            if (moveRight) {
                testValX += 0.1f;
            }
            if (moveLeft) {
                testValX -= 0.1f;
            }
            if (moveUp) {
                testValY += 0.1f;
            }
            if (moveDown) {
                testValY -= 0.1f;
            }
            
            prevAngle = angle;
            angle += 0.1f;
            if (angle > 360.f) {
                angle = 0.f;
            }
            
            next_tick += SKIP_TICKS;
            loops++;
        }
        
        interpolation = float(SDL_GetTicks() + SKIP_TICKS - next_tick) / float(SKIP_TICKS);
        
        Projection = glm::perspective(glm::radians(45.0f), _screen.x / _screen.y, 0.1f, 100.0f);
        
        if (projectionMod) {
            Projection = glm::ortho(-10.0f * (_screen.x / _screen.y), 10.0f * (_screen.x / _screen.y), -10.0f, 10.0f, 0.0f, 100.0f);
        }
        
开发者ID:SuperiorJT,项目名称:sdl-tetris,代码行数:66,代码来源:game.cpp


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