Переглянути джерело

:sparkles: current menu choice is now more obvious, also FPS are shown in the game now

Felix Bytow 1 рік тому
батько
коміт
4e54853e8d
3 змінених файлів з 12 додано та 1 видалено
  1. 1 1
      game/MenuState.hxx
  2. 10 0
      game/PlayingState.cxx
  3. 1 0
      game/PlayingState.hxx

+ 1 - 1
game/MenuState.hxx

@@ -23,7 +23,7 @@ public:
   void render(SDLRenderer& renderer) override;
 
 private:
-  static int constexpr ACTIVE_SIZE_DIFF = 8;
+  static int constexpr ACTIVE_SIZE_DIFF = 32;
 
   static int constexpr BUTTON_HEIGHT = 80;
   static int constexpr BUTTON_WIDTH = 350;

+ 10 - 0
game/PlayingState.cxx

@@ -80,6 +80,7 @@ void PlayingState::on_event(GameStateManager& gsm, SDL_Event const& evt)
 void PlayingState::update(GameStateManager& gsm, std::chrono::milliseconds const delta_time)
 {
   handle_direction_change();
+  fps_ = static_cast<int>(1000.0/static_cast<double>(delta_time.count()));
 
   auto const distance = speed_*static_cast<float>(delta_time.count());
   if (distance>MAX_DISTANCE) {
@@ -179,6 +180,15 @@ void PlayingState::render_ui(SDLRenderer& renderer, SDL_Rect const& playing_fiel
   SDL_RenderCopy(renderer, text, nullptr, &render_quad);
   SDL_DestroyTexture(text);
 
+  auto const fps_text = "Frames per second: "+std::to_string(fps_);
+  text_surface = TTF_RenderText_Solid(font_, fps_text.c_str(), {255, 255, 255, SDL_ALPHA_OPAQUE});
+  text = SDL_CreateTextureFromSurface(renderer, text_surface);
+  SDL_FreeSurface(text_surface);
+  SDL_QueryTexture(text, nullptr, nullptr, &text_width, &text_height);
+  render_quad = {playing_field.x+playing_field.w-text_width, 10, text_width, text_height};
+  SDL_RenderCopy(renderer, text, nullptr, &render_quad);
+  SDL_DestroyTexture(text);
+
   SDL_SetRenderDrawColor(renderer, 249, 95, 0, SDL_ALPHA_OPAQUE);
   SDL_RenderDrawRect(renderer, &playing_field);
 }

+ 1 - 0
game/PlayingState.hxx

@@ -65,6 +65,7 @@ private:
   SDL_FPoint head_{};
   std::deque<SDL_Point> tail_;
   float speed_{0.001f};
+  int fps_{0};
 
   Asset<TTF_Font*> font_;
 };