本文整理汇总了C++中Stopwatch::getFloatTime方法的典型用法代码示例。如果您正苦于以下问题:C++ Stopwatch::getFloatTime方法的具体用法?C++ Stopwatch::getFloatTime怎么用?C++ Stopwatch::getFloatTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch::getFloatTime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
// Create a new bullet manager and make it govern the window + 100px padding
BulletManager manager{-100, -100, 840, 680, player};
bool collision{false};
bool frameAdvanceMode{false};
float bestTime{0.0f};
Stopwatch timer;
// Create Font
Font font{"DroidSansFallback.ttf"};
bool running = true;
while (running)
{
SDL_Event e;
while (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
{
running = false;
}
else if (e.type == SDL_KEYDOWN)
{
if (e.key.keysym.sym == SDLK_ESCAPE)
{
running = false;
}
else if (e.key.keysym.sym == SDLK_SPACE)
{
timer.start();
manager.clear();
manager.createBulletFromFile(filename, &origin);
}
else if (e.key.keysym.sym == SDLK_c)
{
collision = !collision;
}
else if (e.key.keysym.sym == SDLK_f)
{
frameAdvanceMode = !frameAdvanceMode;
}
else if (e.key.keysym.sym == SDLK_a)
{
if (frameAdvanceMode)
manager.tick();
}
}
}
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
if (!frameAdvanceMode)
manager.tick();
int x, y;
SDL_GetMouseState(&x, &y);
player.x = x;
player.y = y;
if (manager.checkCollision())
{
manager.vanishAll();
if (timer.getFloatTime() > bestTime)
bestTime = timer.getFloatTime();
timer.stop();
}
glBegin(GL_QUADS);
{
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
glVertex2f(player.x , player.y);
glVertex2f(player.x + player.w, player.y);
glVertex2f(player.x + player.w, player.y + player.h);
glVertex2f(player.x , player.y + player.h);
}
glEnd();
manager.draw();
if (collision)
manager.drawCollision();
glColor4f(0.2f, 0.2f, 0.2f, 1.0f);
font.draw(10.0f, 20.0f, format("Current %.3f", timer.getFloatTime()));
font.draw(10.0f, 40.0f, format("Best %.3f", bestTime));
font.draw(10.0f, 470.0f, "Press Space to Begin");
font.draw(460.0f, 430.0f, "c = toggle collision boxes");
font.draw(460.0f, 450.0f, "f = frame advance mode");
font.draw(460.0f, 470.0f, "a = advance frame");
SDL_GL_SwapWindow(window);
}
SDL_GL_DeleteContext(glContext);
SDL_Quit();
return 0;
}