"You have 2 minutes to create a maze, the exit from which you need a minute." Kob, "Start"
About a year ago, it became interesting for me to draw a maze, which takes at least some time to complete. I tried to do this for a long time, but I encountered many problems:
From the exit of such a maze was passed to the "one-two."
It was almost always possible to see and understand whether you were going the right way or not.
Drawing a maze took a lot of time.
Then I decided to write a program that will hide what is not supposed to be seen and, at the same time, generate labyrinths. And then he picked up a maze in 3D using OpenGL. And then he added a network, streams and floors. So, meet:
Labyrus is an open cross-platform multi-threaded online game written using OpenGl and Qt.
Legend
The maze consists of "cells". The walls can only stand between the cells. n is the width of the maze n is the length of the labyrinth (the base of the labyrinth is a square), h - the height of the maze. ')
Card generation
First, a hollow die is created. Then a list of all possible walls inside this cube is created in a random order. After that, in turn, trying to add walls. After each addition, the map is checked for connectivity by dfs. Total it turns out a tree.
Evaluation of work time
number of cells: n * n * h , number of walls: 3 * n * n * h , dfs operation time: n ^ 4 * h ^ 2 (I do not optimally store the graph), generation time: O (n ^ 6 * h ^ 3) .
In principle, generation can be significantly accelerated. But:
Too lazy to write.
The card, which takes ~ 10 minutes to complete, is generated in 0.4 s, which, in principle, performs the task. (Justification of laziness)
Labyrinth with h = 1. Developer mode. View from above.
Description of executable files
labyrus-server: generates a maze and waits for a connection.
labyrus-server-gui: GUI to server - for those who do not like the console.
labyrus-client: the client part of the game - the game is in it (requires running server)
labyrus-switchlanguage: to change the language (system default). For those who like apps in% language%. Naturally, only those languages that I have built in (English and Russian) work.
Control
Standard control - arrows and keys [ wasd ].
Chat and commands - press [ enter ] command [ enter ].
A mouse is available in full screen mode.
Switch to full screen mode and back - hot key z .
Open the menu - escape .
On the Control - binoculars. I just was interested to write it.
In developer mode (debug mode), the [ qe ] keys are available - vertical takeoff and landing, without a test of intersections with the walls.
General scheme
First you need to raise the server. Then the players connect to the server. At the moment when the number of players specified on the server is connected, the game begins. All fall down through the walls at the start. Initially you are exit oriented. It is always located on the same floor as you - in the opposite corner. With the --strong parameter no further connections are possible. Wins the player who first reached the exit. After the last player reaches the finish line, a new card is generated and the game is restarted.
System requirements
How to define them, I do not know, but it seems not great. OpenGL hardware acceleration is welcome. (~ 40000 polygons in the largest maze)
Comments
During the writing of the project, I learned a bunch of new things:
Seriously advanced in the development of Qt.
I learned how to work with OpenGl.
I worked with Git, I can say with a clear conscience: Git is not for me. God forgive me Linus.
I realized that it is worthwhile to first somehow design a program, because at some point you have to redo too many things. In particular, the transition from discrete to real coordinates was very painful and took with it the opportunity to build and demolish walls.
I ran into a bunch of interesting and not very bugs. In particular, it was not possible to compile Labyrus on Qt5 under Windows.
I realized that in Linux with dependencies everything is also not so good - they had to be calculated by experience and with the help of similar Qt programs.
Understand how important testers are.
It was very interesting to learn how to write the intersection of objects.
I understand why in games, screen resolutions are usually fixed. In my case, they are not fixed, and the transition to full screen mode occurs without restarting the program. It was hard to implement. In addition, it creates a bunch of bugs that I leave on the conscience of users. That is, if you ran forward and switched to another window - be ready to see how you continue to run.
Wrote a bot that runs a maze. Very interesting how to write really complex bots.
... And also I learned 9 laps of hell debug application, which:
Graphic.
OpenGL.
Qt. (It’s not clear who called this slot, and why the program fell somewhere inside the Qt-part)
Multithreaded
Network.
Cross platform (compile under Linux, not under Windows. But ifdefs are resolved)
Multilingual (Russian + English). Qt, of course, provides a great translation system, but when text is placed in the right area in one language and not in the other, this is terrible.
It consists of many files (loading graphics and intercepting the output of another program). I didn’t understand for a long time why everything works under Windows, while others have white textures. As a result, it turned out that some left-wing libraries were missing.
Requires version control. No, Git, of course, I mastered. But here, how to find out the version in the style of xx.xx.xx-buildxx, I have no idea. So far, normally done only for ArchLinux. There is at least a package creation date.
Authorship
The project was written by me completely, without using any engines, except for:
Skins - thanks to my mom.
The begin2d () end2d () functions are taken from gamedev.ru.