Roguelike Game in C++17

User Interface.

So far all the Textual information hasn't been getting to the player from within the game. We write it out to console, which is silly.

Goals

Things to accomplish for this section.

  • Status Bar, to show Player's Health
  • Message Log, to show Actions by and around the player
  • Looking at Enemy's Status.

Refactor

C++ Project configuration.

Before we start, I want to refactor some items in out project. First items to refactor is how CMake is configured. To follow some of the recommendation on how CMake is supposed to be used, by *learned peoples*.

I would like to decouple some things from how CMake Project itself. As these settings I use with every project. To this end, there is now a new folder cmake within which exist following two files, vcpkg.cmake and msvc_settings.cmake.

vcpkg.cmake, which will contain CMake script to load the vcpkg toolchain file.

Which we will call from CMakeLists.txt at project root as such, it must be called before we call project command:

Next, the plan is to pull as the MSVC specific settings out of CMakeLists.txt. To do this we will use msvc_settings.cmake. The settings will only be activated if compiler is MSVC. It will setup some defaults for MSVC as well as provide some options for per-project configuration, to enable C++17 or C++20 features in MSVC, default is to use C++17.

And it can be used as such, in root CMakeLists.txt we create a new library interface. Then call the set_msvc_project_configuration function from cmake/msvc_settings.cmake, to set the configuration we want with MSVC.

Next we have to change src/CMakeLists.txt, to remove all the compiler specific stuff, as well as tell CMake to use settings from Library interface from root CMakeLists.txt.

With this done, it makes it easy for us in future to make new projects with similar settings. Anything to ease the pain of project managment in C++.

GitHub Repo

Console drawing cleanup

In order to show the ui, we will create a new console_layer and do all our ui rendering to that. We'd already setup ability to do this several commits ago. However, to make it more clearer to understand, we'll make few changes to how console_layer works.

First of which is to have it store layer position, previously we passed this position in as part of the blit function. Well, we intended to do that, but never utilized it. So we'll remove it from blit function.

And add it to the constructor of console_layer

Update the console.cpp file, as such blit function

and the console_layer constructor

Next we need to modify main.cpp to accomodate the UI aspects. We'll specify new variable to hold UI height and Map<->UI split location.

Create two console_layer objects for map and UI respectively, using above variables. And update the call to generate_map function so it uses proper height.

Add the scafolding for UI drawing in the main loop.

Next we are going to clean up how we call layer drawing functions, such that they don't need to know about game_map, fov_map, or game_entity. To do this we will add new cell type. In order to be able to hold color information we are also going to forward declare TCODColor.

We will remove the two overloaded draw methods from console_layer class, and replace them with draw method that takes in a vector of cell.

console.hpp

console.cpp

In main.cpp we'll update the calls so map_layer.draw is passed a vector via prepare_to_draw function.

Then we'll add the prepare_to_draw function in both game_map.[cpp|hpp] and game_entity.[cpp|hpp] file sets. These functions will basically contain the logic that we had in console.cpp. game_map.hpp

To transform from tile to cell we are using cppitertools's imap functionality. For each element in tiles list, it will give us a cell. game_map.cpp

game_entity.hpp

game_entity.cpp

GitHub Repo

Panels and Status bar

Links

GitHub Repo ╠═══
Home ╠═══
╣ Prev: Combat ╠═══
╣ Next: Items and inventory ╠═══

Author: Neel Raiyani [Roy Fokker]

Created: 2020-04-04 Sat 17:01

Validate