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


C++ Stopwatch::getFloatTime方法代码示例

本文整理汇总了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;
}
开发者ID:Noxalus,项目名称:BulletLua,代码行数:101,代码来源:main.cpp


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