Changeset f809ae6 in opengl-game


Ignore:
Timestamp:
Jun 10, 2020, 9:44:02 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master
Children:
6bfd91c
Parents:
699e83a
Message:

Show the score and frame rate on the game screen

Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • gui/game-screen.cpp

    r699e83a rf809ae6  
    99#include "button.hpp"
    1010#include "panel.hpp"
     11#include "ui-value.hpp"
    1112
    1213using namespace std;
     
    2021      Screen(renderer, gameInfo) {
    2122   Panel *statsPanel = new Panel(10, 50, 95, 46, 0x161616FF, this->renderer);
     23
     24   statsPanel->addUIElement(new UIValue(0, 0, "Score: ", this->gameInfo.score,
     25      this->gameInfo.proggyFont, 0xFFFFFFFF, this->renderer));
     26   statsPanel->addUIElement(new UIValue(14, 19, "FPS: ", this->gameInfo.fps,
     27      this->gameInfo.proggyFont, 0xFFFFFFFF, this->renderer));
    2228
    2329   // TODO: Add the button to the panel it's in, not directly to the window
  • makefile

    r699e83a rf809ae6  
    6060
    6161GUI_SRC_FILES = gui/screen.cpp gui/main-screen.cpp gui/game-screen.cpp gui/ui-element.cpp gui/button.cpp gui/panel.cpp
    62 GUI_HEADER_FILES = gui/screen.hpp gui/main-screen.hpp gui/game-screen.hpp gui/ui-element.hpp gui/button.hpp gui/panel.hpp
     62GUI_HEADER_FILES = gui/screen.hpp gui/main-screen.hpp gui/game-screen.hpp gui/ui-element.hpp gui/button.hpp gui/panel.hpp gui/ui-value.hpp
    6363
    6464SRC_FILES = main-vulkan.cpp vulkan-game.cpp crash-logger.cpp logger.cpp vulkan-utils.cpp utils.cpp game-gui-sdl.cpp $(GUI_SRC_FILES)
  • vulkan-game.cpp

    r699e83a rf809ae6  
    4444
    4545   cout << "Vulkan Game" << endl;
     46
     47   this->score = 0;
    4648
    4749   if (initUI(width, height, guiFlags) == RTWO_ERROR) {
     
    674676   curTime = duration<float, seconds::period>(high_resolution_clock::now() - this->startTime).count();
    675677
     678   this->fpsStartTime = curTime;
     679   this->frameCount = 0;
     680
    676681   lastSpawn_asteroid = curTime;
    677682
     
    681686      curTime = duration<float, seconds::period>(high_resolution_clock::now() - this->startTime).count();
    682687      this->elapsedTime = curTime - this->prevTime;
     688
     689      if (curTime - this->fpsStartTime >= 1.0f) {
     690         this->fps = (float)frameCount / (curTime - this->fpsStartTime);
     691
     692         this->frameCount = 0;
     693         this->fpsStartTime = curTime;
     694      }
     695
     696      this->frameCount++;
    683697
    684698      gui->processEvents();
     
    818832      }
    819833
    820       // renderUI();
    821834      currentScreen->renderUI();
    822835
     
    877890            addExplosion(model_mat, 0.5f, curTime);
    878891
    879             // TODO: Increment player's score here
     892            this->score++;
    880893         } else if ((objCenter.z - asteroid.radius) > -NEAR_CLIP) {
    881894            asteroid.ssbo.deleted = true;
     
    10221035
    10231036   VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_explosionPipeline[currentImage], 0, explosion_UBO);
    1024 }
    1025 
    1026 void VulkanGame::renderUI() {
    1027    SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
    1028    SDL_RenderClear(renderer);
    1029 
    1030    SDL_Rect rect = {280, 220, 100, 100};
    1031    SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
    1032    SDL_RenderFillRect(renderer, &rect);
    1033 
    1034    rect = {10, 10, 0, 0};
    1035    SDL_QueryTexture(fontSDLTexture, nullptr, nullptr, &(rect.w), &(rect.h));
    1036    SDL_RenderCopy(renderer, fontSDLTexture, nullptr, &rect);
    1037 
    1038    rect = {10, 80, 0, 0};
    1039    SDL_QueryTexture(imageSDLTexture, nullptr, nullptr, &(rect.w), &(rect.h));
    1040    SDL_RenderCopy(renderer, imageSDLTexture, nullptr, &rect);
    1041 
    1042    SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xFF, 0xFF);
    1043    SDL_RenderDrawLine(renderer, 50, 5, 150, 500);
    1044 
    1045    VulkanUtils::populateVulkanImageFromSDLTexture(device, physicalDevice, commandPool, uiOverlay, renderer,
    1046       sdlOverlayImage, graphicsQueue);
    10471037}
    10481038
  • vulkan-game.hpp

    r699e83a rf809ae6  
    204204      TTF_Font* proggyFont;
    205205
     206      int score;
     207      float fps;
     208
    206209      GraphicsPipeline_Vulkan<OverlayVertex, void*> overlayPipeline;
    207210
     
    345348      float prevTime, elapsedTime;
    346349
     350      float fpsStartTime;
     351      int frameCount;
     352
    347353      float shipSpeed = 0.5f;
    348354      float asteroidSpeed = 2.0f;
     
    363369      void mainLoop();
    364370      void updateScene(uint32_t currentImage);
    365       void renderUI();
    366371      void renderScene();
    367372      void cleanup();
Note: See TracChangeset for help on using the changeset viewer.