How-to: Roguelike Gamedev with C++ and BearLibTerminal - Setting up

Welcome

Welcome to my tutorial on developing a basic roguelike game using C++ and the BearLibTerminal library. This is the second incarnation of this tutorial, the first one having been made for the Roguelike-dev 2019 code along project. In this version i aim to for a more concise, easier to follow format, while removing some of the bugs that were present in the first edition. Also: the server hosting the first edition no longer exists. This tutorial closely follows the format presented in the python/libtcod tutorial available here.

A note on programming environments

While its true that this project can be completed with nothing but a text editor and the command line, using a full fledged IDE will enhance your programming experience and make your life ALOT easier. Users of macOS and Windows are highly encouraged to look into Microsoft Visual Studio Code. Linux Users may be interested in Atom, KDevelop, or Code::Blocks.

The two C++ compilers used by the majority of developers is the GNU Compiler Collection, and clang. Versions are available for all major operating systems. Windows users of course have the choice of using the Microsoft Visual C++ complier (though it is not free like the others).

All of the code here was developed on macOS using Microsoft Visual Studio Code IDE and the clang compiler. An effort was made for all code to conform to the C++17 standard.

Aside from the C++ Standard Library, the only library we will need is BearLibTerminal which is available: Here

I highly encourage you to read the Design Overview and API reference.

Once you've downloaded BearLibTerminal you can use the following program to test whether your programming environment is set up and working:

#include "BearLibTerminal.h"
using namespace std;

int main(int argc, char *argv[])
{
  char k;
  int x=80, y=40;
  terminal_open();
  terminal_set("window: size=80x40");
  terminal_print(34, 20, "hello, world!");
  terminal_refresh();
  while (true) {
   k = terminal_read();
   if (k == TK_Q)
   {
    break;
   }
  }
  terminal_close();
  return EXIT_SUCCESS;
}

Save this file as main.cpp in the same directory as libBearLibTerminal.dylib and BearLibTerminal.h and To compile and test your program open a terminal window and cd to the folder you saved everything to and type:

g++ --std=c++17 libBearLibTerminal.dylib main.cpp -o roguelike

./roguelike

You should be presented with a black window with the text "hello, world!" in the middle of it. If everything worked as expected, then we're ready to get started.


Leave A Comment