├── .gitignore ├── .gitmodules ├── .travis.yml ├── CMakeLists.txt ├── COPYING ├── FONT_LICENSE ├── README.md ├── data ├── Noto-Mono-R.ttf ├── Noto-Sans-M.ttf ├── Noto-Sans-R.ttf ├── icon.png ├── style.theme └── wall.obj ├── deb ├── DEBIAN │ ├── control │ ├── copyright │ └── postinst └── usr │ └── share │ └── doc │ └── mazemaze │ └── copyright ├── lib ├── OBJ_Loader.h └── gettext.h ├── locale ├── CMakeLists.txt ├── de │ └── LC_MESSAGES │ │ └── mazemaze.po ├── mazemaze.pot ├── ru │ └── LC_MESSAGES │ │ └── mazemaze.po └── uk │ └── LC_MESSAGES │ └── mazemaze.po ├── mazemaze.desktop.in ├── screenshot.png ├── scripts ├── before_deploy.sh ├── before_script.sh └── script.sh ├── src ├── Camera.cpp ├── Camera.hpp ├── CameraBobbing.cpp ├── CameraBobbing.hpp ├── Chunk.cpp ├── Chunk.hpp ├── FpsCalculator.cpp ├── FpsCalculator.hpp ├── Game.cpp ├── Game.hpp ├── GraphicEngine.cpp ├── GraphicEngine.hpp ├── Gui │ ├── Background.cpp │ ├── Background.hpp │ ├── Gui.cpp │ ├── Gui.hpp │ ├── MainMenu.cpp │ ├── MainMenu.hpp │ ├── State.cpp │ ├── State.hpp │ └── States │ │ ├── About.cpp │ │ ├── About.hpp │ │ ├── Debug.cpp │ │ ├── Debug.hpp │ │ ├── FpsOverlay.cpp │ │ ├── FpsOverlay.hpp │ │ ├── Main.cpp │ │ ├── Main.hpp │ │ ├── NewGame.cpp │ │ ├── NewGame.hpp │ │ ├── Options.cpp │ │ ├── Options.hpp │ │ ├── OptionsControls.cpp │ │ ├── OptionsControls.hpp │ │ ├── OptionsControlsKeyChangeWindow.cpp │ │ ├── OptionsControlsKeys.cpp │ │ ├── OptionsGraphics.cpp │ │ ├── OptionsGraphics.hpp │ │ ├── OptionsMenu.cpp │ │ ├── OptionsMenu.hpp │ │ ├── OptionsOther.cpp │ │ ├── OptionsOther.hpp │ │ ├── Pause.cpp │ │ ├── Pause.hpp │ │ ├── Progress.cpp │ │ ├── Progress.hpp │ │ ├── Win.cpp │ │ └── Win.hpp ├── IRenderable.cpp ├── IRenderable.hpp ├── ITickable.hpp ├── Logger.cpp ├── Logger.hpp ├── Maze.cpp ├── Maze.hpp ├── MazeRenderer.cpp ├── MazeRenderer.hpp ├── MazeRenderers │ ├── Brick.cpp │ ├── Brick.hpp │ ├── Classic.cpp │ ├── Classic.hpp │ ├── Gray.cpp │ ├── Gray.hpp │ ├── NightBrick.cpp │ └── NightBrick.hpp ├── Player.cpp ├── Player.hpp ├── Point.cpp ├── Point.hpp ├── Point2.cpp ├── Point2.hpp ├── Rotation.cpp ├── Rotation.hpp ├── Saver.cpp ├── Saver.hpp ├── Settings.cpp ├── Settings.hpp ├── Skybox.cpp ├── Skybox.hpp ├── StarSky.cpp ├── StarSky.hpp ├── TickableHandler.hpp ├── main.cpp ├── path_separator.hpp ├── utils.cpp └── utils.hpp └── win └── resource.rc /.gitignore: -------------------------------------------------------------------------------- 1 | /* 2 | !.gitignore 3 | !.gitmodules 4 | !/CMakeLists.txt 5 | !/README.md 6 | !/COPYING 7 | !/screenshot.png 8 | !/mazemaze.desktop.in 9 | !/.travis.yml 10 | !/FONT_LICENSE 11 | !/deb 12 | 13 | !/cmake/ 14 | 15 | !/src/ 16 | /src/* 17 | 18 | !/src/*/ 19 | /src/*/* 20 | 21 | !/src/*/*/ 22 | /src/*/*/* 23 | 24 | !/src/*/*/*/ 25 | /src/*/*/*/* 26 | 27 | !/src/*/*/*/*/ 28 | /src/*/*/*/*/* 29 | 30 | !/src/**/*.cpp 31 | !/src/**/*.hpp 32 | 33 | !/data 34 | !/data/** 35 | 36 | !/locale/ 37 | /locale/* 38 | !/locale/CMakeLists.txt 39 | !/locale/*.pot 40 | !/locale/?? 41 | /locale/??/* 42 | !/locale/??/LC_MESSAGES 43 | /locale/??/LC_MESSAGES/*.mo 44 | 45 | !/lib 46 | 47 | !/sfgui 48 | 49 | /deb/DEBIAN/md5sums 50 | /deb/DEBIAN/usr/share/applications/mazemaze.desktop 51 | /deb/opt/* 52 | 53 | !/scripts 54 | !/win 55 | /win/icon.ico 56 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "sfgui"] 2 | path = sfgui 3 | url = https://github.com/TankOs/SFGUI.git 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | addons: 4 | apt_packages: 5 | - cmake 6 | - curl 7 | 8 | os: linux 9 | cache: ccache 10 | dist: focal 11 | 12 | jobs: 13 | include: 14 | - name: "Linux Clang" 15 | compiler: clang-10 16 | env: 17 | - DEPLOY=TRUE 18 | - ARCH=x86_64 19 | - CC_COMPILER=clang-10 20 | - CXX_COMPILER=clang++-10 21 | addons: 22 | apt_packages: 23 | - libxrandr-dev 24 | - libudev-dev 25 | - clang-10 26 | - libgl1-mesa-dev 27 | - libsfml-dev 28 | - libjsoncpp-dev 29 | - curl 30 | - fakeroot 31 | - hashdeep 32 | 33 | - name: "Windows x86_64 static cross-compile" 34 | compiler: gcc 35 | env: 36 | - WINDOWS=TRUE 37 | - DEPLOY=TRUE 38 | - ARCH=x86_64 39 | addons: 40 | apt_packages: 41 | - imagemagick 42 | 43 | - name: "Windows i686 static cross-compile" 44 | if: (tag IS present) OR env(FORCE_DEPLOY) 45 | compiler: gcc 46 | dist: bionic 47 | env: 48 | - WINDOWS=TRUE 49 | - DEPLOY=TRUE 50 | - ARCH=i686 51 | addons: 52 | apt_packages: 53 | - imagemagick 54 | 55 | before_script: 56 | - source scripts/before_script.sh 57 | 58 | script: 59 | - source scripts/script.sh 60 | 61 | before_deploy: 62 | - source scripts/before_deploy.sh 63 | 64 | deploy: 65 | provider: releases 66 | token: $GITHUB_OAUTH_TOKEN 67 | file_glob: true 68 | file: deploy/* 69 | skip_cleanup: true 70 | draft: true 71 | on: 72 | all_branches: true 73 | condition: $DEPLOY = TRUE && (-n $TRAVIS_TAG || $FORCE_DEPLOY = TRUE) 74 | 75 | notifications: 76 | email: false 77 | -------------------------------------------------------------------------------- /FONT_LICENSE: -------------------------------------------------------------------------------- 1 | This Font Software is licensed under the SIL Open Font License, 2 | Version 1.1. 3 | 4 | This license is copied below, and is also available with a FAQ at: 5 | http://scripts.sil.org/OFL 6 | 7 | ----------------------------------------------------------- 8 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 9 | ----------------------------------------------------------- 10 | 11 | PREAMBLE 12 | The goals of the Open Font License (OFL) are to stimulate worldwide 13 | development of collaborative font projects, to support the font 14 | creation efforts of academic and linguistic communities, and to 15 | provide a free and open framework in which fonts may be shared and 16 | improved in partnership with others. 17 | 18 | The OFL allows the licensed fonts to be used, studied, modified and 19 | redistributed freely as long as they are not sold by themselves. The 20 | fonts, including any derivative works, can be bundled, embedded, 21 | redistributed and/or sold with any software provided that any reserved 22 | names are not used by derivative works. The fonts and derivatives, 23 | however, cannot be released under any other type of license. The 24 | requirement for fonts to remain under this license does not apply to 25 | any document created using the fonts or their derivatives. 26 | 27 | DEFINITIONS 28 | "Font Software" refers to the set of files released by the Copyright 29 | Holder(s) under this license and clearly marked as such. This may 30 | include source files, build scripts and documentation. 31 | 32 | "Reserved Font Name" refers to any names specified as such after the 33 | copyright statement(s). 34 | 35 | "Original Version" refers to the collection of Font Software 36 | components as distributed by the Copyright Holder(s). 37 | 38 | "Modified Version" refers to any derivative made by adding to, 39 | deleting, or substituting -- in part or in whole -- any of the 40 | components of the Original Version, by changing formats or by porting 41 | the Font Software to a new environment. 42 | 43 | "Author" refers to any designer, engineer, programmer, technical 44 | writer or other person who contributed to the Font Software. 45 | 46 | PERMISSION & CONDITIONS 47 | Permission is hereby granted, free of charge, to any person obtaining 48 | a copy of the Font Software, to use, study, copy, merge, embed, 49 | modify, redistribute, and sell modified and unmodified copies of the 50 | Font Software, subject to the following conditions: 51 | 52 | 1) Neither the Font Software nor any of its individual components, in 53 | Original or Modified Versions, may be sold by itself. 54 | 55 | 2) Original or Modified Versions of the Font Software may be bundled, 56 | redistributed and/or sold with any software, provided that each copy 57 | contains the above copyright notice and this license. These can be 58 | included either as stand-alone text files, human-readable headers or 59 | in the appropriate machine-readable metadata fields within text or 60 | binary files as long as those fields can be easily viewed by the user. 61 | 62 | 3) No Modified Version of the Font Software may use the Reserved Font 63 | Name(s) unless explicit written permission is granted by the 64 | corresponding Copyright Holder. This restriction only applies to the 65 | primary font name as presented to the users. 66 | 67 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 68 | Software shall not be used to promote, endorse or advertise any 69 | Modified Version, except to acknowledge the contribution(s) of the 70 | Copyright Holder(s) and the Author(s) or with their explicit written 71 | permission. 72 | 73 | 5) The Font Software, modified or unmodified, in part or in whole, 74 | must be distributed entirely under this license, and must not be 75 | distributed under any other license. The requirement for fonts to 76 | remain under this license does not apply to any document created using 77 | the Font Software. 78 | 79 | TERMINATION 80 | This license becomes null and void if any of the above conditions are 81 | not met. 82 | 83 | DISCLAIMER 84 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 85 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 86 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 87 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 88 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 89 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 90 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 91 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 92 | OTHER DEALINGS IN THE FONT SOFTWARE. 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Mazemaze 2 | ======== 3 | [![Build Status](https://app.travis-ci.com/rsxrwscjpzdzwpxaujrr/mazemaze.svg?branch=master)](https://app.travis-ci.com/github/rsxrwscjpzdzwpxaujrr/mazemaze) 4 | 5 | Simple 3D OpenGL first-person maze game. 6 | 7 | ![](screenshot.png) 8 | 9 | ### Install: 10 | You can download the latest version precompiled binaries: 11 | 12 | ##### Windows: 13 | * [Mazemaze_0.2.2_Windows_64bit.zip](https://github.com/rsxrwscjpzdzwpxaujrr/mazemaze/releases/download/v0.2.2/Mazemaze_0.2.2_Windows_64bit.zip) 14 | * [Mazemaze_0.2.2_Windows_32bit.zip](https://github.com/rsxrwscjpzdzwpxaujrr/mazemaze/releases/download/v0.2.2/Mazemaze_0.2.2_Windows_32bit.zip) 15 | 16 | ##### Ubuntu, Debian, etc: 17 | * [mazemaze_0.2.2_amd64.deb](https://github.com/rsxrwscjpzdzwpxaujrr/mazemaze/releases/download/v0.2.2/mazemaze_0.2.2_amd64.deb) 18 | 19 | ##### Other GNU/Linux: 20 | * [Mazemaze_0.2.2_Linux_64bit.tar.gz](https://github.com/rsxrwscjpzdzwpxaujrr/mazemaze/releases/download/v0.2.2/Mazemaze_0.2.2_Linux_64bit.tar.gz) 21 | * Note that in this case, you need to install the dependencies for distribution by yourself (JsonCpp and SFML 2.5 and later) 22 | 23 | You can check checksums of binary packages in [Travis CI logs](https://travis-ci.org/rsxrwscjpzdzwpxaujrr/mazemaze/builds). 24 | 25 | ### Build: 26 | On Arch Linux you can also use a [mazemaze](https://aur.archlinux.org/packages/mazemaze/) and [mazemaze-git](https://aur.archlinux.org/packages/mazemaze-git/) AUR packages instead. 27 | 28 | First you need to install build dependencies: 29 | * Ubuntu, Debian, etc: 30 | ``` 31 | $ sudo apt install libsfml-dev libjsoncpp-dev 32 | ``` 33 | 34 | * Arch Linux: 35 | ``` 36 | $ sudo pacman -S sfml jsoncpp 37 | ``` 38 | 39 | Then you can proceed with the build: 40 | ``` 41 | $ git clone https://github.com/rsxrwscjpzdzwpxaujrr/mazemaze.git 42 | $ cd mazemaze 43 | $ mkdir build 44 | $ cd build 45 | $ cmake .. 46 | $ make 47 | ``` 48 | 49 | You can also install the game after this: 50 | ``` 51 | $ sudo make install 52 | ``` 53 | -------------------------------------------------------------------------------- /data/Noto-Mono-R.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsxrwscjpzdzwpxaujrr/mazemaze/84099dc9c46180aec276c810cbbea5b85b0bb8c3/data/Noto-Mono-R.ttf -------------------------------------------------------------------------------- /data/Noto-Sans-M.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsxrwscjpzdzwpxaujrr/mazemaze/84099dc9c46180aec276c810cbbea5b85b0bb8c3/data/Noto-Sans-M.ttf -------------------------------------------------------------------------------- /data/Noto-Sans-R.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsxrwscjpzdzwpxaujrr/mazemaze/84099dc9c46180aec276c810cbbea5b85b0bb8c3/data/Noto-Sans-R.ttf -------------------------------------------------------------------------------- /data/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsxrwscjpzdzwpxaujrr/mazemaze/84099dc9c46180aec276c810cbbea5b85b0bb8c3/data/icon.png -------------------------------------------------------------------------------- /data/style.theme: -------------------------------------------------------------------------------- 1 | Window { 2 | BackgroundColor: #2D2D2DE0; 3 | } 4 | 5 | Window.light { 6 | BackgroundColor: #2F2F2FFF; 7 | } 8 | 9 | * { 10 | BorderWidth: 0.0f; 11 | Padding: 16.0f; 12 | Spacing: 16.0f; 13 | Gap: 16.0f; 14 | FontSize: 28.0f; 15 | FontName: data/Noto-Sans-R.ttf; 16 | } 17 | 18 | Button { 19 | FontName: data/Noto-Sans-M.ttf; 20 | Color: #DCDCDCff; 21 | BackgroundColor: #3D3D3Dff; 22 | } 23 | 24 | Button:PRELIGHT { 25 | Color: #DCDCDCff; 26 | BackgroundColor: #D64937ff; 27 | } 28 | 29 | Button:ACTIVE { 30 | Color: #3D3D3Dff; 31 | BackgroundColor: #DCDCDCff; 32 | } 33 | 34 | Button.small { 35 | Padding: 8.0f; 36 | FontSize: 21.0f; 37 | } 38 | 39 | Button.verySmall { 40 | Padding: 6.0f; 41 | FontSize: 16.0f; 42 | } 43 | 44 | CheckButton { 45 | Spacing: 0.0f; 46 | Padding: 0.0f; 47 | BoxSize: 28.0f; 48 | CheckSize: 15.0f; 49 | CheckColor: #DCDCDCff; 50 | BackgroundColor: #3D3D3Dff; 51 | } 52 | 53 | CheckButton:PRELIGHT { 54 | CheckColor: #DCDCDCff; 55 | BackgroundColor: #3D3D3Dff; 56 | } 57 | 58 | CheckButton:ACTIVE { 59 | CheckColor: #DCDCDCff; 60 | BackgroundColor: #3D3D3Dff; 61 | } 62 | 63 | Separator { 64 | Color: #00000000; 65 | } 66 | 67 | Scrollbar { 68 | StepperBackgroundColor: #3D3D3Dff; 69 | StepperArrowColor: #DCDCDCff; 70 | SliderColor: #3D3D3Dff; 71 | TroughColor: #00000000; 72 | BackgroundColor: #00000000; 73 | } 74 | 75 | Scale { 76 | SliderColor: #3D3D3DFF; 77 | TroughColor: #323232FF; 78 | } 79 | 80 | ComboBox { 81 | FontSize: 16.0f; 82 | FontName: data/Noto-Sans-M.ttf; 83 | 84 | ItemPadding: 5.0f; 85 | 86 | ArrowColor: #DCDCDCff; 87 | Color: #DCDCDCff; 88 | BackgroundColor: #3D3D3Dff; 89 | HighlightedColor: #D64937ff; 90 | } 91 | 92 | ComboBox:PRELIGHT { 93 | BackgroundColor: #D64937ff; 94 | } 95 | 96 | ComboBox:ACTIVE { 97 | BackgroundColor: #3D3D3Dff; 98 | } 99 | 100 | Label { 101 | FontSize: 19.0f; 102 | } 103 | 104 | Label.win { 105 | FontName: data/Noto-Sans-M.ttf; 106 | FontSize: 48.0f; 107 | } 108 | 109 | Label.newGameMazeSize { 110 | FontName: data/Noto-Sans-M.ttf; 111 | FontSize: 23.0f; 112 | } 113 | 114 | Label.fps { 115 | FontName: data/Noto-Mono-R.ttf; 116 | FontSize: 19.0f; 117 | } 118 | 119 | Window.log_window { 120 | BackgroundColor: #2D2D2DFF; 121 | TitleBackgroundColor: #3D3D3DFF; 122 | TitlePadding: 6.0f; 123 | HandleSize: 18.0f; 124 | CloseHeight: 11.0f; 125 | FontName: data/Noto-Mono-R.ttf; 126 | FontSize: 14.0f; 127 | } 128 | 129 | Box.log_box { 130 | Gap: 4.0f; 131 | } 132 | 133 | Window.log_element { 134 | BackgroundColor: #3D3D3DB0; 135 | Gap: 4.0f; 136 | } 137 | 138 | Label.debug, Label.status, Label.warn, Label.error { 139 | FontName: data/Noto-Mono-R.ttf; 140 | FontSize: 14.0f; 141 | } 142 | 143 | Label.debug { 144 | Color: #7D7D7DFF; 145 | } 146 | 147 | Label.warn { 148 | Color: #FFA726FF; 149 | } 150 | 151 | Label.error { 152 | Color: #D64937FF; 153 | } 154 | 155 | Entry { 156 | FontSize: 21.0f; 157 | BackgroundColor: #3D3D3DFF; 158 | Padding: 10.0f; 159 | } 160 | 161 | ProgressBar { 162 | BarColor: #D64937ff; 163 | BarBorderWidth: 0.0f; 164 | } 165 | 166 | Box.options { 167 | Gap: 10.0f; 168 | } 169 | 170 | *.nogap { 171 | Gap: 0.0f; 172 | } 173 | -------------------------------------------------------------------------------- /deb/DEBIAN/control: -------------------------------------------------------------------------------- 1 | Package: mazemaze 2 | Version: 0.3.0-1 3 | Maintainer: Мирослава Странная 4 | Architecture: amd64 5 | Section: games 6 | Description: Simple 3D OpenGL first-person maze game. 7 | Depends: libsfml-system2.5, libsfml-graphics2.5, libsfml-window2.5, libjsoncpp1 8 | -------------------------------------------------------------------------------- /deb/DEBIAN/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$1" = "configure" ] && [ -x "`which update-menus 2>/dev/null`" ] ; then 4 | update-menus 5 | fi 6 | -------------------------------------------------------------------------------- /deb/usr/share/doc/mazemaze/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: mazemaze 3 | Source: https://github.com/mirai65536/mazemaze 4 | 5 | Files: * 6 | Copyright: 7 | 2018-2021 Мирослава Странная 8 | License: GPL-2 9 | 10 | Files: *.po 11 | Copyright: 12 | 2018-2021 Мирослава Странная 13 | февральский снег 14 | Nikita Scherbina 15 | License: GPL-2 16 | 17 | Files: *.ttf 18 | License: OFL 19 | 20 | License: OFL 21 | PREAMBLE 22 | The goals of the Open Font License (OFL) are to stimulate worldwide 23 | development of collaborative font projects, to support the font 24 | creation efforts of academic and linguistic communities, and to 25 | provide a free and open framework in which fonts may be shared and 26 | improved in partnership with others. 27 | 28 | The OFL allows the licensed fonts to be used, studied, modified and 29 | redistributed freely as long as they are not sold by themselves. The 30 | fonts, including any derivative works, can be bundled, embedded, 31 | redistributed and/or sold with any software provided that any reserved 32 | names are not used by derivative works. The fonts and derivatives, 33 | however, cannot be released under any other type of license. The 34 | requirement for fonts to remain under this license does not apply to 35 | any document created using the fonts or their derivatives. 36 | 37 | DEFINITIONS 38 | "Font Software" refers to the set of files released by the Copyright 39 | Holder(s) under this license and clearly marked as such. This may 40 | include source files, build scripts and documentation. 41 | 42 | "Reserved Font Name" refers to any names specified as such after the 43 | copyright statement(s). 44 | 45 | "Original Version" refers to the collection of Font Software 46 | components as distributed by the Copyright Holder(s). 47 | 48 | "Modified Version" refers to any derivative made by adding to, 49 | deleting, or substituting -- in part or in whole -- any of the 50 | components of the Original Version, by changing formats or by porting 51 | the Font Software to a new environment. 52 | 53 | "Author" refers to any designer, engineer, programmer, technical 54 | writer or other person who contributed to the Font Software. 55 | 56 | PERMISSION & CONDITIONS 57 | Permission is hereby granted, free of charge, to any person obtaining 58 | a copy of the Font Software, to use, study, copy, merge, embed, 59 | modify, redistribute, and sell modified and unmodified copies of the 60 | Font Software, subject to the following conditions: 61 | 62 | 1) Neither the Font Software nor any of its individual components, in 63 | Original or Modified Versions, may be sold by itself. 64 | 65 | 2) Original or Modified Versions of the Font Software may be bundled, 66 | redistributed and/or sold with any software, provided that each copy 67 | contains the above copyright notice and this license. These can be 68 | included either as stand-alone text files, human-readable headers or 69 | in the appropriate machine-readable metadata fields within text or 70 | binary files as long as those fields can be easily viewed by the user. 71 | 72 | 3) No Modified Version of the Font Software may use the Reserved Font 73 | Name(s) unless explicit written permission is granted by the 74 | corresponding Copyright Holder. This restriction only applies to the 75 | primary font name as presented to the users. 76 | 77 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 78 | Software shall not be used to promote, endorse or advertise any 79 | Modified Version, except to acknowledge the contribution(s) of the 80 | Copyright Holder(s) and the Author(s) or with their explicit written 81 | permission. 82 | 83 | 5) The Font Software, modified or unmodified, in part or in whole, 84 | must be distributed entirely under this license, and must not be 85 | distributed under any other license. The requirement for fonts to 86 | remain under this license does not apply to any document created using 87 | the Font Software. 88 | 89 | TERMINATION 90 | This license becomes null and void if any of the above conditions are 91 | not met. 92 | 93 | DISCLAIMER 94 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 95 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 96 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 97 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 98 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 99 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 100 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 101 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 102 | OTHER DEALINGS IN THE FONT SOFTWARE. 103 | -------------------------------------------------------------------------------- /locale/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(DOMAIN ${PROJECT_NAME}) 2 | 3 | find_package(Gettext MODULE) 4 | find_program(XGETTEXT_EXECUTABLE xgettext) 5 | 6 | if (Gettext_FOUND AND XGETTEXT_EXECUTABLE) 7 | set(LINGUAS ru uk de) 8 | 9 | set(POT_FILE ${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}.pot) 10 | 11 | set(XGETTEXT_KEYWORDS --keyword=pgtx:1c,2 --keyword=pgtxf:1c,2 --keyword=npgtxf:1c,2,3) 12 | get_target_property(XGETTEXT_INPUT mazemaze SOURCES) 13 | 14 | add_custom_target(translations ALL DEPENDS) 15 | add_custom_target(update-translation-templates) 16 | 17 | add_custom_command(TARGET update-translation-templates 18 | COMMAND ${XGETTEXT_EXECUTABLE} 19 | ${XGETTEXT_KEYWORDS} -C -o ${POT_FILE} ${XGETTEXT_INPUT} 20 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../) 21 | 22 | foreach(LANG ${LINGUAS}) 23 | set(PO_FILE ${CMAKE_CURRENT_LIST_DIR}/${LANG}/LC_MESSAGES/${DOMAIN}.po) 24 | set(MO_FILE ${CMAKE_CURRENT_LIST_DIR}/${LANG}/LC_MESSAGES/${DOMAIN}.mo) 25 | 26 | add_custom_command(TARGET update-translation-templates 27 | COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} 28 | -q -v ${PO_FILE} ${POT_FILE} -o ${PO_FILE}) 29 | 30 | add_custom_command(TARGET translations 31 | COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} 32 | -v -c -o ${MO_FILE} ${PO_FILE}) 33 | endforeach(LANG) 34 | else (Gettext_FOUND AND XGETTEXT_EXECUTABLE) 35 | message(WARNING "Gettext not found, translations can't be done") 36 | endif (Gettext_FOUND AND XGETTEXT_EXECUTABLE) 37 | 38 | install(DIRECTORY . 39 | DESTINATION ${MAZEMAZE_INSTALL_DIR}/${PROJECT_NAME}/locale 40 | FILES_MATCHING PATTERN *.mo) 41 | -------------------------------------------------------------------------------- /mazemaze.desktop.in: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Version=1.0 3 | Encoding=UTF-8 4 | Name=Mazemaze 5 | Comment=Simple maze game 6 | Path=@MAZEMAZE_INSTALL_DIR@/mazemaze 7 | Exec=@MAZEMAZE_INSTALL_DIR@/mazemaze/mazemaze 8 | Icon=mazemaze 9 | Terminal=false 10 | Type=Application 11 | Categories=Game; 12 | StartupNotify=false 13 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsxrwscjpzdzwpxaujrr/mazemaze/84099dc9c46180aec276c810cbbea5b85b0bb8c3/screenshot.png -------------------------------------------------------------------------------- /scripts/before_deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -xeE 4 | trap 'sleep 1' ERR 5 | 6 | mkdir deploy 7 | 8 | if [[ $WINDOWS = "TRUE" ]] 9 | then 10 | ln -s ${MXE_DIR}/usr/$MXE_TARGET/opt/mazemaze mazemaze 11 | zip -r deploy/Mazemaze_${VERSION}_Windows_${ARCH_HUMAN}.zip mazemaze 12 | else 13 | cd build 14 | $CMAKE $CMAKE_MAZEMAZE_FLAGS \ 15 | -DCMAKE_INSTALL_PREFIX=/usr \ 16 | -DMAZEMAZE_INSTALL_DIR=/opt \ 17 | .. 18 | sudo make install DESTDIR=../deb 19 | cd ../deb 20 | md5deep -rl opt usr > DEBIAN/md5sums 21 | cat DEBIAN/md5sums 22 | cd .. 23 | fakeroot dpkg-deb --build deb 24 | mv deb.deb deploy/mazemaze_${VERSION}_${APT_ARCH}.deb 25 | 26 | tar -C /opt/ \ 27 | -cvzf deploy/Mazemaze_${VERSION}_Linux_${ARCH_HUMAN}.tar.gz \ 28 | mazemaze 29 | fi 30 | 31 | md5deep -rl deploy 32 | 33 | set +xeE 34 | -------------------------------------------------------------------------------- /scripts/before_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -xeE 4 | trap 'sleep 1' ERR 5 | 6 | ccache --set-config=compiler_check=content 7 | 8 | export VERSION=0.3 9 | 10 | if [[ $ARCH = "x86_64" ]] 11 | then 12 | export ARCH_HUMAN="64bit" 13 | export APT_ARCH=amd64 14 | else 15 | export ARCH_HUMAN="32bit" 16 | export APT_ARCH=i386 17 | fi 18 | 19 | if [[ $WINDOWS = "TRUE" ]] 20 | then 21 | sudo echo "deb http://pkg.mxe.cc/repos/apt bionic main" \ 22 | | sudo tee /etc/apt/sources.list.d/mxeapt.list 23 | 24 | sudo apt-key adv --keyserver keyserver.ubuntu.com \ 25 | --recv-keys C6BF758A33A3A276 26 | 27 | export MXE_TARGET=$ARCH-w64-mingw32.static 28 | export MXE_APT_TARGET=$(echo "$MXE_TARGET" | sed 's/_/-/g') 29 | export MXE_DIR=/usr/lib/mxe 30 | export MXE_PREFIX=${MXE_DIR}/usr/$MXE_TARGET 31 | 32 | export CMAKE="${MXE_DIR}/usr/bin/${MXE_TARGET}-cmake \ 33 | -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ 34 | -DCMAKE_C_COMPILER_LAUNCHER=ccache" 35 | 36 | sudo apt-get --yes update 37 | sudo apt-get --yes \ 38 | --no-install-suggests \ 39 | --no-install-recommends \ 40 | install \ 41 | mxe-$MXE_APT_TARGET-sfml \ 42 | mxe-$MXE_APT_TARGET-jsoncpp 43 | sudo apt-get --yes remove mxe-$MXE_APT_TARGET-sfml 44 | 45 | # Hack to fix linking error 46 | sudo ln -s $MXE_PREFIX/lib/libopengl32.a \ 47 | $MXE_PREFIX/lib/libOpenGL32.a 48 | 49 | # SFML 50 | 51 | wget https://www.sfml-dev.org/files/SFML-2.5.1-sources.zip 52 | unzip SFML-2.5.1-sources.zip 53 | cd SFML-2.5.1 54 | mkdir build 55 | cd build 56 | $CMAKE \ 57 | -DSFML_USE_STATIC_STD_LIBS=TRUE \ 58 | -DBUILD_SHARED_LIBS=FALSE \ 59 | -DSFML_BUILD_EXAMPLES=FALSE \ 60 | -DSFML_BUILD_DOC=FALSE \ 61 | -DSFML_BUILD_AUDIO=FALSE \ 62 | -DSFML_BUILD_GRAPHICS=TRUE \ 63 | -DSFML_BUILD_WINDOW=TRUE \ 64 | -DSFML_BUILD_NETWORK=FALSE \ 65 | .. 66 | $CMAKE --build . 67 | sudo make install 68 | cd ../.. 69 | 70 | # Icon 71 | convert data/icon.png \ 72 | -colors 256 \ 73 | -define icon:auto-resize=16,24,32,48,256 \ 74 | -background transparent \ 75 | win/icon.ico 76 | else 77 | export CMAKE=cmake 78 | 79 | export CC=$CC_COMPILER 80 | export CXX=$CXX_COMPILER 81 | fi 82 | 83 | # SFGUI 84 | 85 | git clone https://github.com/TankOs/SFGUI.git 86 | cd SFGUI 87 | sed '130{s/^/#/}' CMakeLists.txt > tmp # hack to disable SFGUI warnings 88 | mv tmp CMakeLists.txt # 89 | mkdir build 90 | cd build 91 | CMAKE_SFGUI_FLAGS="-DSFGUI_BUILD_EXAMPLES=FALSE \ 92 | -DSFGUI_BUILD_SHARED_LIBS=FALSE" 93 | if [[ $WINDOWS = "TRUE" ]] 94 | then 95 | CMAKE_SFGUI_FLAGS="$CMAKE_SFGUI_FLAGS \ 96 | -DSFGUI_STATIC_STD_LIBS=TRUE \ 97 | -DSFML_STATIC_LIBRARIES=TRUE \ 98 | -DSFGUI_BUILD_EXAMPLES=FALSE" 99 | fi 100 | $CMAKE $CMAKE_SFGUI_FLAGS .. 101 | $CMAKE --build . 102 | sudo make install 103 | cd ../.. 104 | 105 | set +xeE 106 | -------------------------------------------------------------------------------- /scripts/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -xeE 4 | trap 'sleep 1' ERR 5 | 6 | mkdir build 7 | cd build 8 | export CMAKE_MAZEMAZE_FLAGS=" 9 | -DCMAKE_VERBOSE_MAKEFILE=TRUE \ 10 | -DSFGUI_SUBMODULE=FALSE" 11 | if [[ $WINDOWS = "TRUE" ]] 12 | then 13 | CMAKE_MAZEMAZE_FLAGS="$CMAKE_MAZEMAZE_FLAGS \ 14 | -DSFML_STATIC_LIBRARIES=TRUE \ 15 | -DMAZEMAZE_INSTALL_DIR=${MXE_DIR}/usr/$MXE_TARGET/opt" 16 | fi 17 | $CMAKE $CMAKE_MAZEMAZE_FLAGS .. 18 | $CMAKE --build . 19 | sudo make install 20 | cd .. 21 | 22 | ccache -s 23 | 24 | set +xeE 25 | -------------------------------------------------------------------------------- /src/Camera.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Camera.hpp" 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include "GraphicEngine.hpp" 25 | 26 | namespace mazemaze { 27 | 28 | Camera::Camera(Pointf position, 29 | Rotation rotation, 30 | double fov, double near_dist, double far_dist) : 31 | m_position(position), 32 | m_rotation(rotation), 33 | m_fov(fov), near_dist(near_dist), far_dist(far_dist) {} 34 | 35 | Camera::~Camera() = default; 36 | 37 | void 38 | Camera::setup_rotation() { 39 | float todeg = static_cast(180.0 / M_PI); 40 | 41 | glRotatef(m_rotation.pitch() * todeg, 1.0, 0.0, 0.0); 42 | glRotatef(m_rotation.yaw() * todeg, 0.0, 1.0, 0.0); 43 | glRotatef(m_rotation.roll() * todeg, 0.0, 0.0, 1.0); 44 | } 45 | 46 | void 47 | Camera::setup_translation() { 48 | glTranslatef(-m_position.x, -m_position.y, -m_position.z); 49 | } 50 | 51 | void 52 | Camera::setup_perspective() { 53 | auto window_size = GraphicEngine::inst().window_size(); 54 | 55 | double ratio = window_size.x / static_cast(window_size.y); 56 | 57 | glMatrixMode(GL_PROJECTION); 58 | glLoadIdentity(); 59 | 60 | glFrustum(-ratio * near_dist, ratio * near_dist, 61 | -1.0 * near_dist, 1.0 * near_dist, 62 | (ratio * near_dist) / tan(m_fov * (M_PI / 360.0)), 63 | far_dist); 64 | 65 | glMatrixMode(GL_MODELVIEW); 66 | glLoadIdentity(); 67 | } 68 | 69 | Pointf& 70 | Camera::position() { 71 | return m_position; 72 | } 73 | 74 | Rotation& 75 | Camera::rotation() { 76 | return m_rotation; 77 | } 78 | 79 | double 80 | Camera::fov() const { 81 | return m_fov; 82 | } 83 | 84 | void 85 | Camera::set_fov(double fov) { 86 | m_fov = fov; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/Camera.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "Point.hpp" 21 | #include "Rotation.hpp" 22 | 23 | namespace mazemaze { 24 | 25 | class Camera { 26 | public: 27 | explicit Camera(Pointf position, Rotation rotation, 28 | double fov, double near_dist, double far_dist); 29 | ~Camera(); 30 | 31 | void setup_rotation(); 32 | void setup_translation(); 33 | void setup_perspective(); 34 | 35 | Pointf & position(); 36 | Rotation& rotation(); 37 | 38 | double fov() const; 39 | 40 | void set_fov(double fov); 41 | 42 | private: 43 | Pointf m_position; 44 | Rotation m_rotation; 45 | 46 | double m_fov; 47 | double near_dist; 48 | double far_dist; 49 | }; 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/CameraBobbing.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "CameraBobbing.hpp" 19 | 20 | #include "Camera.hpp" 21 | #include "Player.hpp" 22 | #include "utils.hpp" 23 | 24 | #include 25 | #include 26 | 27 | namespace mazemaze { 28 | 29 | const float rot_out_speed = 1.5f; 30 | const float pos_out_speed = 2.0f; 31 | const float time_out_speed = 2.0f; 32 | 33 | const float rot_in_speed = 4.0f; 34 | const float pos_in_speed = 4.0f; 35 | const float time_in_speed = 4.0f; 36 | 37 | const float pos_speed = 7.75f; 38 | const float rot_speed = pos_speed * 2.0f; 39 | 40 | const float pos_amount = 0.014f; 41 | const float rot_amount = 0.0015f; 42 | 43 | CameraBobbing::CameraBobbing() : 44 | rot_coeff(0.0f), 45 | pos_coeff(0.0f), 46 | time_coeff(0.0f), 47 | last_pitch(0.0f), 48 | easing_type(false), 49 | time(0.0f) { 50 | } 51 | 52 | CameraBobbing::~CameraBobbing() = default; 53 | 54 | void 55 | CameraBobbing::tick(Player& player, float delta_time) { 56 | Camera& camera = player.camera(); 57 | 58 | auto& position = camera.position(); 59 | auto& rotation = camera.rotation(); 60 | 61 | float current_rot; 62 | Pointf current; 63 | 64 | float rot_coeff_with_easing; 65 | float pos_coeff_with_easing; 66 | float time_coeff_with_easing; 67 | 68 | float (*easing_func)(float); 69 | 70 | if (player.is_moving()) { 71 | if ( rot_coeff < 1.0f) 72 | rot_coeff += std::min(delta_time * rot_in_speed, 1.0f - rot_coeff); 73 | 74 | if ( pos_coeff < 1.0f) 75 | pos_coeff += std::min(delta_time * pos_in_speed, 1.0f - pos_coeff); 76 | 77 | if (time_coeff < 1.0f) 78 | time_coeff += std::min(delta_time * time_in_speed, 1.0f - time_coeff); 79 | 80 | easing_type = true; 81 | } 82 | 83 | if (!player.is_moving()) { 84 | if (rot_coeff > 0.0f) 85 | rot_coeff -= std::min(delta_time * rot_out_speed, rot_coeff); 86 | 87 | if ( pos_coeff > 0.0f) 88 | pos_coeff -= std::min(delta_time * pos_out_speed, pos_coeff); 89 | 90 | if ( time_coeff > 0.0f) 91 | time_coeff -= std::min(delta_time * time_out_speed, time_coeff); 92 | 93 | easing_type = false; 94 | } 95 | 96 | if (easing_type) { 97 | easing_func = &ease_out_cubic; 98 | } else { 99 | easing_func = &ease_in_cubic; 100 | } 101 | 102 | rot_coeff_with_easing = easing_func( rot_coeff); 103 | pos_coeff_with_easing = easing_func( pos_coeff); 104 | time_coeff_with_easing = easing_func(time_coeff); 105 | 106 | float rot_raw = powfi((std::cos(time * rot_speed) + 1.0f) / 2.0f, 2) * 2.0f - 1.0f; 107 | 108 | current_rot = rot_raw * rot_amount * rot_coeff_with_easing; 109 | 110 | current.x = std::cos(time * pos_speed) * pos_amount * pos_coeff_with_easing; 111 | current.y = -std::abs(std::sin(time * pos_speed)) * pos_amount * pos_coeff_with_easing; 112 | 113 | rotation.set_pitch(rotation.pitch() - last_pitch + current_rot); 114 | 115 | position.x += current.x * std::cos(rotation.yaw()); 116 | position.y += current.y; 117 | position.z += current.x * std::sin(rotation.yaw()); 118 | 119 | last_pitch = current_rot; 120 | 121 | time += delta_time * time_coeff_with_easing; 122 | } 123 | 124 | float 125 | CameraBobbing::ease_out_cubic(float x) { 126 | return 1.0f - ease_in_cubic(1.0f - x); 127 | } 128 | 129 | float 130 | CameraBobbing::ease_in_cubic(float x) { 131 | return powfi(x, 3); 132 | } 133 | 134 | } 135 | 136 | 137 | -------------------------------------------------------------------------------- /src/CameraBobbing.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "ITickable.hpp" 21 | 22 | namespace mazemaze { 23 | 24 | class Player; 25 | 26 | class CameraBobbing : public ITickable { 27 | public: 28 | explicit CameraBobbing(); 29 | ~CameraBobbing(); 30 | 31 | void tick(Player& player, float delta_time); 32 | 33 | private: 34 | float rot_coeff; 35 | float pos_coeff; 36 | float time_coeff; 37 | 38 | float last_pitch; 39 | 40 | bool easing_type; 41 | 42 | float time; 43 | 44 | static float ease_in_cubic (float x); 45 | static float ease_out_cubic(float x); 46 | }; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/Chunk.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Chunk.hpp" 19 | 20 | namespace mazemaze { 21 | 22 | Chunk::Chunk() { 23 | for (unsigned int i = 0; i < SIZE; i++) 24 | for (unsigned int j = 0; j < SIZE; j++) 25 | opened[j][i] = false; 26 | } 27 | 28 | Chunk::~Chunk() = default; 29 | 30 | bool 31 | Chunk::get_opened(unsigned int x, unsigned int y) const { 32 | return opened[x][y]; 33 | } 34 | 35 | void 36 | Chunk::set_opened(unsigned int x, unsigned int y, bool opened) { 37 | Chunk::opened[x][y] = opened; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/Chunk.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | namespace mazemaze { 21 | 22 | class Chunk { 23 | public: 24 | static const unsigned int SIZE = 16; 25 | 26 | Chunk(); 27 | ~Chunk(); 28 | 29 | void set_opened(unsigned int x, unsigned int y, bool opened); 30 | bool get_opened(unsigned int x, unsigned int y) const; 31 | 32 | private: 33 | bool opened[SIZE][SIZE]; 34 | }; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/FpsCalculator.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "FpsCalculator.hpp" 19 | 20 | namespace mazemaze { 21 | 22 | FpsCalculator::FpsCalculator(std::function const& on_update, float update_interval) : 23 | on_update(on_update), 24 | m_update_interval(update_interval), 25 | time_passed(0.0f), 26 | delta_sum(0.0f), 27 | delta_count(0.0f), 28 | m_last_fps(0.0f) {} 29 | 30 | FpsCalculator::~FpsCalculator() = default; 31 | 32 | void 33 | FpsCalculator::tick(void*, float delta_time) { 34 | time_passed += delta_time; 35 | delta_sum += delta_time; 36 | delta_count++; 37 | 38 | if (time_passed >= m_update_interval) { 39 | float big_count = static_cast(time_passed / m_update_interval); 40 | time_passed -= m_update_interval * big_count; 41 | 42 | m_last_fps = 1.0f / (delta_sum / delta_count); 43 | 44 | on_update(m_last_fps); 45 | 46 | delta_count = 0.0f; 47 | delta_sum = 0.0; 48 | } 49 | } 50 | 51 | float 52 | FpsCalculator::last_fps() const { 53 | return m_last_fps; 54 | } 55 | 56 | float 57 | FpsCalculator::update_interval() const { 58 | return m_update_interval; 59 | } 60 | 61 | void 62 | FpsCalculator::set_update_interval(float update_interval) { 63 | m_update_interval = update_interval; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/FpsCalculator.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | #include "ITickable.hpp" 23 | 24 | namespace mazemaze { 25 | 26 | class FpsCalculator : public ITickable { 27 | public: 28 | explicit FpsCalculator(std::function const& on_update, float update_interval); 29 | ~FpsCalculator() override; 30 | 31 | void tick(void*, float delta_time) override; 32 | 33 | void set_update_interval(float update_interval); 34 | 35 | float last_fps() const; 36 | float update_interval() const; 37 | 38 | private: 39 | std::function on_update; 40 | float m_update_interval; 41 | float time_passed; 42 | 43 | float delta_sum; 44 | float delta_count; 45 | float m_last_fps; 46 | }; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/Game.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "Gui/Background.hpp" 21 | 22 | #include "Maze.hpp" 23 | #include "Player.hpp" 24 | #include "IRenderable.hpp" 25 | #include "ITickable.hpp" 26 | #include "TickableHandler.hpp" 27 | 28 | namespace mazemaze { 29 | namespace gui { 30 | 31 | class MainMenu; 32 | 33 | } 34 | 35 | class Camera; 36 | class Settings; 37 | class MazeRenderer; 38 | class Saver; 39 | 40 | class Game : public gui::Background { 41 | public: 42 | explicit Game( 43 | gui::MainMenu& main_menu, 44 | Settings& settings, 45 | Saver& saver, 46 | Point2i maze_size 47 | ); 48 | 49 | ~Game() override; 50 | 51 | void new_game(); 52 | void on_load(); 53 | 54 | void render() override; 55 | void tick(void*, float delta_time) override; 56 | void open_gui(); 57 | void stop(); 58 | 59 | void set_paused(bool paused); 60 | void set_won(bool won); 61 | void set_time(float time); 62 | void set_renderer(int id); 63 | 64 | bool is_paused() const; 65 | bool is_won() const; 66 | bool is_loaded() const; 67 | 68 | float time() const; 69 | Maze& maze(); 70 | Player& player(); 71 | Camera* camera() override; 72 | MazeRenderer& renderer() const; 73 | Settings& settings() const; 74 | 75 | private: 76 | Maze m_maze; 77 | int maze_renderer; 78 | MazeRenderer* maze_renderers[16]; 79 | Player m_player; 80 | Settings& m_settings; 81 | Saver& saver; 82 | TickableHandler tickable_handler; 83 | 84 | gui::MainMenu& main_menu; 85 | 86 | int pause_state; 87 | int won_state; 88 | 89 | bool paused; 90 | bool won; 91 | bool old_pause_key_state; 92 | float m_time; 93 | bool loaded; 94 | 95 | unsigned int gen_seed(); 96 | }; 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/GraphicEngine.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include "Gui/MainMenu.hpp" 27 | 28 | namespace mazemaze { 29 | 30 | class GraphicEngine { 31 | public: 32 | void open_window(); 33 | 34 | void loop(sfg::SFGUI& sfgui, gui::MainMenu& main_menu); 35 | void wait_key(std::function const& onKey); 36 | void unwait_key(); 37 | 38 | void set_fullscreen(bool fullscreen); 39 | void set_antialiasing(unsigned int antialiasing); 40 | void set_vsync(bool vsync); 41 | void set_on_set_states_callback(std::function const& on_set_states); 42 | 43 | sf::RenderWindow& window(); 44 | Point2i window_size() const; 45 | unsigned int max_antialiasing() const; 46 | bool fullscreen() const; 47 | bool vsync() const; 48 | bool has_focus() const; 49 | 50 | GraphicEngine(GraphicEngine const&) = delete; 51 | void operator= (GraphicEngine const&) = delete; 52 | 53 | static GraphicEngine& inst() { 54 | static GraphicEngine instance; 55 | return instance; 56 | } 57 | 58 | private: 59 | GraphicEngine(); 60 | ~GraphicEngine(); 61 | 62 | sf::RenderWindow* m_window; 63 | 64 | sf::Vector2i old_window_pos; 65 | sf::Vector2u old_window_size; 66 | #ifdef _WIN32 67 | bool old_maximized; 68 | #endif 69 | 70 | Point2i m_window_size; 71 | bool icon_loaded; 72 | bool running; 73 | bool need_reopen; 74 | bool need_reopen_event; 75 | bool m_fullscreen; 76 | bool m_vsync; 77 | bool m_focus; 78 | unsigned int m_max_antialiasing; 79 | sf::ContextSettings settings; 80 | sf::VideoMode video_mode; 81 | 82 | sf::Image icon; 83 | 84 | std::function on_key_waiting; 85 | std::function on_set_states; 86 | 87 | void open_window(unsigned int width, unsigned int height, bool fullscreen); 88 | void open_window(sf::VideoMode video_mode, bool fullscreen); 89 | void update(); 90 | void set_states(); 91 | unsigned int calc_max_antialiasing(); 92 | #ifdef _WIN32 93 | void update_old_maximized(); 94 | #endif 95 | void handle_events(gui::MainMenu& main_menu); 96 | }; 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/Gui/Background.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Background.hpp" 19 | 20 | #include "SFML/OpenGL.hpp" 21 | 22 | #include "../Camera.hpp" 23 | 24 | namespace mazemaze { 25 | namespace gui { 26 | 27 | Background::Background(ITickable* tickable, IRenderable* renderable, Camera* camera) : 28 | m_tickable(tickable), 29 | m_renderable(renderable), 30 | m_camera(camera) {} 31 | 32 | Background::~Background() = default; 33 | 34 | void 35 | Background::tick(void* _, float delta_time) { 36 | m_tickable->tick(_, delta_time); 37 | } 38 | 39 | void 40 | Background::render() { 41 | glPushMatrix(); 42 | 43 | m_camera->setup_perspective(); 44 | m_camera->setup_rotation(); 45 | m_camera->setup_translation(); 46 | 47 | m_renderable->render(); 48 | 49 | glPopMatrix(); 50 | } 51 | 52 | ITickable* 53 | Background::tickable() const { 54 | return m_tickable; 55 | } 56 | 57 | IRenderable* 58 | Background::renderable() const { 59 | return m_renderable; 60 | } 61 | 62 | Camera* 63 | Background::camera() { 64 | return m_camera; 65 | } 66 | 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Gui/Background.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../ITickable.hpp" 21 | #include "../IRenderable.hpp" 22 | 23 | namespace mazemaze { 24 | 25 | class Camera; 26 | 27 | namespace gui { 28 | 29 | class Background : public ITickable, public IRenderable { 30 | public: 31 | explicit Background(ITickable* tickable, IRenderable* renderable, Camera* camera); 32 | ~Background() override; 33 | 34 | void tick(void*, float delta_time) override; 35 | void render() override; 36 | 37 | ITickable* tickable() const; 38 | IRenderable* renderable() const; 39 | virtual Camera* camera(); 40 | 41 | private: 42 | ITickable* m_tickable; 43 | IRenderable* m_renderable; 44 | Camera* m_camera; 45 | }; 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Gui/Gui.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2023, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Gui.hpp" 19 | 20 | #include "../Logger.hpp" 21 | 22 | #include "State.hpp" 23 | 24 | namespace mazemaze { 25 | namespace gui { 26 | 27 | Gui::Gui() : m_background(nullptr), 28 | m_state(-1), 29 | m_wants_exit(false) {} 30 | 31 | Gui::~Gui() { 32 | remove_states(); 33 | } 34 | 35 | void 36 | Gui::handle_event(const sf::Event& event) { 37 | if (event.type == sf::Event::Resized) { 38 | for (auto state : states) 39 | state->center(); 40 | } 41 | 42 | on_event(event); 43 | 44 | m_desktop.HandleEvent(event); 45 | } 46 | 47 | void 48 | Gui::on_event(const sf::Event&) { 49 | 50 | } 51 | 52 | void 53 | Gui::tick(void* _, float delta_time) { 54 | m_desktop.Update(delta_time); 55 | 56 | tickable_handler.tick(_, delta_time); 57 | } 58 | 59 | void 60 | Gui::render() { 61 | if (m_background != nullptr) 62 | m_background->render(); 63 | } 64 | 65 | void 66 | Gui::back() { 67 | state_stack.pop(); 68 | set_state(state_stack.top(), true); 69 | } 70 | 71 | void 72 | Gui::back_to(int dest_state) { 73 | while (state_stack.top() != dest_state) { 74 | state_stack.pop(); 75 | 76 | if (state_stack.empty()) { 77 | m_wants_exit = true; 78 | return; 79 | } 80 | } 81 | 82 | set_state(state_stack.top(), true); 83 | } 84 | 85 | int 86 | Gui::add_state(State* state) { 87 | Logger::inst().log_debug("Adding " + state->name + " state to GUI."); 88 | 89 | states.emplace_back(state); 90 | states.at(states.size() - 1)->show(false); 91 | 92 | return states.size() - 1; 93 | } 94 | 95 | void 96 | Gui::remove_state(int state) { 97 | if (m_state == state) 98 | set_state(-1); 99 | 100 | delete states.at(state); 101 | states.erase(states.begin() + state); 102 | } 103 | 104 | void 105 | Gui::remove_states() { 106 | for (auto state : states) 107 | delete state; 108 | 109 | states.clear(); 110 | } 111 | 112 | void 113 | Gui::reset_text() { 114 | Logger::inst().log_debug("Resetting text."); 115 | 116 | for (auto state : states) 117 | state->reset_text(); 118 | } 119 | 120 | void 121 | Gui::add_overlay(int state_id) { 122 | Logger::inst().log_debug("Adding overlay " + state(state_id).name); 123 | 124 | states.at(state_id)->show(true); 125 | 126 | tickable_handler.addTickable(states[state_id]); 127 | overlays.emplace_back(state_id); 128 | } 129 | 130 | void 131 | Gui::remove_overlay(int state_id) { 132 | Logger::inst().log_debug("Removing overlay " + state(state_id).name); 133 | 134 | states.at(state_id)->show(false); 135 | 136 | for (auto i = overlays.begin(); i < overlays.end(); i++) { 137 | if (*i == state_id) { 138 | tickable_handler.removeTickable(states[state_id]); 139 | overlays.erase(i); 140 | break; 141 | } 142 | } 143 | } 144 | 145 | void 146 | Gui::set_state(int state, bool back) { 147 | Logger::inst().log_debug("Setting state to " + (state >= 0 ? Gui::state(state).name : "-1")); 148 | 149 | if (Gui::m_state >= 0) { 150 | states[Gui::m_state]->show(false); 151 | tickable_handler.removeTickable(states[Gui::m_state]); 152 | } 153 | 154 | if (state < 0 && !back) 155 | state_stack.emplace(state); 156 | 157 | for (int i = 0; i < states.size(); i++) { 158 | if (i == state) { 159 | tickable_handler.addTickable(states[i]); 160 | states[i]->show(true); 161 | 162 | if (!back) 163 | state_stack.emplace(i); 164 | } 165 | } 166 | 167 | m_state = state; 168 | } 169 | 170 | void 171 | Gui::set_background(Background* background) { 172 | if (Gui::m_background) 173 | tickable_handler.removeTickable(Gui::m_background); 174 | 175 | if (Gui::m_background != background) 176 | tickable_handler.addTickable(background); 177 | 178 | m_background = background; 179 | } 180 | 181 | void 182 | Gui::exit() { 183 | m_wants_exit = true; 184 | 185 | on_exit(); 186 | } 187 | 188 | sfg::Desktop& 189 | Gui::desktop() { 190 | return m_desktop; 191 | } 192 | 193 | int 194 | Gui::state() const { 195 | return m_state; 196 | } 197 | 198 | State& 199 | Gui::state(int state) { 200 | return *states.at(state); 201 | } 202 | 203 | bool 204 | Gui::wants_exit() const { 205 | return m_wants_exit; 206 | } 207 | 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/Gui/Gui.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2023, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include "../IRenderable.hpp" 26 | #include "../ITickable.hpp" 27 | #include "../TickableHandler.hpp" 28 | 29 | #include "Background.hpp" 30 | 31 | namespace mazemaze { 32 | namespace gui { 33 | 34 | class State; 35 | 36 | class Gui : public ITickable, public IRenderable { 37 | public: 38 | Gui(); 39 | ~Gui() override; 40 | 41 | void handle_event(const sf::Event& event); 42 | virtual void on_event(const sf::Event& event); 43 | 44 | void tick(void*, float delta_time) override; 45 | void render() override; 46 | 47 | void back(); 48 | void back_to(int dest_state); 49 | 50 | int add_state(State* state); 51 | void remove_state(int state); 52 | void remove_states(); 53 | 54 | void reset_text(); 55 | 56 | void add_overlay(int state_id); 57 | void remove_overlay(int state_id); 58 | 59 | void set_state(int state, bool back = false); 60 | void set_background(Background* background); 61 | 62 | void exit(); 63 | 64 | virtual void on_exit() = 0; 65 | 66 | sfg::Desktop& desktop(); 67 | int state() const; 68 | State& state(int state); 69 | Background& background() const; 70 | bool wants_exit() const; 71 | 72 | private: 73 | sfg::Desktop m_desktop; 74 | 75 | Background* m_background; 76 | 77 | std::vector states; 78 | std::stack state_stack; 79 | std::vector overlays; 80 | 81 | TickableHandler tickable_handler; 82 | 83 | int m_state; 84 | bool m_wants_exit; 85 | }; 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Gui/MainMenu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2023, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "MainMenu.hpp" 19 | 20 | #include 21 | 22 | #include "../Game.hpp" 23 | #include "../Saver.hpp" 24 | #include "../Settings.hpp" 25 | #include "../StarSky.hpp" 26 | #include "../Logger.hpp" 27 | #include "../path_separator.hpp" 28 | #include "../GraphicEngine.hpp" 29 | #include "../utils.hpp" 30 | 31 | #include "Background.hpp" 32 | 33 | #include "States/Main.hpp" 34 | #include "States/FpsOverlay.hpp" 35 | #include "States/Debug.hpp" 36 | 37 | namespace mazemaze { 38 | namespace gui { 39 | 40 | MainMenu::MainMenu(Settings& settings) : game(nullptr), 41 | saver(new Saver(settings)), 42 | settings(settings), 43 | fps_show(false), 44 | debug_show(false) { 45 | Logger::inst().log_debug("Starting main menu."); 46 | 47 | auto theme_file = "data" PATH_SEPARATOR "style.theme"; 48 | 49 | if (!desktop().LoadThemeFromFile(theme_file)) { 50 | Logger::inst().log_error(fmt("Can not load theme file \"%s\"", theme_file)); 51 | } 52 | 53 | m_main_state = add_state(new states::Main (*this, settings)); 54 | m_fps_state = add_state(new states::FpsOverlay(*this, settings)); 55 | m_debug_state = add_state(new states::Debug (*this )); 56 | 57 | set_state(m_main_state); 58 | 59 | auto* star_sky = new StarSky(1024, 600.0f, Rotation()); 60 | 61 | star_sky_background = new Background( 62 | star_sky, star_sky, 63 | new Camera(Pointf ( 0.0f, 0.0f, 0.0f), 64 | Rotation(-1.5f, -2.5f, 0.0f), 65 | 110.0, 10.0, 100.0) 66 | ); 67 | 68 | set_background(star_sky_background); 69 | } 70 | 71 | MainMenu::~MainMenu() { 72 | delete star_sky_background->tickable(); 73 | delete star_sky_background->camera(); 74 | delete star_sky_background; 75 | 76 | if (game != nullptr) 77 | delete game; 78 | 79 | delete saver; 80 | } 81 | 82 | void 83 | MainMenu::on_event(const sf::Event& event) { 84 | if (event.type == sf::Event::LostFocus && game != nullptr && game->is_loaded()) 85 | game->set_paused(true); 86 | 87 | if (event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::F3) { 88 | if (game && game->is_loaded() && !game->is_paused() && !game->is_won() && !debug_show) 89 | game->set_paused(true); 90 | 91 | show_debug(!debug_show); 92 | } 93 | } 94 | 95 | void 96 | MainMenu::on_exit() { 97 | settings.save(); 98 | } 99 | 100 | Game& 101 | MainMenu::new_game(Point2i maze_size) { 102 | game = new Game(*this, settings, *saver, maze_size); 103 | game->new_game(); 104 | 105 | return *game; 106 | } 107 | 108 | void 109 | MainMenu::start_game() { 110 | if (!game) 111 | return; 112 | 113 | if (!game->is_loaded()) 114 | return; 115 | 116 | setup_game(); 117 | 118 | set_state(-1); 119 | game->set_paused(!GraphicEngine::inst().has_focus()); 120 | } 121 | 122 | void 123 | MainMenu::resume_game() { 124 | game = saver->load(*this); 125 | 126 | start_game(); 127 | } 128 | 129 | void 130 | MainMenu::stop_game() { 131 | back_to(m_main_state); 132 | 133 | delete game; 134 | 135 | game = nullptr; 136 | 137 | set_background(star_sky_background); 138 | } 139 | 140 | bool 141 | MainMenu::is_game_open() { 142 | return game != nullptr; 143 | } 144 | 145 | void 146 | MainMenu::show_fps(bool show) { 147 | if (fps_show != show) { 148 | if (show) 149 | add_overlay(m_fps_state); 150 | else 151 | remove_overlay(m_fps_state); 152 | 153 | fps_show = show; 154 | } 155 | } 156 | 157 | void 158 | MainMenu::show_debug(bool show) { 159 | if (debug_show != show) { 160 | if (show) 161 | add_overlay(m_debug_state); 162 | else 163 | remove_overlay(m_debug_state); 164 | 165 | debug_show = show; 166 | } 167 | } 168 | 169 | int 170 | MainMenu::options_state() const { 171 | return m_options_state; 172 | } 173 | 174 | void 175 | MainMenu::set_options_state(states::OptionsMenu&, int state) { 176 | m_options_state = state; 177 | } 178 | 179 | bool 180 | MainMenu::show_fps() const { 181 | return fps_show; 182 | } 183 | 184 | bool 185 | MainMenu::show_debug() const { 186 | return debug_show; 187 | } 188 | 189 | void 190 | MainMenu::setup_game() { 191 | set_background(game); 192 | } 193 | 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /src/Gui/MainMenu.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2023, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "Gui.hpp" 21 | #include "../Point2.hpp" 22 | 23 | namespace mazemaze { 24 | 25 | class Game; 26 | class StarSky; 27 | class Settings; 28 | class Saver; 29 | 30 | namespace gui { 31 | 32 | class State; 33 | 34 | namespace states { 35 | 36 | class OptionsMenu; 37 | 38 | } 39 | 40 | class MainMenu : public Gui { 41 | public: 42 | explicit MainMenu(Settings& settings); 43 | ~MainMenu() override; 44 | 45 | void on_event(const sf::Event& event) override; 46 | void on_exit() override; 47 | 48 | Game& new_game(Point2i maze_size); 49 | void start_game(); 50 | void resume_game(); 51 | void stop_game(); 52 | void show_fps(bool show); 53 | void show_debug(bool show); 54 | 55 | void set_options_state(states::OptionsMenu& options, int state); 56 | 57 | int options_state() const; 58 | bool show_fps() const; 59 | bool show_debug() const; 60 | bool is_game_open(); 61 | 62 | private: 63 | Game* game; 64 | Saver* saver; 65 | Background* star_sky_background; 66 | Settings& settings; 67 | 68 | int m_main_state; 69 | int m_fps_state; 70 | int m_debug_state; 71 | int m_options_state; 72 | 73 | bool fps_show; 74 | bool debug_show; 75 | 76 | void setup_game(); 77 | }; 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Gui/State.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "State.hpp" 19 | 20 | #include "../GraphicEngine.hpp" 21 | 22 | namespace mazemaze { 23 | namespace gui { 24 | 25 | State::State(sfg::Desktop& desktop, const std::string& name) : 26 | name(name), 27 | desktop(desktop), 28 | box(sfg::Box::Create()) {} 29 | 30 | State::~State() { 31 | desktop.Remove(main_container()); 32 | } 33 | 34 | void 35 | State::center() { 36 | center(main_container()); 37 | } 38 | 39 | void 40 | State::center(sfg::Widget::Ptr widget) { 41 | sf::Vector2f widget_Size(widget->GetAllocation().width, widget->GetAllocation().height); 42 | sf::Vector2f window_Size = 43 | static_cast(GraphicEngine::inst().window().getSize()); 44 | 45 | widget->SetPosition((window_Size - widget_Size) / 2.0f); 46 | } 47 | 48 | void 49 | State::show(bool show) { 50 | main_container()->Show(show); 51 | } 52 | 53 | void 54 | State::tick(void*, float) { 55 | 56 | } 57 | 58 | sfg::Container::Ptr 59 | State::main_container() { 60 | return box; 61 | } 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Gui/State.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../ITickable.hpp" 21 | 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | 28 | namespace mazemaze { 29 | namespace gui { 30 | 31 | class State : public ITickable { 32 | public: 33 | const std::string name; 34 | 35 | explicit State(sfg::Desktop& desktop, const std::string& name); 36 | virtual ~State(); 37 | 38 | virtual void center(); 39 | virtual void show(bool show); 40 | virtual void tick(void*, float delta_time) override; 41 | virtual void reset_text() = 0; 42 | virtual sfg::Container::Ptr main_container(); 43 | 44 | protected: 45 | sfg::Desktop& desktop; 46 | sfg::Box::Ptr box; 47 | 48 | virtual void center(sfg::Widget::Ptr widget); 49 | }; 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Gui/States/About.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "About.hpp" 19 | 20 | #include 21 | 22 | #include "../../utils.hpp" 23 | 24 | #include "../MainMenu.hpp" 25 | 26 | using namespace sfg; 27 | 28 | namespace mazemaze { 29 | namespace gui { 30 | namespace states { 31 | 32 | About::About(MainMenu& main_menu, Settings& settings) : 33 | Options(main_menu, settings, "About"), 34 | about_label(Label::Create()) { 35 | reset_text(); 36 | 37 | about_label->SetLineWrap(true); 38 | window_box->Pack(about_label); 39 | 40 | center(); 41 | } 42 | 43 | void 44 | About::on_reset_text() { 45 | about_label->SetText(pgtxf("about", 46 | "Mazemaze 0.3-git (under development)\n" 47 | "Built on %s\n" 48 | "\n" 49 | "Simple maze game created by sad girl\n" 50 | "Mira Strannaya. Licensed under GPL v2.\n" 51 | "\n" 52 | "You can read more about me and this game on " 53 | "my personal website https://mira-strannaya.ru/", 54 | __DATE__)); 55 | } 56 | 57 | About::~About() = default; 58 | 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Gui/States/About.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../State.hpp" 21 | 22 | #include "Options.hpp" 23 | 24 | namespace mazemaze { 25 | 26 | class Settings; 27 | 28 | namespace gui { 29 | 30 | class MainMenu; 31 | 32 | namespace states { 33 | 34 | class About : public Options { 35 | public: 36 | explicit About(MainMenu& mainMenu, Settings& settings); 37 | ~About() override; 38 | 39 | void on_reset_text() override; 40 | 41 | private: 42 | sfg::Label::Ptr about_label; 43 | }; 44 | 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Gui/States/Debug.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Debug.hpp" 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include "../MainMenu.hpp" 25 | 26 | #include "../../Settings.hpp" 27 | #include "../../utils.hpp" 28 | 29 | using namespace sfg; 30 | 31 | namespace mazemaze { 32 | namespace gui { 33 | namespace states { 34 | 35 | Debug::Debug(MainMenu& main_menu) : 36 | State(main_menu.desktop(), "Debug"), 37 | log_box(Box::Create(Box::Orientation::VERTICAL)), 38 | window(Window::Create( 39 | Window::Style::BACKGROUND | 40 | Window::Style::TITLEBAR | 41 | Window::Style::RESIZE | 42 | Window::Style::CLOSE 43 | )), 44 | scrolled_window(ScrolledWindow::Create()), 45 | not_displayed_messages(std::deque( 46 | Logger::inst().messages().begin(), 47 | Logger::inst().messages().end() 48 | )), 49 | showing(false), 50 | odd(false) { 51 | Logger::inst().add_message_listener([this] (Logger::Message& message) { 52 | not_displayed_messages.emplace(message); 53 | }); 54 | 55 | char scrollbar_policy = ScrolledWindow::HORIZONTAL_NEVER | ScrolledWindow::VERTICAL_ALWAYS; 56 | 57 | window->SetClass("log_window"); 58 | window->Add(scrolled_window); 59 | window->SetTitle(pgtx("debug", "Debug log")); 60 | window->SetPosition({ 16.0f, 16.0f }); 61 | 62 | window->GetSignal(Window::OnCloseButton).Connect([&main_menu] () { 63 | main_menu.show_debug(false); 64 | }); 65 | 66 | scrolled_window->SetScrollbarPolicy(scrollbar_policy); 67 | scrolled_window->SetRequisition({ 0.0f, 320.0f }); 68 | scrolled_window->AddWithViewport(log_box); 69 | 70 | log_box->SetRequisition({ 640.0f, 0.0f }); 71 | log_box->SetClass("log_box"); 72 | 73 | tick(nullptr, 0.0f); 74 | 75 | desktop.Add(window); 76 | } 77 | 78 | Debug::~Debug() = default; 79 | 80 | 81 | void 82 | Debug::center() { 83 | } 84 | 85 | void 86 | Debug::tick(void*, float) { 87 | if (!showing) 88 | return; 89 | 90 | bool first = true; 91 | bool adjustement_pinned = false; 92 | 93 | while (not_displayed_messages.size() > 0) { 94 | if (first) { 95 | adjustement_pinned = adjustement_value() == adjustement_upper_value(); 96 | first = false; 97 | } 98 | 99 | log_box->Pack(create_log_element(not_displayed_messages.front(), odd)); 100 | not_displayed_messages.pop(); 101 | 102 | odd = !odd; 103 | } 104 | 105 | if (adjustement_pinned) { 106 | scrolled_window->Refresh(); 107 | set_adjustement_value(adjustement_upper_value()); 108 | } 109 | } 110 | 111 | void 112 | Debug::show(bool show) { 113 | State::show(show); 114 | 115 | showing = show; 116 | 117 | if (show) 118 | desktop.BringToFront(window); 119 | } 120 | 121 | Container::Ptr 122 | Debug::main_container() { 123 | return window; 124 | } 125 | 126 | void 127 | Debug::reset_text() { 128 | } 129 | 130 | Widget::Ptr 131 | Debug::create_log_element(Logger::Message& message, bool odd) { 132 | auto element = Window::Create(Window::Style::NO_STYLE); 133 | element->SetClass("log_element"); 134 | 135 | if (odd) 136 | element->SetStyle(Window::Style::BACKGROUND); 137 | 138 | auto label = Label::Create(message.to_string()); 139 | 140 | std::string class_name; 141 | 142 | switch (message.level) { 143 | case Logger::DEBUG: 144 | class_name = "debug"; 145 | break; 146 | 147 | case Logger::STATUS: 148 | class_name = "status"; 149 | break; 150 | 151 | case Logger::WARN: 152 | class_name = "warn"; 153 | break; 154 | 155 | case Logger::ERR: 156 | class_name = "error"; 157 | break; 158 | } 159 | 160 | label->SetClass(class_name); 161 | label->SetAlignment({ 0.0f, 0.5f }); 162 | 163 | element->Add(label); 164 | 165 | return element; 166 | } 167 | 168 | float 169 | Debug::adjustement_upper_value() { 170 | auto adjustement = scrolled_window->GetVerticalAdjustment(); 171 | 172 | return adjustement->GetUpper() - adjustement->GetPageSize(); 173 | } 174 | 175 | float 176 | Debug::adjustement_value() { 177 | auto adjustement = scrolled_window->GetVerticalAdjustment(); 178 | 179 | return adjustement->GetValue(); 180 | } 181 | 182 | void 183 | Debug::set_adjustement_value(float value) { 184 | auto adjustement = scrolled_window->GetVerticalAdjustment(); 185 | 186 | adjustement->SetValue(value); 187 | } 188 | 189 | } 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /src/Gui/States/Debug.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../State.hpp" 21 | 22 | #include 23 | 24 | #include "../../Logger.hpp" 25 | 26 | namespace mazemaze { 27 | namespace gui { 28 | 29 | class MainMenu; 30 | 31 | namespace states { 32 | 33 | class Debug : public State { 34 | public: 35 | explicit Debug(MainMenu& main_menu); 36 | ~Debug() override; 37 | 38 | void center() override; 39 | void tick(void*, float deltaTime) override; 40 | void show(bool show) override; 41 | sfg::Container::Ptr main_container() override; 42 | void reset_text() override; 43 | 44 | private: 45 | sfg::Box::Ptr log_box; 46 | sfg::Window::Ptr window; 47 | sfg::ScrolledWindow::Ptr scrolled_window; 48 | std::queue not_displayed_messages; 49 | 50 | bool showing; 51 | bool odd; 52 | 53 | sfg::Widget::Ptr create_log_element(Logger::Message& message, bool odd); 54 | float adjustement_upper_value(); 55 | float adjustement_value(); 56 | void set_adjustement_value(float value); 57 | }; 58 | 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Gui/States/FpsOverlay.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "FpsOverlay.hpp" 19 | 20 | #include 21 | 22 | #include "../MainMenu.hpp" 23 | 24 | #include "../../Settings.hpp" 25 | #include "../../utils.hpp" 26 | 27 | using namespace sfg; 28 | 29 | namespace mazemaze { 30 | namespace gui { 31 | namespace states { 32 | 33 | FpsOverlay::FpsOverlay(MainMenu& main_menu, Settings& settings) : 34 | State(main_menu.desktop(), "FpsOverlay"), 35 | settings(settings), 36 | fps_calculator([this] (float fps) { 37 | fpsLabel->SetText(fmt("%.2f", fps)); 38 | box->UpdateDrawablePosition(); 39 | }, 0.5f), 40 | showing(false) { 41 | auto window = Window::Create(Window::Style::BACKGROUND); 42 | 43 | fpsLabel = Label::Create(L"00,00"); 44 | fpsLabel->SetClass("fps"); 45 | 46 | window->Add(fpsLabel); 47 | 48 | box->Pack(window); 49 | 50 | desktop.Add(box); 51 | } 52 | 53 | FpsOverlay::~FpsOverlay() = default; 54 | 55 | void 56 | FpsOverlay::show(bool show) { 57 | box->Show(show); 58 | 59 | showing = show; 60 | } 61 | 62 | void 63 | FpsOverlay::reset_text() {} 64 | 65 | void 66 | FpsOverlay::tick(void*, float delta_time) { 67 | if (showing) 68 | fps_calculator.tick(nullptr, delta_time); 69 | } 70 | 71 | void 72 | FpsOverlay::center() { 73 | box->UpdateDrawablePosition(); 74 | } 75 | 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Gui/States/FpsOverlay.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../State.hpp" 21 | 22 | #include "../../FpsCalculator.hpp" 23 | 24 | namespace mazemaze { 25 | 26 | class Settings; 27 | 28 | namespace gui { 29 | 30 | class MainMenu; 31 | 32 | namespace states { 33 | 34 | class FpsOverlay : public State { 35 | public: 36 | explicit FpsOverlay(MainMenu& main_menu, Settings& settings); 37 | ~FpsOverlay() override; 38 | 39 | void show(bool show) override; 40 | 41 | void reset_text() override; 42 | 43 | private: 44 | sfg::Label::Ptr fpsLabel; 45 | Settings& settings; 46 | FpsCalculator fps_calculator; 47 | 48 | bool showing; 49 | 50 | void tick(void*, float delta_time) override; 51 | void center() override; 52 | }; 53 | 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Gui/States/Main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2020, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Main.hpp" 19 | 20 | #include "../../utils.hpp" 21 | #include "../../Saver.hpp" 22 | #include "../../GraphicEngine.hpp" 23 | 24 | #include "../MainMenu.hpp" 25 | 26 | #include "About.hpp" 27 | #include "NewGame.hpp" 28 | #include "OptionsMenu.hpp" 29 | 30 | using namespace sfg; 31 | 32 | namespace mazemaze { 33 | namespace gui { 34 | namespace states { 35 | 36 | Main::Main(MainMenu& main_menu, Settings& settings) : 37 | State(main_menu.desktop(), "Main"), 38 | resume_button (Button::Create()), 39 | new_game_button(Button::Create()), 40 | options_button (Button::Create()), 41 | about_button (Button::Create()), 42 | exit_button (Button::Create()), 43 | settings(settings), 44 | showing(false) { 45 | reset_text(); 46 | 47 | init_signals(main_menu); 48 | 49 | update_buttons(Saver::save_exists(settings)); 50 | 51 | OptionsMenu* options = new OptionsMenu(main_menu, settings); 52 | 53 | new_game_state = main_menu.add_state(new NewGame(main_menu)); 54 | options_state = main_menu.add_state(options); 55 | about_state = main_menu.add_state(new About(main_menu, settings)); 56 | 57 | main_menu.set_options_state(*options, options_state); 58 | 59 | about_button->SetClass("verySmall"); 60 | } 61 | 62 | Main::~Main() = default; 63 | 64 | void 65 | Main::show(bool show) { 66 | State::show(show); 67 | 68 | showing = show; 69 | 70 | about_button->Show(show); 71 | 72 | if (show) 73 | update_buttons(Saver::save_exists(settings)); 74 | } 75 | 76 | void 77 | Main::update_buttons(bool save_exists) { 78 | desktop.Remove(box); 79 | 80 | box = Box::Create(Box::Orientation::VERTICAL); 81 | 82 | box->SetSpacing(20.0f); 83 | 84 | resume_button->Show(save_exists); 85 | 86 | box->Pack(resume_button); 87 | box->Pack(new_game_button); 88 | box->Pack(options_button); 89 | box->Pack(exit_button); 90 | 91 | desktop.Add(about_button); 92 | 93 | box->SetRequisition({300.0f, box->GetRequisition().y}); 94 | 95 | desktop.Add(box); 96 | 97 | center(); 98 | } 99 | 100 | void 101 | Main::center() { 102 | sf::Vector2f widget_size(about_button->GetAllocation().width, 103 | about_button->GetAllocation().height); 104 | 105 | sf::Vector2f window_size = 106 | static_cast(GraphicEngine::inst().window().getSize()); 107 | 108 | about_button->Show(showing && window_size.x > 640 && window_size.y > 300); 109 | 110 | sf::Vector2f spacing(24.0f, 24.0f); 111 | 112 | about_button->SetAllocation(sf::FloatRect( 113 | window_size - widget_size - spacing, 114 | { 140.0f, 36.0f } 115 | )); 116 | 117 | State::center(); 118 | } 119 | 120 | void 121 | Main::reset_text() { 122 | resume_button ->SetLabel(pgtx("main", "Resume")); 123 | new_game_button->SetLabel(pgtx("main", "New Game")); 124 | options_button ->SetLabel(pgtx("main", "Options")); 125 | about_button ->SetLabel(pgtx("main", "About")); 126 | exit_button ->SetLabel(pgtx("main", "Exit")); 127 | } 128 | 129 | void 130 | Main::init_signals(MainMenu& main_menu) { 131 | resume_button->GetSignal(Widget::OnLeftClick).Connect([&main_menu] { 132 | main_menu.resume_game(); 133 | }); 134 | 135 | new_game_button->GetSignal(Widget::OnLeftClick).Connect([&main_menu, this] { 136 | main_menu.set_state(new_game_state); 137 | }); 138 | 139 | options_button->GetSignal(Widget::OnLeftClick).Connect([&main_menu, this] { 140 | main_menu.set_state(options_state); 141 | }); 142 | 143 | about_button->GetSignal(Widget::OnLeftClick).Connect([&main_menu, this] { 144 | main_menu.set_state(about_state); 145 | }); 146 | 147 | exit_button->GetSignal(Widget::OnLeftClick).Connect([&main_menu] { 148 | main_menu.exit(); 149 | }); 150 | } 151 | 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/Gui/States/Main.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../State.hpp" 21 | 22 | namespace mazemaze { 23 | 24 | class Game; 25 | class Settings; 26 | 27 | namespace gui { 28 | 29 | class MainMenu; 30 | 31 | namespace states { 32 | 33 | class Main : public State { 34 | public: 35 | explicit Main(MainMenu& main_menu, Settings& settings); 36 | ~Main() override; 37 | 38 | void show(bool show) override; 39 | void update_buttons(bool save_exists); 40 | 41 | void center() override; 42 | void reset_text() override; 43 | 44 | private: 45 | sfg::Button::Ptr resume_button; 46 | sfg::Button::Ptr new_game_button; 47 | sfg::Button::Ptr options_button; 48 | sfg::Button::Ptr about_button; 49 | sfg::Button::Ptr exit_button; 50 | 51 | Settings& settings; 52 | 53 | int new_game_state; 54 | int options_state; 55 | int about_state; 56 | 57 | bool showing; 58 | 59 | void init_signals(MainMenu& main_menu); 60 | }; 61 | 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Gui/States/NewGame.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "NewGame.hpp" 19 | #include "Progress.hpp" 20 | 21 | #include "../../utils.hpp" 22 | 23 | #include "../MainMenu.hpp" 24 | 25 | using namespace sfg; 26 | 27 | namespace mazemaze { 28 | namespace gui { 29 | namespace states { 30 | 31 | void 32 | NewGame::init_signals(MainMenu& main_menu) { 33 | start_button->GetSignal(Widget::OnLeftClick).Connect([this, &main_menu] { 34 | const sf::String text = size_entry->GetText(); 35 | int maze_size = 1; 36 | 37 | if (text.getSize() > 0) 38 | maze_size = std::stoi(size_entry->GetText().toWideString()); 39 | 40 | Game* game = &main_menu.new_game(Point2i(maze_size, maze_size)); 41 | 42 | static_cast(main_menu.state(progress_state)).setGame(game); 43 | main_menu.set_state(progress_state); 44 | }); 45 | 46 | back_button->GetSignal(Widget::OnLeftClick).Connect([&main_menu] { 47 | main_menu.back(); 48 | }); 49 | 50 | size_entry->GetSignal(Entry::OnTextChanged).Connect([this] { 51 | const sf::String text = size_entry->GetText(); 52 | bool need_old = false; 53 | 54 | if (text.getSize() != 0) { 55 | need_old = text.getSize() > max_size_chars; 56 | 57 | if (!need_old) { 58 | for (auto c : text) { 59 | if (!std::isdigit(c)) { 60 | need_old = true; 61 | break; 62 | } 63 | } 64 | } 65 | } 66 | 67 | if (need_old) { 68 | size_entry->SetText(old_text); 69 | size_entry->SetCursorPosition(old_cursor); 70 | } 71 | 72 | old_text = size_entry->GetText(); 73 | }); 74 | } 75 | 76 | NewGame::NewGame(MainMenu& main_menu) : 77 | State(main_menu.desktop(), "NewGame"), 78 | back_button(Button::Create()), 79 | start_button(Button::Create()), 80 | size_entry(Entry::Create(L"10")), 81 | maze_size_label(Label::Create()), 82 | old_text(size_entry->GetText()), 83 | old_cursor(size_entry->GetCursorPosition()) { 84 | reset_text(); 85 | 86 | auto button_box = Box::Create(Box::Orientation::HORIZONTAL); 87 | auto separator_horizontal = Separator::Create(Separator::Orientation::HORIZONTAL); 88 | auto separator_vertical = Separator::Create(Separator::Orientation::VERTICAL); 89 | auto window = Window::Create(Window::Style::BACKGROUND); 90 | auto window_box = Box::Create(Box::Orientation::VERTICAL); 91 | 92 | separator_horizontal->SetRequisition({20.0f, 0.0f}); 93 | separator_vertical->SetRequisition({0.0f, 20.0f}); 94 | 95 | size_entry->SetRequisition({10.0f, 10.0f}); 96 | 97 | maze_size_label->SetClass("newGameMazeSize"); 98 | 99 | window_box->Pack(maze_size_label); 100 | window_box->Pack(size_entry); 101 | window_box->SetSpacing(20.0f); 102 | 103 | window->Add(window_box); 104 | 105 | button_box->Pack(back_button); 106 | button_box->Pack(separator_horizontal); 107 | button_box->Pack(start_button); 108 | button_box->SetClass("nogap"); 109 | 110 | start_button->SetRequisition({182.0f, 0.0f}); 111 | back_button->SetRequisition({182.0f, 0.0f}); 112 | 113 | window->SetRequisition({384.0f, 0.0f}); 114 | 115 | box = Box::Create(Box::Orientation::VERTICAL); 116 | 117 | box->Pack(window); 118 | box->Pack(separator_vertical); 119 | box->Pack(button_box); 120 | 121 | desktop.Add(box); 122 | 123 | init_signals(main_menu); 124 | 125 | center(); 126 | 127 | progress_state = main_menu.add_state(new Progress(main_menu)); 128 | } 129 | 130 | void 131 | NewGame::tick(void*, float) { 132 | old_cursor = size_entry->GetCursorPosition(); 133 | } 134 | 135 | void 136 | NewGame::reset_text() { 137 | back_button ->SetLabel(pgtx("new_game", "Back")); 138 | start_button ->SetLabel(pgtx("new_game", "Start")); 139 | maze_size_label->SetText (pgtx("new_game", "Enter maze size")); 140 | } 141 | 142 | NewGame::~NewGame() = default; 143 | 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/Gui/States/NewGame.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../State.hpp" 21 | 22 | namespace mazemaze { 23 | 24 | namespace gui { 25 | 26 | class MainMenu; 27 | 28 | namespace states { 29 | 30 | class NewGame : public State { 31 | public: 32 | const char max_size_chars = 4; 33 | 34 | explicit NewGame(MainMenu& main_menu); 35 | ~NewGame() override; 36 | 37 | void tick(void*, float delta_time) override; 38 | void reset_text() override; 39 | 40 | private: 41 | sfg::Button::Ptr back_button; 42 | sfg::Button::Ptr start_button; 43 | sfg::Entry::Ptr size_entry; 44 | sfg::Label::Ptr maze_size_label; 45 | 46 | int progress_state; 47 | 48 | sf::String old_text; 49 | int old_cursor; 50 | 51 | void init_signals(MainMenu& main_menu); 52 | }; 53 | 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Gui/States/Options.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Options.hpp" 19 | 20 | #include "../../utils.hpp" 21 | #include "../../Settings.hpp" 22 | 23 | #include "../MainMenu.hpp" 24 | 25 | #include "OptionsGraphics.hpp" 26 | #include "OptionsControls.hpp" 27 | #include "OptionsOther.hpp" 28 | 29 | using namespace sfg; 30 | 31 | namespace mazemaze { 32 | namespace gui { 33 | namespace states { 34 | 35 | void 36 | Options::init_signals(MainMenu& main_menu) { 37 | back_button->GetSignal(Widget::OnLeftClick).Connect([&main_menu] () { 38 | main_menu.back(); 39 | }); 40 | } 41 | 42 | Options::Options(MainMenu& main_menu, Settings& settings, const std::string& name) : 43 | State(main_menu.desktop(), name), 44 | settings (settings), 45 | window_box (Box::Create(Box::Orientation::VERTICAL)), 46 | back_button(Button::Create()) { 47 | auto window = Window::Create(Window::Style::BACKGROUND); 48 | auto window_alignment = Alignment::Create(); 49 | 50 | window_alignment->SetScale({1.0f, 0.0f}); 51 | window_alignment->SetAlignment({0.0f, 0.0f}); 52 | window_alignment->Add(window_box); 53 | 54 | window->Add(window_alignment); 55 | window->SetRequisition({512.0f, 300.0f}); 56 | 57 | box->SetOrientation(Box::Orientation::VERTICAL); 58 | box->SetRequisition({300.0f, box->GetRequisition().y}); 59 | box->SetSpacing(20.0f); 60 | 61 | box->SetOrientation(Box::Orientation::VERTICAL); 62 | box->SetSpacing(20.0f); 63 | box->Pack(window); 64 | box->Pack(back_button); 65 | 66 | desktop.Add(box); 67 | 68 | init_signals(main_menu); 69 | } 70 | 71 | void 72 | Options::reset_text() { 73 | back_button->SetLabel(pgtx("options", "Back")); 74 | 75 | on_reset_text(); 76 | } 77 | 78 | void 79 | Options::on_reset_text() { 80 | 81 | } 82 | 83 | Options::~Options() = default; 84 | 85 | Options::Option::Option(const sf::String& label, Widget::Ptr control) : 86 | label(Label::Create(label)), 87 | m_control(control), 88 | widget(Box::Create()) { 89 | auto alignment1 = Alignment::Create(); 90 | auto alignment2 = Alignment::Create(); 91 | 92 | alignment1->Add(Options::Option::label); 93 | 94 | alignment1->SetScale({0.0f, 0.0f}); 95 | alignment1->SetAlignment({0.0f, 0.5f}); 96 | 97 | alignment2->Add(control); 98 | 99 | alignment2->SetScale({0.0f, 0.0f}); 100 | alignment2->SetAlignment({1.0f, 0.5f}); 101 | 102 | std::static_pointer_cast(widget)->Pack(alignment1); 103 | std::static_pointer_cast(widget)->Pack(alignment2); 104 | Option::widget->SetClass("options"); 105 | } 106 | 107 | Options::Option::Option(Widget::Ptr widget) : Options::Option(L"", widget) {} 108 | 109 | void 110 | Options::Option::change_text(const sf::String& text) { 111 | label->SetText(text); 112 | } 113 | 114 | Widget::Ptr 115 | Options::Option::control() const { 116 | return m_control; 117 | } 118 | 119 | Widget::Ptr 120 | Options::Option::to_widget() const { 121 | return widget; 122 | } 123 | 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/Gui/States/Options.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include "../State.hpp" 25 | 26 | namespace mazemaze { 27 | 28 | class Settings; 29 | 30 | namespace gui { 31 | 32 | class MainMenu; 33 | 34 | namespace states { 35 | 36 | class Options : public State { 37 | public: 38 | explicit Options(MainMenu& main_menu, Settings& settings, const std::string& name); 39 | ~Options() override; 40 | 41 | void reset_text() override final; 42 | virtual void on_reset_text(); 43 | 44 | protected: 45 | Settings& settings; 46 | 47 | sfg::Box::Ptr window_box; 48 | 49 | class Option { 50 | public: 51 | explicit Option(const sf::String& label, sfg::Widget::Ptr control); 52 | explicit Option(sfg::Widget::Ptr widget); 53 | 54 | void change_text(const sf::String& text); 55 | sfg::Widget::Ptr control() const; 56 | sfg::Widget::Ptr to_widget() const; 57 | 58 | private: 59 | sfg::Label::Ptr label; 60 | sfg::Widget::Ptr m_control; 61 | sfg::Widget::Ptr widget; 62 | }; 63 | 64 | private: 65 | sfg::Button::Ptr back_button; 66 | 67 | void init_signals(MainMenu& main_menu); 68 | }; 69 | 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Gui/States/OptionsControls.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "OptionsControls.hpp" 19 | 20 | #include "../MainMenu.hpp" 21 | 22 | #include "../../utils.hpp" 23 | #include "../../Settings.hpp" 24 | #include "../../GraphicEngine.hpp" 25 | 26 | using namespace sfg; 27 | 28 | namespace mazemaze { 29 | namespace gui { 30 | namespace states { 31 | 32 | OptionsControls::OptionsControls(MainMenu& main_menu, Settings& settings) : 33 | Options(main_menu, settings, "OptionsControls"), 34 | sensitivity_slider(Scale::Create(Scrollbar::Orientation::HORIZONTAL)), 35 | sensitivity_adjustement(sensitivity_slider->GetAdjustment()), 36 | key_change_window(*this), 37 | sensitivity_opt("", sensitivity_slider), 38 | key_opts { 39 | Option(Button::Create()), 40 | Option(Button::Create()), 41 | Option(Button::Create()), 42 | Option(Button::Create()) 43 | }, 44 | key_controls { 45 | "up", 46 | "down", 47 | "right", 48 | "left", 49 | } { 50 | reset_text(); 51 | 52 | sf::Vector2f button_size = {200.0f, 28.0f}; 53 | sf::Vector2f adjustmement_bounds = {0.0001f, 0.003f}; 54 | 55 | window_box->Pack(sensitivity_opt.to_widget()); 56 | 57 | sensitivity_slider->SetRequisition(button_size); 58 | 59 | sensitivity_adjustement = sensitivity_slider->GetAdjustment(); 60 | 61 | sensitivity_adjustement->SetLower(adjustmement_bounds.x); 62 | sensitivity_adjustement->SetUpper(adjustmement_bounds.y); 63 | 64 | sensitivity_adjustement->SetMinorStep( 65 | (adjustmement_bounds.y - adjustmement_bounds.x) / button_size.x); 66 | 67 | for (int i = 0; i < buttons_count; i++) { 68 | key_buttons[i] = std::dynamic_pointer_cast(key_opts[i].control()); 69 | update_key_button_label(i); 70 | 71 | key_buttons[i]->SetRequisition(button_size); 72 | key_buttons[i]->SetClass("verySmall"); 73 | key_buttons[i]->SetZOrder(0); 74 | 75 | window_box->Pack(key_opts[i].to_widget()); 76 | } 77 | 78 | init_signals(); 79 | 80 | center(); 81 | } 82 | 83 | OptionsControls::~OptionsControls() = default; 84 | 85 | void 86 | OptionsControls::show(bool show) { 87 | State::show(show); 88 | 89 | if (show) 90 | sensitivity_adjustement->SetValue(settings.sensitivity()); 91 | 92 | if (!show && key_change_window.is_opened()) 93 | key_change_window.close(); 94 | } 95 | 96 | void 97 | OptionsControls::tick(void*, float) { 98 | key_change_window.tick(); 99 | } 100 | 101 | void 102 | OptionsControls::center() { 103 | State::center(); 104 | 105 | if (key_change_window.is_opened()) 106 | State::center(key_change_window.window()); 107 | } 108 | 109 | void 110 | OptionsControls::on_reset_text() { 111 | key_labels = { 112 | pgtx("options", "Forward"), 113 | pgtx("options", "Backward"), 114 | pgtx("options", "Right"), 115 | pgtx("options", "Left") 116 | }; 117 | 118 | for (int i = 0; i < buttons_count; i++) 119 | key_opts[i].change_text(key_labels[i]); 120 | 121 | sensitivity_opt.change_text(pgtx("options", "Mouse sensitivity")); 122 | 123 | key_change_window.reset_text(); 124 | } 125 | 126 | void 127 | OptionsControls::update_key_button_label(int button) { 128 | std::string control = key_controls.at(button); 129 | 130 | key_buttons.at(button)->SetLabel(key_name(settings.key(control))); 131 | } 132 | 133 | void 134 | OptionsControls::init_signals() { 135 | sensitivity_adjustement->GetSignal(Adjustment::OnChange).Connect([this] () { 136 | settings.set_sensitivity(sensitivity_adjustement->GetValue()); 137 | }); 138 | 139 | for (int i = 0; i < buttons_count; i++) { 140 | key_buttons.at(i)->GetSignal(Widget::OnLeftClick).Connect([this, i] () { 141 | key_change_window.open(i); 142 | }); 143 | } 144 | } 145 | 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/Gui/States/OptionsControls.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../State.hpp" 21 | 22 | #include "Options.hpp" 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | namespace mazemaze { 34 | 35 | class Settings; 36 | 37 | namespace gui { 38 | 39 | class MainMenu; 40 | 41 | namespace states { 42 | 43 | class OptionsControls : public Options { 44 | public: 45 | static const int buttons_count = 4; 46 | 47 | explicit OptionsControls(MainMenu& main_menu, Settings& settings); 48 | ~OptionsControls() override; 49 | 50 | void show(bool show) override; 51 | void tick(void*, float delta_time) override; 52 | void center() override; 53 | void on_reset_text() override; 54 | 55 | private: 56 | class KeyChangeWindow { 57 | public: 58 | explicit KeyChangeWindow(OptionsControls& opt_ctrls); 59 | ~KeyChangeWindow(); 60 | 61 | void tick(); 62 | 63 | bool is_opened(); 64 | sfg::Window::Ptr window(); 65 | 66 | void reset_text(); 67 | void open(int button); 68 | void close(); 69 | 70 | private: 71 | OptionsControls& opt_ctrls; 72 | 73 | sfg::Window::Ptr m_window; 74 | sfg::Label::Ptr label; 75 | sfg::Button::Ptr cancel_button; 76 | sfg::Button::Ptr ok_button; 77 | sfg::Separator::Ptr button_separator; 78 | 79 | int button; 80 | bool opened; 81 | 82 | void init_signals(); 83 | }; 84 | 85 | sfg::Scale::Ptr sensitivity_slider; 86 | sfg::Adjustment::Ptr sensitivity_adjustement; 87 | std::array key_buttons; 88 | std::array key_labels; 89 | 90 | KeyChangeWindow key_change_window; 91 | 92 | Option sensitivity_opt; 93 | std::array key_opts; 94 | 95 | sf::Keyboard::Key selected_key; 96 | std::array key_controls; 97 | 98 | void update_key_button_label(int button); 99 | 100 | void init_signals(); 101 | 102 | sf::String key_name(sf::Keyboard::Key key); 103 | }; 104 | 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/Gui/States/OptionsControlsKeyChangeWindow.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "OptionsControls.hpp" 19 | 20 | #include "../../utils.hpp" 21 | #include "../../GraphicEngine.hpp" 22 | #include "../../Settings.hpp" 23 | 24 | using namespace sfg; 25 | 26 | namespace mazemaze { 27 | namespace gui { 28 | namespace states { 29 | 30 | OptionsControls::KeyChangeWindow::KeyChangeWindow(OptionsControls& opt_ctrls) : 31 | opt_ctrls(opt_ctrls), 32 | m_window (Window::Create(Window::Style::BACKGROUND)), 33 | label (Label::Create()), 34 | cancel_button (Button::Create()), 35 | ok_button (Button::Create()), 36 | button_separator(Separator::Create(Separator::Orientation::HORIZONTAL)), 37 | button(-1), 38 | opened(false) { 39 | reset_text(); 40 | 41 | auto main_box = Box::Create(Box::Orientation::VERTICAL); 42 | auto buttons_box = Box::Create(Box::Orientation::HORIZONTAL); 43 | 44 | auto separator = Separator::Create(Separator::Orientation::VERTICAL); 45 | 46 | button_separator->SetRequisition({0.0f, 0.0f}); 47 | separator->SetRequisition({0.0f, 10.0f}); 48 | 49 | buttons_box->Pack(cancel_button); 50 | buttons_box->Pack(button_separator); 51 | buttons_box->Pack(ok_button); 52 | 53 | main_box->Pack(separator); 54 | main_box->Pack(label); 55 | main_box->Pack(buttons_box); 56 | 57 | main_box->SetClass("nogap"); 58 | 59 | cancel_button->SetClass("small"); 60 | ok_button->SetClass("small"); 61 | m_window->SetClass("light"); 62 | 63 | m_window->Add(main_box); 64 | 65 | m_window->SetRequisition({300, 150}); 66 | 67 | opt_ctrls.desktop.Add(m_window); 68 | m_window->Show(opened); 69 | } 70 | 71 | OptionsControls::KeyChangeWindow::~KeyChangeWindow() { 72 | opt_ctrls.desktop.Remove(m_window); 73 | } 74 | 75 | void 76 | OptionsControls::KeyChangeWindow::tick() { 77 | if (opened) 78 | opt_ctrls.desktop.BringToFront(m_window); 79 | } 80 | 81 | void 82 | OptionsControls::KeyChangeWindow::open(int button) { 83 | if (opened) 84 | return; 85 | 86 | KeyChangeWindow::button = button; 87 | 88 | ok_button->Show(false); 89 | button_separator->Show(false); 90 | 91 | opened = true; 92 | m_window->Show(opened); 93 | 94 | opt_ctrls.center(); 95 | 96 | for (auto key_button : opt_ctrls.key_buttons) 97 | key_button->SetState(Widget::State::INSENSITIVE); 98 | 99 | init_signals(); 100 | } 101 | 102 | bool 103 | OptionsControls::KeyChangeWindow::is_opened() { 104 | return opened; 105 | } 106 | 107 | Window::Ptr 108 | OptionsControls::KeyChangeWindow::window() { 109 | return m_window; 110 | } 111 | 112 | void 113 | OptionsControls::KeyChangeWindow::reset_text() { 114 | label ->SetText (pgtx("options", "Press new key")); 115 | cancel_button->SetLabel(pgtx("options", "Cancel")); 116 | ok_button ->SetLabel(pgtx("options", "Ok")); 117 | } 118 | 119 | void 120 | OptionsControls::KeyChangeWindow::close() { 121 | GraphicEngine::inst().unwait_key(); 122 | 123 | opened = false; 124 | m_window->Show(opened); 125 | 126 | for (auto keyButton : opt_ctrls.key_buttons) 127 | keyButton->SetState(Widget::State::NORMAL); 128 | } 129 | 130 | void 131 | OptionsControls::KeyChangeWindow::init_signals() { 132 | GraphicEngine::inst().wait_key([this] (const sf::Keyboard::Key key) { 133 | ok_button->Show(true); 134 | button_separator->Show(true); 135 | 136 | opt_ctrls.selected_key = key; 137 | 138 | sf::String new_text = pgtx("options", "Pressed key is %s"); 139 | new_text.replace("%s", opt_ctrls.key_name(key)); 140 | 141 | label->SetText(new_text); 142 | 143 | opt_ctrls.center(); 144 | }); 145 | 146 | cancel_button->GetSignal(Widget::OnLeftClick).Connect([this] () { 147 | close(); 148 | }); 149 | 150 | ok_button->GetSignal(Widget::OnLeftClick).Connect([this] () { 151 | std::string control = opt_ctrls.key_controls.at(button); 152 | 153 | opt_ctrls.settings.set_key(control, opt_ctrls.selected_key); 154 | opt_ctrls.update_key_button_label(button); 155 | close(); 156 | }); 157 | } 158 | 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/Gui/States/OptionsGraphics.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "OptionsGraphics.hpp" 19 | 20 | #include "../MainMenu.hpp" 21 | 22 | #include "../../utils.hpp" 23 | #include "../../Settings.hpp" 24 | 25 | #include 26 | 27 | using namespace sfg; 28 | 29 | namespace mazemaze { 30 | namespace gui { 31 | namespace states { 32 | 33 | void 34 | OptionsGraphics::init_signals() { 35 | fullscreen_check->GetSignal(Widget::OnLeftClick).Connect([this] () { 36 | settings.set_fullscreen(fullscreen_check->IsActive()); 37 | }); 38 | 39 | antialiasing_combo->GetSignal(ComboBox::OnSelect).Connect([this] () { 40 | int item = antialiasing_combo->GetSelectedItem(); 41 | unsigned int antialiasing = 1; 42 | 43 | for (int i = 0; i < item; i++) 44 | antialiasing *= 2; 45 | 46 | if (antialiasing == 1) 47 | antialiasing = 0; 48 | 49 | settings.set_antialiasing(antialiasing); 50 | }); 51 | 52 | vsync_check->GetSignal(Widget::OnLeftClick).Connect([this] () { 53 | settings.set_vsync(vsync_check->IsActive()); 54 | }); 55 | 56 | style_combo->GetSignal(ComboBox::OnSelect).Connect([this] () { 57 | settings.set_renderer(style_combo->GetSelectedItem()); 58 | }); 59 | 60 | camera_bobbing_check->GetSignal(Widget::OnLeftClick).Connect([this] () { 61 | settings.set_camera_bobbing(camera_bobbing_check->IsActive()); 62 | }); 63 | } 64 | 65 | void 66 | OptionsGraphics::init_antialiasing_combo() { 67 | int max_antialiasing = settings.max_antialiasing(); 68 | 69 | antialiasing_combo->AppendItem(""); 70 | 71 | for (int i = 2; i <= max_antialiasing; i *= 2) 72 | antialiasing_combo->AppendItem(fmt("%dx", i)); 73 | } 74 | 75 | void 76 | OptionsGraphics::init_options() { 77 | fullscreen_check->SetActive(settings.fullscreen()); 78 | 79 | init_antialiasing_combo(); 80 | 81 | unsigned int antialiasing = settings.antialiasing(); 82 | 83 | if (antialiasing == 0) 84 | antialiasing = 1; 85 | 86 | for (unsigned int i = 0, j = 1; j <= antialiasing; i++, j *= 2) 87 | if (j == antialiasing) { 88 | antialiasing_combo->SelectItem(i); 89 | break; 90 | } 91 | 92 | vsync_check->SetActive(settings.vsync()); 93 | 94 | style_combo->AppendItem(""); 95 | style_combo->AppendItem(""); 96 | style_combo->AppendItem(""); 97 | style_combo->AppendItem(""); 98 | style_combo->SelectItem(settings.renderer()); 99 | 100 | camera_bobbing_check->SetActive(settings.camera_bobbing()); 101 | } 102 | 103 | OptionsGraphics::OptionsGraphics(MainMenu& main_menu, Settings& settings) : 104 | Options(main_menu, settings, "OptionsGraphics"), 105 | fullscreen_check (CheckButton::Create(L"")), 106 | vsync_check (CheckButton::Create(L"")), 107 | antialiasing_combo (ComboBox::Create()), 108 | style_combo (ComboBox::Create()), 109 | camera_bobbing_check(CheckButton::Create(L"")), 110 | fullscreen_opt (Option("", fullscreen_check)), 111 | vsync_opt (Option("", vsync_check)), 112 | antialiasing_opt (Option("", antialiasing_combo)), 113 | style_opt (Option("", style_combo)), 114 | camera_bobbing_opt(Option("", camera_bobbing_check)) { 115 | window_box->Pack(fullscreen_opt.to_widget()); 116 | window_box->Pack(antialiasing_opt.to_widget()); 117 | window_box->Pack(vsync_opt.to_widget()); 118 | window_box->Pack(style_opt.to_widget()); 119 | window_box->Pack(camera_bobbing_opt.to_widget()); 120 | 121 | init_signals(); 122 | init_options(); 123 | 124 | reset_text(); 125 | 126 | center(); 127 | } 128 | 129 | void 130 | OptionsGraphics::on_reset_text() { 131 | fullscreen_opt .change_text(pgtx("options", "Fullscreen")); 132 | vsync_opt .change_text(pgtx("options", "V-Sync")); 133 | antialiasing_opt .change_text(pgtx("options", "Antialiasing")); 134 | style_opt .change_text(pgtx("options", "Style")); 135 | camera_bobbing_opt.change_text(pgtx("options", "Camera Bobbing")); 136 | 137 | style_combo->ChangeItem(0, pgtx("options", "Classic")); 138 | style_combo->ChangeItem(1, pgtx("options", "Gray")); 139 | style_combo->ChangeItem(2, pgtx("options", "Brick")); 140 | style_combo->ChangeItem(3, pgtx("options", "Night Brick")); 141 | 142 | style_combo->RequestResize(); 143 | 144 | antialiasing_combo->ChangeItem(0, pgtx("options", "No")); 145 | 146 | antialiasing_combo->RequestResize(); 147 | } 148 | 149 | OptionsGraphics::~OptionsGraphics() = default; 150 | 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/Gui/States/OptionsGraphics.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../State.hpp" 21 | 22 | #include "Options.hpp" 23 | 24 | #include 25 | 26 | namespace mazemaze { 27 | 28 | class Settings; 29 | 30 | namespace gui { 31 | 32 | class MainMenu; 33 | 34 | namespace states { 35 | 36 | class OptionsGraphics : public Options { 37 | public: 38 | explicit OptionsGraphics(MainMenu& main_menu, Settings& settings); 39 | ~OptionsGraphics() override; 40 | 41 | void on_reset_text() override; 42 | 43 | private: 44 | sfg::CheckButton::Ptr fullscreen_check; 45 | sfg::CheckButton::Ptr vsync_check; 46 | sfg::ComboBox::Ptr antialiasing_combo; 47 | sfg::ComboBox::Ptr style_combo; 48 | sfg::CheckButton::Ptr camera_bobbing_check; 49 | 50 | Option fullscreen_opt; 51 | Option vsync_opt; 52 | Option antialiasing_opt; 53 | Option style_opt; 54 | Option camera_bobbing_opt; 55 | 56 | void init_signals(); 57 | void init_antialiasing_combo(); 58 | void init_options(); 59 | }; 60 | 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Gui/States/OptionsMenu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "OptionsMenu.hpp" 19 | 20 | #include "../../utils.hpp" 21 | #include "../../Settings.hpp" 22 | 23 | #include "../MainMenu.hpp" 24 | 25 | #include "OptionsGraphics.hpp" 26 | #include "OptionsControls.hpp" 27 | #include "OptionsOther.hpp" 28 | 29 | using namespace sfg; 30 | 31 | namespace mazemaze { 32 | namespace gui { 33 | namespace states { 34 | 35 | void 36 | OptionsMenu::init_signals(MainMenu& main_menu) { 37 | back_button->GetSignal(Widget::OnLeftClick).Connect([&main_menu] () { 38 | main_menu.back(); 39 | }); 40 | 41 | graphics_button->GetSignal(Widget::OnLeftClick).Connect([&main_menu, this] () { 42 | main_menu.set_state(graphics_state); 43 | }); 44 | 45 | controls_button->GetSignal(Widget::OnLeftClick).Connect([&main_menu, this] () { 46 | main_menu.set_state(controls_state); 47 | }); 48 | 49 | other_button->GetSignal(Widget::OnLeftClick).Connect([&main_menu, this] () { 50 | main_menu.set_state(other_state); 51 | }); 52 | } 53 | 54 | OptionsMenu::OptionsMenu(MainMenu& main_menu, Settings& settings) : 55 | State(main_menu.desktop(), "OptionsMenu"), 56 | graphics_button (Button::Create()), 57 | controls_button (Button::Create()), 58 | other_button (Button::Create()), 59 | back_button (Button::Create()) { 60 | reset_text(); 61 | 62 | box->SetOrientation(Box::Orientation::VERTICAL); 63 | box->SetRequisition({300.0f, box->GetRequisition().y}); 64 | box->SetSpacing(20.0f); 65 | 66 | box->Pack(graphics_button); 67 | box->Pack(controls_button); 68 | box->Pack(other_button); 69 | box->Pack(back_button); 70 | 71 | desktop.Add(box); 72 | 73 | init_signals(main_menu); 74 | 75 | center(); 76 | 77 | graphics_state = main_menu.add_state(new OptionsGraphics(main_menu, settings)); 78 | controls_state = main_menu.add_state(new OptionsControls(main_menu, settings)); 79 | other_state = main_menu.add_state(new OptionsOther (main_menu, settings)); 80 | } 81 | 82 | void 83 | OptionsMenu::reset_text() { 84 | graphics_button->SetLabel(pgtx("options", "Graphics")); 85 | controls_button->SetLabel(pgtx("options", "Controls")); 86 | other_button ->SetLabel(pgtx("options", "Other")); 87 | back_button ->SetLabel(pgtx("options", "Back")); 88 | } 89 | 90 | OptionsMenu::~OptionsMenu() = default; 91 | 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/Gui/States/OptionsMenu.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../State.hpp" 21 | 22 | namespace mazemaze { 23 | 24 | class Settings; 25 | 26 | namespace gui { 27 | 28 | class MainMenu; 29 | 30 | namespace states { 31 | 32 | class OptionsMenu : public State { 33 | public: 34 | explicit OptionsMenu(MainMenu& main_menu, Settings& settings); 35 | ~OptionsMenu() override; 36 | 37 | void reset_text() override; 38 | 39 | private: 40 | sfg::Button::Ptr graphics_button; 41 | sfg::Button::Ptr controls_button; 42 | sfg::Button::Ptr other_button; 43 | sfg::Button::Ptr back_button; 44 | 45 | int graphics_state; 46 | int controls_state; 47 | int other_state; 48 | 49 | void init_signals(MainMenu& main_menu); 50 | }; 51 | 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Gui/States/OptionsOther.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "OptionsOther.hpp" 19 | 20 | #include "../../utils.hpp" 21 | #include "../../Settings.hpp" 22 | 23 | using namespace sfg; 24 | 25 | namespace mazemaze { 26 | namespace gui { 27 | namespace states { 28 | 29 | void 30 | OptionsOther::init_signals() { 31 | lang_combo->GetSignal(ComboBox::OnSelect).Connect([this] () { 32 | auto langs = settings.supported_langs(); 33 | 34 | settings.set_lang(langs[lang_combo->GetSelectedItem()].code); 35 | }); 36 | 37 | autosave_check->GetSignal(Widget::OnLeftClick).Connect([this] () { 38 | settings.set_autosave(autosave_check->IsActive()); 39 | }); 40 | 41 | show_fps_check->GetSignal(Widget::OnLeftClick).Connect([this] () { 42 | settings.set_show_fps(show_fps_check->IsActive()); 43 | }); 44 | } 45 | 46 | void 47 | OptionsOther::init_options() { 48 | std::string cur_lang = settings.lang(); 49 | auto langs = settings.supported_langs(); 50 | 51 | int i = 0; 52 | 53 | for (auto lang = langs.begin(); lang < langs.end(); lang++, i++) { 54 | lang_combo->AppendItem(lang->name); 55 | 56 | if (lang->code == cur_lang) 57 | lang_combo->SelectItem(i); 58 | } 59 | 60 | autosave_check->SetActive(settings.autosave()); 61 | show_fps_check->SetActive(settings.show_fps()); 62 | } 63 | 64 | OptionsOther::OptionsOther(MainMenu& main_menu, Settings& settings) : 65 | Options(main_menu, settings, "OptionsOther"), 66 | lang_combo (ComboBox::Create()), 67 | autosave_check(CheckButton::Create(L"")), 68 | show_fps_check(CheckButton::Create(L"")), 69 | lang_opt (Option(lang_combo)), 70 | autosave_opt(Option(autosave_check)), 71 | show_fps_opt(Option(show_fps_check)) { 72 | reset_text(); 73 | 74 | window_box->Pack(lang_opt.to_widget()); 75 | window_box->Pack(autosave_opt.to_widget()); 76 | window_box->Pack(show_fps_opt.to_widget()); 77 | 78 | init_signals(); 79 | init_options(); 80 | 81 | center(); 82 | } 83 | 84 | void 85 | OptionsOther::on_reset_text() { 86 | lang_opt.change_text (pgtx("options", "Language")); 87 | autosave_opt.change_text(pgtx("options", "Autosave")); 88 | show_fps_opt.change_text(pgtx("options", "Show FPS")); 89 | } 90 | 91 | OptionsOther::~OptionsOther() = default; 92 | 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/Gui/States/OptionsOther.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../State.hpp" 21 | 22 | #include "Options.hpp" 23 | 24 | #include 25 | 26 | namespace mazemaze { 27 | 28 | class Settings; 29 | 30 | namespace gui { 31 | 32 | class MainMenu; 33 | 34 | namespace states { 35 | 36 | class OptionsOther : public Options { 37 | public: 38 | explicit OptionsOther(MainMenu& main_menu, Settings& settings); 39 | ~OptionsOther() override; 40 | 41 | void on_reset_text() override; 42 | 43 | private: 44 | sfg::ComboBox::Ptr lang_combo; 45 | sfg::CheckButton::Ptr autosave_check; 46 | sfg::CheckButton::Ptr show_fps_check; 47 | 48 | Option lang_opt; 49 | Option autosave_opt; 50 | Option show_fps_opt; 51 | 52 | void init_signals(); 53 | void init_options(); 54 | }; 55 | 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Gui/States/Pause.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Pause.hpp" 19 | 20 | #include "../../utils.hpp" 21 | #include "../../Game.hpp" 22 | 23 | #include "../MainMenu.hpp" 24 | 25 | using namespace sfg; 26 | 27 | namespace mazemaze { 28 | namespace gui { 29 | namespace states { 30 | 31 | Pause::Pause(MainMenu& main_menu, Game& game) : 32 | State(main_menu.desktop(), "Pause"), 33 | resume_button(Button::Create()), 34 | options_button(Button::Create()), 35 | exit_button(Button::Create()) { 36 | reset_text(); 37 | 38 | resume_button->GetSignal(Widget::OnLeftClick).Connect([&game] { 39 | game.set_paused(false); 40 | }); 41 | 42 | options_button->GetSignal(Widget::OnLeftClick).Connect([&main_menu] { 43 | main_menu.set_state(main_menu.options_state()); 44 | }); 45 | 46 | exit_button->GetSignal(Widget::OnLeftClick).Connect([&game] { 47 | game.stop(); 48 | }); 49 | 50 | box = Box::Create(Box::Orientation::VERTICAL); 51 | 52 | box->Pack(resume_button); 53 | box->Pack(options_button); 54 | box->Pack(exit_button); 55 | 56 | box->SetSpacing(20.0f); 57 | box->SetRequisition({400.0f, box->GetRequisition().y}); 58 | 59 | desktop.Add(box); 60 | 61 | center(); 62 | } 63 | 64 | void 65 | Pause::reset_text() { 66 | resume_button ->SetLabel(pgtx("pause", "Resume")); 67 | options_button->SetLabel(pgtx("pause", "Options")); 68 | exit_button ->SetLabel(pgtx("pause", "Exit to main menu")); 69 | } 70 | 71 | Pause::~Pause() = default; 72 | 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Gui/States/Pause.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../State.hpp" 21 | 22 | namespace mazemaze { 23 | 24 | class Game; 25 | 26 | namespace gui { 27 | 28 | class MainMenu; 29 | 30 | namespace states { 31 | 32 | class Pause : public State { 33 | public: 34 | explicit Pause(MainMenu& main_menu, Game& game); 35 | ~Pause() override; 36 | 37 | void reset_text() override; 38 | 39 | private: 40 | sfg::Button::Ptr resume_button; 41 | sfg::Button::Ptr options_button; 42 | sfg::Button::Ptr exit_button; 43 | }; 44 | 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Gui/States/Progress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Progress.hpp" 19 | 20 | #include "../../Game.hpp" 21 | #include "../../utils.hpp" 22 | 23 | #include "../MainMenu.hpp" 24 | 25 | using namespace sfg; 26 | 27 | namespace mazemaze { 28 | namespace gui { 29 | namespace states { 30 | 31 | void 32 | Progress::init_signals() { 33 | back_button->GetSignal(Widget::OnLeftClick).Connect([this] { 34 | if (game) { 35 | game->maze().cancel_generation(); 36 | main_menu.back(); 37 | } 38 | }); 39 | } 40 | 41 | Progress::Progress(MainMenu& main_menu) : 42 | State(main_menu.desktop(), "Progress"), 43 | main_menu(main_menu), 44 | back_button(Button::Create()), 45 | maze_size_label(Label::Create()), 46 | progress_bar(ProgressBar::Create()), 47 | game(nullptr) { 48 | reset_text(); 49 | 50 | auto button_box = Box::Create(Box::Orientation::HORIZONTAL); 51 | auto separator_vertical = Separator::Create(Separator::Orientation::VERTICAL); 52 | auto window = Window::Create(Window::Style::BACKGROUND); 53 | auto window_box = Box::Create(Box::Orientation::VERTICAL); 54 | 55 | separator_vertical->SetRequisition({0.0f, 20.0f}); 56 | 57 | maze_size_label->SetClass("newGameMazeSize"); 58 | 59 | window_box->Pack(maze_size_label); 60 | window_box->Pack(progress_bar); 61 | window_box->SetSpacing(20.0f); 62 | 63 | window->Add(window_box); 64 | 65 | button_box->Pack(back_button); 66 | button_box->SetClass("nogap"); 67 | 68 | window->SetRequisition({384.0f, 0.0f}); 69 | 70 | box = Box::Create(Box::Orientation::VERTICAL); 71 | 72 | box->Pack(window); 73 | box->Pack(separator_vertical); 74 | box->Pack(button_box); 75 | 76 | desktop.Add(box); 77 | 78 | init_signals(); 79 | 80 | center(); 81 | } 82 | 83 | void 84 | Progress::tick(void*, float) { 85 | if (game) { 86 | if (game->is_loaded()) { 87 | progress_bar->SetFraction(0); 88 | main_menu.start_game(); 89 | return; 90 | } 91 | 92 | progress_bar->SetFraction(game->maze().generation_progress()); 93 | } 94 | } 95 | 96 | void 97 | Progress::reset_text() { 98 | back_button ->SetLabel(pgtx("progress", "Cancel")); 99 | maze_size_label->SetText (pgtx("progress", "Maze generation...")); 100 | } 101 | 102 | void 103 | Progress::setGame(Game* game) { 104 | Progress::game = game; 105 | } 106 | 107 | Progress::~Progress() = default; 108 | 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/Gui/States/Progress.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../State.hpp" 21 | 22 | namespace mazemaze { 23 | 24 | class Game; 25 | 26 | namespace gui { 27 | 28 | class MainMenu; 29 | 30 | namespace states { 31 | 32 | class Progress : public State { 33 | public: 34 | const char max_size_chars = 4; 35 | 36 | explicit Progress(MainMenu& main_menu); 37 | ~Progress() override; 38 | 39 | void tick(void*, float delta_time) override; 40 | void reset_text() override; 41 | void setGame(Game* game); 42 | 43 | private: 44 | MainMenu& main_menu; 45 | 46 | sfg::Button::Ptr back_button; 47 | sfg::Label::Ptr maze_size_label; 48 | sfg::ProgressBar::Ptr progress_bar; 49 | 50 | Game* game; 51 | 52 | void init_signals(); 53 | }; 54 | 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Gui/States/Win.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Win.hpp" 19 | 20 | #include 21 | 22 | #include "../../utils.hpp" 23 | #include "../../Game.hpp" 24 | 25 | #include "../MainMenu.hpp" 26 | 27 | using namespace sfg; 28 | 29 | namespace mazemaze { 30 | namespace gui { 31 | namespace states { 32 | 33 | Win::Win(MainMenu& main_menu, Game& game) : 34 | State(main_menu.desktop(), "State"), 35 | exit_button(Button::Create()), 36 | win_label(Label::Create()), 37 | win_note_time_label(Label::Create()), 38 | win_note_size_label(Label::Create()), 39 | game(game) { 40 | reset_text(); 41 | 42 | auto win_note_time_alignment = Alignment::Create(); 43 | auto win_note_size_alignment = Alignment::Create(); 44 | 45 | win_label->SetClass("win"); 46 | 47 | win_note_time_alignment->SetAlignment({0.0f, 0.5f}); 48 | win_note_time_alignment->SetScale({0.0f, 0.0f}); 49 | win_note_time_alignment->Add(win_note_time_label); 50 | 51 | win_note_size_alignment->SetAlignment({0.0f, 0.5f}); 52 | win_note_size_alignment->SetScale({0.0f, 0.0f}); 53 | win_note_size_alignment->Add(win_note_size_label); 54 | 55 | box = Box::Create(Box::Orientation::VERTICAL); 56 | 57 | box->Pack(win_label); 58 | box->Pack(Separator::Create(Separator::Orientation::VERTICAL)); 59 | box->Pack(win_note_time_alignment); 60 | box->Pack(win_note_size_alignment); 61 | box->Pack(Separator::Create(Separator::Orientation::VERTICAL)); 62 | box->Pack(exit_button); 63 | 64 | box->SetSpacing(20.0f); 65 | box->SetRequisition({400.0f, box->GetRequisition().y}); 66 | 67 | desktop.Add(box); 68 | 69 | exit_button->GetSignal(Widget::OnLeftClick).Connect([&game] { 70 | game.stop(); 71 | }); 72 | 73 | center(); 74 | } 75 | 76 | Win::~Win() = default; 77 | 78 | void 79 | Win::show(bool show) { 80 | box->Show(show); 81 | 82 | if (show) 83 | update_labels(game); 84 | } 85 | 86 | void 87 | Win::reset_text() { 88 | exit_button->SetLabel(pgtx("win", "Exit to main menu")); 89 | win_label ->SetText (pgtx("win", "You won!")); 90 | } 91 | 92 | void 93 | Win::update_labels(Game& game) { 94 | int time = static_cast(game.time()); 95 | int secs = time % 60; 96 | int mins = (time / 60) % 60; 97 | int hours = (time / (60 * 60)) % 24; 98 | int days = time / (60 * 60 * 24); 99 | 100 | sf::String time_string(pgtx("win", "Time: ")); 101 | 102 | if (days > 0) 103 | time_string = time_string + npgtxf("win", "%d day ", "%d days ", days); 104 | 105 | if (hours > 0) 106 | time_string = time_string + npgtxf("win", "%d hour ", "%d hours ", hours); 107 | 108 | if (mins > 0) 109 | time_string = time_string + npgtxf("win", "%d min ", "%d mins ", mins); 110 | 111 | if (secs > 0) 112 | time_string = time_string + npgtxf("win", "%d sec ", "%d secs ", secs); 113 | 114 | win_note_time_label->SetText(time_string); 115 | 116 | Maze& maze = game.maze(); 117 | const sf::String maze_size = std::to_wstring((maze.size().x - 1) / 2) + 118 | L"x" + 119 | std::to_wstring((maze.size().y - 1) / 2); 120 | 121 | win_note_size_label->SetText(sf::String(pgtx("win", "Maze size: ")) + maze_size); 122 | 123 | center(); 124 | } 125 | 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/Gui/States/Win.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../State.hpp" 21 | 22 | namespace mazemaze { 23 | 24 | class Game; 25 | 26 | namespace gui { 27 | 28 | class MainMenu; 29 | 30 | namespace states { 31 | 32 | class Win : public State { 33 | public: 34 | explicit Win(MainMenu& main_menu, Game& game); 35 | ~Win() override; 36 | 37 | void show(bool show) override; 38 | void reset_text() override; 39 | 40 | private: 41 | sfg::Button::Ptr exit_button; 42 | sfg::Label::Ptr win_label; 43 | sfg::Label::Ptr win_note_time_label; 44 | sfg::Label::Ptr win_note_size_label; 45 | Game& game; 46 | 47 | void update_labels(Game& game); 48 | }; 49 | 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/IRenderable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "IRenderable.hpp" 19 | 20 | namespace mazemaze { 21 | 22 | IRenderable::~IRenderable() = default; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/IRenderable.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | namespace mazemaze { 21 | 22 | class IRenderable { 23 | public: 24 | virtual void render() = 0; 25 | virtual ~IRenderable(); 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/ITickable.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | namespace mazemaze { 21 | 22 | template 23 | class ITickable { 24 | public: 25 | virtual void tick(T, float delta_time) = 0; 26 | virtual ~ITickable(); 27 | }; 28 | 29 | template 30 | ITickable::~ITickable() = default; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/Logger.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Logger.hpp" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "utils.hpp" 26 | 27 | namespace mazemaze { 28 | 29 | Logger::Logger() : m_init_time(system_clock::now().time_since_epoch()) { 30 | }; 31 | 32 | Logger::~Logger() = default; 33 | 34 | void 35 | Logger::log(Level level, const std::string& message) { 36 | std::lock_guard lock(mutex); 37 | 38 | m_messages.emplace_back(Message(level, message)); 39 | 40 | std::ostream* stream; 41 | 42 | if (level < WARN) 43 | stream = &std::cout; 44 | else 45 | stream = &std::cerr; 46 | 47 | *stream << m_messages.back().to_string() << std::endl; 48 | 49 | for (auto& message_listener: message_listeners) 50 | message_listener(m_messages.back()); 51 | } 52 | 53 | int 54 | Logger::add_message_listener(std::function message_listener) { 55 | message_listeners.emplace_back(message_listener); 56 | 57 | return message_listeners.size() - 1; 58 | } 59 | 60 | void 61 | Logger::remove_message_listener(int id) { 62 | message_listeners.erase(message_listeners.begin() + id); 63 | } 64 | 65 | std::vector& 66 | Logger::messages() { 67 | return Logger::m_messages; 68 | } 69 | 70 | system_clock::time_point 71 | Logger::init_time() { 72 | return m_init_time; 73 | } 74 | 75 | Logger::Message::Message(Logger::Level level, std::string message) : 76 | time(system_clock::now()), 77 | level(level), 78 | message(std::move(message)) { 79 | } 80 | 81 | std::string 82 | Logger::Message::to_string() const { 83 | using namespace std::chrono; 84 | 85 | std::string level_text = ""; 86 | 87 | switch (level) { 88 | case DEBUG: 89 | level_text = DEBUG_LEVEL; 90 | break; 91 | 92 | case STATUS: 93 | level_text = STATUS_LEVEL; 94 | break; 95 | 96 | case WARN: 97 | level_text = WARN_LEVEL; 98 | break; 99 | 100 | case ERR: 101 | level_text = ERROR_LEVEL; 102 | break; 103 | } 104 | 105 | auto since_init = time - Logger::inst().m_init_time; 106 | 107 | std::string time_string = fmt( 108 | "%d.%03d", 109 | duration_cast(since_init).count(), 110 | duration_cast(since_init).count() % 1000 111 | ); 112 | 113 | int time_chars = 5; 114 | 115 | char indent[] = " "; 116 | char time_indent[] = " "; 117 | 118 | indent[7 - level_text.size()] = '\0'; 119 | 120 | if (time_string.size() < time_chars + 4) { 121 | time_indent[time_chars - (time_string.size() - 4)] = '\0'; 122 | } else { 123 | time_indent[0] = '\0'; 124 | } 125 | 126 | return fmt( 127 | "[%s%s] [%s]%s%s", 128 | time_indent, 129 | time_string.c_str(), 130 | level_text.c_str(), 131 | indent, 132 | message.c_str() 133 | ); 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/Logger.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #define DEBUG_LEVEL "DEBUG" 27 | #define STATUS_LEVEL "STATUS" 28 | #define WARN_LEVEL "WARN" 29 | #define ERROR_LEVEL "ERROR" 30 | 31 | namespace mazemaze { 32 | 33 | using std::chrono::system_clock; 34 | 35 | class Logger { 36 | public: 37 | enum Level { 38 | DEBUG = 0, 39 | STATUS = 1, 40 | WARN = 2, 41 | ERR = 3 42 | }; 43 | 44 | class Message { 45 | public: 46 | Message(Level level, std::string message); 47 | 48 | const system_clock::time_point time; 49 | const Level level; 50 | const std::string message; 51 | 52 | std::string to_string() const; 53 | }; 54 | 55 | Logger(Logger const&) = delete; 56 | void operator= (Logger const&) = delete; 57 | 58 | static Logger& inst() { 59 | static Logger instance; 60 | return instance; 61 | } 62 | 63 | void log_debug (const std::string& message); 64 | void log_status(const std::string& message); 65 | void log_warn (const std::string& message); 66 | void log_error (const std::string& message); 67 | 68 | int add_message_listener(std::function message_listener); 69 | 70 | void remove_message_listener(int id); 71 | std::vector& messages(); 72 | 73 | system_clock::time_point init_time(); 74 | private: 75 | Logger(); 76 | ~Logger(); 77 | 78 | void log(Level level, const std::string& message); 79 | 80 | const system_clock::time_point m_init_time; 81 | std::vector m_messages; 82 | std::vector> message_listeners; 83 | std::mutex mutex; 84 | }; 85 | 86 | inline void 87 | Logger::log_debug(const std::string& message) { 88 | #ifndef _NDEBUG 89 | log(DEBUG, message); 90 | #endif 91 | } 92 | 93 | inline void 94 | Logger::log_status(const std::string& message) { 95 | log(STATUS, message); 96 | } 97 | 98 | inline void 99 | Logger::log_warn(const std::string& message) { 100 | log(WARN, message); 101 | } 102 | 103 | inline void 104 | Logger::log_error(const std::string& message) { 105 | log(ERR, message); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/Maze.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include "Point.hpp" 24 | #include "Point2.hpp" 25 | 26 | #include 27 | 28 | namespace mazemaze { 29 | 30 | class Chunk; 31 | 32 | class Maze { 33 | public: 34 | explicit Maze(Point2i size); 35 | ~Maze(); 36 | 37 | bool generate(unsigned int seed); 38 | void cancel_generation(); 39 | 40 | float generation_progress() const; 41 | bool get_opened(Point2i point) const; 42 | bool get_opened(Pointf point) const; 43 | unsigned int seed () const; 44 | Chunk* chunks () const; 45 | Point2i& exit (); 46 | Point2i& start (); 47 | Point2i& size (); 48 | Point2i& chunks_count(); 49 | 50 | void set_seed(unsigned int seed); 51 | 52 | void init_chunks(); 53 | 54 | private: 55 | struct Generator { 56 | Generator(short x, short y); 57 | Generator(short x, short y, int side); 58 | 59 | unsigned short x; 60 | unsigned short y; 61 | unsigned char tried; 62 | }; 63 | 64 | bool get_opened(int x, int y) const; 65 | void set_opened(int x, int y, bool opened); 66 | 67 | void gen_exit(std::mt19937& random); 68 | void gen_start(std::mt19937& random); 69 | bool gen_step(std::stack& generator, Generator* current_generator, int side); 70 | 71 | int angles_opened; 72 | bool need_cancel; 73 | 74 | Point2i m_exit; 75 | Point2i m_start; 76 | Point2i m_size; 77 | Point2i m_chunks_count; 78 | 79 | unsigned int m_seed; 80 | Chunk* m_chunks; 81 | }; 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/MazeRenderer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "MazeRenderer.hpp" 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include "GraphicEngine.hpp" 25 | #include "Chunk.hpp" 26 | #include "Game.hpp" 27 | #include "Logger.hpp" 28 | 29 | namespace mazemaze { 30 | 31 | MazeRenderer::MazeRenderer(Game& game) : maze(game.maze()), 32 | deleted(true), 33 | old_hcp(-1, -1) {} 34 | 35 | MazeRenderer::~MazeRenderer() { 36 | if (!deleted) 37 | disable(); 38 | } 39 | 40 | void 41 | MazeRenderer::enable() { 42 | int chunks_count = maze.chunks_count().x * maze.chunks_count().y; 43 | 44 | visible = new int[16] {-1}; 45 | compiled = new bool[chunks_count] {false}; 46 | draw_list = glGenLists(chunks_count); 47 | 48 | set_states(); 49 | on_enable(); 50 | 51 | GraphicEngine::inst().set_on_set_states_callback([this] { 52 | this->set_states(); 53 | }); 54 | 55 | deleted = false; 56 | } 57 | 58 | void 59 | MazeRenderer::disable() { 60 | GraphicEngine::inst().set_on_set_states_callback([] {}); 61 | 62 | on_disable(); 63 | 64 | int chunk_count = maze.chunks_count().x * maze.chunks_count().y; 65 | 66 | glDeleteLists(draw_list, chunk_count); 67 | 68 | delete [] visible; 69 | delete [] compiled; 70 | 71 | deleted = true; 72 | } 73 | 74 | void 75 | MazeRenderer::tick(Game& game, float delta_time) { 76 | bool force = false; 77 | 78 | Player& player = game.player(); 79 | 80 | Point2i p( 81 | static_cast(player.position().x) / (Chunk::SIZE / 2), 82 | static_cast(player.position().z) / (Chunk::SIZE / 2) 83 | ); 84 | 85 | if (p != old_hcp || force) { 86 | Logger::inst().log_debug("Re-enabling chunks."); 87 | 88 | old_hcp = p; 89 | 90 | for (int i = 0; i < 16; i++) 91 | visible[i] = -1; 92 | 93 | if (p.x % 2 == 0) p.x--; 94 | if (p.y % 2 == 0) p.y--; 95 | 96 | p.x /= 2; 97 | p.y /= 2; 98 | 99 | Point2i pe(p.x + 2, p.y + 2); 100 | 101 | if (p.x < 0) p.x = 0; 102 | if (p.y < 0) p.y = 0; 103 | 104 | auto& chunks_count = maze.chunks_count(); 105 | 106 | if (pe.x > chunks_count.x) pe.x = chunks_count.x; 107 | if (pe.y > chunks_count.y) pe.y = chunks_count.y; 108 | 109 | for (int i = p.x; i < pe.x; i++) 110 | for (int j = p.y; j < pe.y; j++) { 111 | int chunk_num = i + j * chunks_count.x; 112 | 113 | enable_chunk(chunk_num); 114 | } 115 | } 116 | 117 | on_tick(delta_time); 118 | } 119 | 120 | void 121 | MazeRenderer::render() { 122 | int chunks[16 + 1]; 123 | int index = 0; 124 | 125 | chunks[16] = -1; 126 | 127 | for (int i = 0; i < 16; i++) { 128 | if (visible[i] != -1) { 129 | chunks[index] = visible[i]; 130 | index++; 131 | } else { 132 | chunks[index] = -1; 133 | break; 134 | } 135 | } 136 | 137 | render_chunks(chunks); 138 | } 139 | 140 | void 141 | MazeRenderer::set_states() { 142 | } 143 | 144 | void 145 | MazeRenderer::on_enable() { 146 | } 147 | 148 | void 149 | MazeRenderer::on_disable() { 150 | } 151 | 152 | void 153 | MazeRenderer::enable_chunk(int num) { 154 | if (!compiled[num]) 155 | compile_chunk(num); 156 | 157 | for (int i = 0; i < 16; i++) { 158 | if (visible[i] == -1) { 159 | visible[i] = num; 160 | break; 161 | } 162 | } 163 | } 164 | 165 | void 166 | MazeRenderer::render_chunks(int chunks[]) { 167 | for (; *chunks != -1; chunks++) 168 | glCallList(draw_list + *chunks); 169 | } 170 | 171 | } 172 | -------------------------------------------------------------------------------- /src/MazeRenderer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "ITickable.hpp" 21 | #include "Point2.hpp" 22 | 23 | namespace mazemaze { 24 | 25 | class Maze; 26 | class Game; 27 | 28 | class MazeRenderer : public ITickable { 29 | public: 30 | explicit MazeRenderer(Game& game); 31 | virtual ~MazeRenderer() = 0; 32 | 33 | void enable(); 34 | void disable(); 35 | void tick(Game& game, float delta_time) override; 36 | void render(); 37 | virtual void render_sky() = 0; 38 | 39 | protected: 40 | int* visible; 41 | Maze& maze; 42 | bool* compiled; 43 | unsigned int draw_list; 44 | bool deleted; 45 | 46 | virtual void set_states(); 47 | virtual void on_enable(); 48 | virtual void on_disable(); 49 | virtual void on_tick(float delta_time) = 0; 50 | virtual void enable_chunk(int num); 51 | virtual void compile_chunk(int num) = 0; 52 | virtual void render_chunks(int chunks[]); 53 | 54 | private: 55 | Point2i old_hcp; 56 | }; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/MazeRenderers/Brick.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../MazeRenderer.hpp" 21 | #include "../Skybox.hpp" 22 | 23 | namespace objl { 24 | 25 | class Mesh; 26 | 27 | } 28 | 29 | namespace mazemaze { 30 | 31 | class Game; 32 | 33 | namespace renderers { 34 | 35 | class Brick : public MazeRenderer { 36 | public: 37 | explicit Brick(Game& game); 38 | ~Brick() override; 39 | 40 | protected: 41 | Game& game; 42 | 43 | private: 44 | enum Angle { 45 | NO = 0, 46 | INNER = 1, 47 | OUTER = 2, 48 | }; 49 | 50 | const int mesh_count; 51 | 52 | Skybox skybox; 53 | int mesh_draw_list; 54 | 55 | void compile_walls(); 56 | void compile_wall(objl::Mesh& mesh, Angle angle_type, bool v_mirror, bool side); 57 | void draw_mortar(Angle angle_type, bool side); 58 | unsigned int get_mesh(Angle angle_type, bool v_mirror, bool side); 59 | 60 | Angle get_angle(bool openeds[]); 61 | 62 | void set_states() override; 63 | void on_enable() override; 64 | void on_disable() override; 65 | void compile_chunk(int num) override; 66 | void on_tick(float deltaTime) override; 67 | void render_chunks(int chunks[]) override; 68 | void render_sky() override; 69 | void render_wall(Angle left_angle, Angle right_angle, bool flip); 70 | }; 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/MazeRenderers/Classic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Classic.hpp" 19 | 20 | #include 21 | 22 | #include "../Logger.hpp" 23 | #include "../utils.hpp" 24 | #include "../Chunk.hpp" 25 | #include "../Game.hpp" 26 | #include "../Camera.hpp" 27 | 28 | namespace mazemaze { 29 | namespace renderers { 30 | 31 | Classic::Classic(Game& game) : 32 | MazeRenderer(game), 33 | star_sky(1024, 0.0f, Rotation(1.5f, 0.7f, 0.0f)), 34 | game(game) {} 35 | 36 | Classic::~Classic() = default; 37 | 38 | void 39 | Classic::compile_chunk(int num) { 40 | Point2i end(Chunk::SIZE, Chunk::SIZE); 41 | Point2i i; 42 | Point2i pos( 43 | (num % maze.chunks_count().x) * Chunk::SIZE, 44 | (num / maze.chunks_count().x) * Chunk::SIZE 45 | ); 46 | 47 | Logger::inst().log_debug(fmt("Compiling chunk %d at %d %d.", num, pos.x, pos.y)); 48 | 49 | glNewList(draw_list + num, GL_COMPILE); 50 | 51 | glPushMatrix(); 52 | 53 | glTranslatef(pos.x, 0.0, pos.y); 54 | 55 | glBegin(GL_QUADS); 56 | 57 | glColor3f(1.0f, 0.0f, 1.0f); 58 | 59 | if (pos.x + Chunk::SIZE > maze.size().x) 60 | end.x = maze.size().x % Chunk::SIZE; 61 | 62 | if (pos.y + Chunk::SIZE > maze.size().y) 63 | end.y = maze.size().y % Chunk::SIZE; 64 | 65 | glVertex3i(0, 0, end.y); 66 | glVertex3i(end.x, 0, end.y); 67 | glVertex3i(end.x, 0, 0); 68 | glVertex3i(0, 0, 0); 69 | 70 | for (i.x = 0; i.x < end.x; i.x++) 71 | for (i.y = 0; i.y < end.y; i.y++) 72 | if (maze.get_opened(Point2i(i.x + pos.x, i.y + pos.y))) { 73 | if (!maze.get_opened(Point2i(i.x + 1 + pos.x, i.y + pos.y))) { 74 | glColor3f(1.0f, 0.0f, 0.0f); 75 | 76 | glVertex3i(i.x + 1, 0, i.y + 1); 77 | glVertex3i(i.x + 1, 1, i.y + 1); 78 | glVertex3i(i.x + 1, 1, i.y); 79 | glVertex3i(i.x + 1, 0, i.y); 80 | } 81 | 82 | if (!maze.get_opened(Point2i(i.x - 1 + pos.x, i.y + pos.y))) { 83 | glColor3f(0.0f, 1.0f, 1.0f); 84 | 85 | glVertex3i(i.x, 0, i.y); 86 | glVertex3i(i.x, 1, i.y); 87 | glVertex3i(i.x, 1, i.y + 1); 88 | glVertex3i(i.x, 0, i.y + 1); 89 | } 90 | 91 | if (!maze.get_opened(Point2i(i.x + pos.x, i.y + 1 + pos.y))) { 92 | glColor3f(0.0f, 0.0f, 1.0f); 93 | 94 | glVertex3i(i.x, 0, i.y + 1); 95 | glVertex3i(i.x, 1, i.y + 1); 96 | glVertex3i(i.x + 1, 1, i.y + 1); 97 | glVertex3i(i.x + 1, 0, i.y + 1); 98 | } 99 | 100 | if (!maze.get_opened(Point2i(i.x + pos.x, i.y - 1 + pos.y))) { 101 | glColor3f(1.0f, 1.0f, 0.0f); 102 | 103 | glVertex3i(i.x + 1, 0, i.y); 104 | glVertex3i(i.x + 1, 1, i.y); 105 | glVertex3i(i.x, 1, i.y); 106 | glVertex3i(i.x, 0, i.y); 107 | } 108 | } else { 109 | glColor3f(0.0f, 1.0f, 0.0f); 110 | 111 | glVertex3i(i.x, 1, i.y); 112 | glVertex3i(i.x, 1, i.y + 1); 113 | glVertex3i(i.x + 1, 1, i.y + 1); 114 | glVertex3i(i.x + 1, 1, i.y); 115 | } 116 | 117 | glEnd(); 118 | 119 | glPopMatrix(); 120 | 121 | glEndList(); 122 | 123 | compiled[num] = true; 124 | } 125 | 126 | void 127 | Classic::on_tick(float) { 128 | star_sky.set_time(game.time()); 129 | } 130 | 131 | void 132 | Classic::render_sky() { 133 | star_sky.render(); 134 | } 135 | 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/MazeRenderers/Classic.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../MazeRenderer.hpp" 21 | #include "../StarSky.hpp" 22 | 23 | namespace mazemaze { 24 | 25 | class Game; 26 | 27 | namespace renderers { 28 | 29 | class Classic : public MazeRenderer { 30 | public: 31 | explicit Classic(Game& game); 32 | ~Classic() override; 33 | 34 | private: 35 | StarSky star_sky; 36 | Game& game; 37 | 38 | void compile_chunk(int num) override; 39 | void on_tick(float delta_time) override; 40 | void render_sky() override; 41 | }; 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/MazeRenderers/Gray.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Gray.hpp" 19 | 20 | #include 21 | 22 | #include "../Logger.hpp" 23 | #include "../utils.hpp" 24 | #include "../Chunk.hpp" 25 | #include "../Game.hpp" 26 | #include "../Camera.hpp" 27 | 28 | namespace mazemaze { 29 | namespace renderers { 30 | 31 | Gray::Gray(Game& game) : 32 | MazeRenderer(game), 33 | game(game), 34 | skybox(50, 0.67f, 0.85f, 1.0f) {} 35 | 36 | Gray::~Gray() = default; 37 | 38 | void 39 | Gray::set_states() { 40 | glEnable(GL_LIGHT0); 41 | } 42 | 43 | void 44 | Gray::on_disable() { 45 | glDisable(GL_LIGHT0); 46 | } 47 | 48 | void 49 | Gray::compile_chunk(int num) { 50 | Point2i end(Chunk::SIZE, Chunk::SIZE); 51 | Point2i i; 52 | Point2i pos( 53 | (num % maze.chunks_count().x) * Chunk::SIZE, 54 | (num / maze.chunks_count().x) * Chunk::SIZE 55 | ); 56 | 57 | Logger::inst().log_debug(fmt("Compiling chunk %d at %d %d.", num, pos.x, pos.y)); 58 | 59 | glNewList(draw_list + num, GL_COMPILE); 60 | 61 | glPushMatrix(); 62 | 63 | glTranslatef(pos.x, 0.0, pos.y); 64 | 65 | glBegin(GL_QUADS); 66 | 67 | glColor3f(0.5f, 0.5f, 0.5f); 68 | 69 | if (pos.x + Chunk::SIZE > maze.size().x) 70 | end.x = maze.size().x % Chunk::SIZE; 71 | 72 | if (pos.y + Chunk::SIZE > maze.size().y) 73 | end.y = maze.size().y % Chunk::SIZE; 74 | 75 | glNormal3f(0.0f, 1.0f, 0.0f); 76 | 77 | glVertex3i(0, 0, end.y); 78 | glVertex3i(end.x, 0, end.y); 79 | glVertex3i(end.x, 0, 0); 80 | glVertex3i(0, 0, 0); 81 | 82 | for (i.x = 0; i.x < end.x; i.x++) 83 | for (i.y = 0; i.y < end.y; i.y++) 84 | if (maze.get_opened(Point2i(i.x + pos.x, i.y + pos.y))) { 85 | if (!maze.get_opened(Point2i(i.x + 1 + pos.x, i.y + pos.y))) { 86 | glNormal3f(-1.0f, 0.0f, 0.0f); 87 | 88 | glVertex3i(i.x + 1, 0, i.y + 1); 89 | glVertex3i(i.x + 1, 1, i.y + 1); 90 | glVertex3i(i.x + 1, 1, i.y); 91 | glVertex3i(i.x + 1, 0, i.y); 92 | } 93 | 94 | if (!maze.get_opened(Point2i(i.x - 1 + pos.x, i.y + pos.y))) { 95 | glNormal3f(1.0f, 0.0f, 0.0f); 96 | 97 | glVertex3i(i.x, 0, i.y); 98 | glVertex3i(i.x, 1, i.y); 99 | glVertex3i(i.x, 1, i.y + 1); 100 | glVertex3i(i.x, 0, i.y + 1); 101 | } 102 | 103 | if (!maze.get_opened(Point2i(i.x + pos.x, i.y + 1 + pos.y))) { 104 | glNormal3f(0.0f, 0.0f, -1.0f); 105 | 106 | glVertex3i(i.x, 0, i.y + 1); 107 | glVertex3i(i.x, 1, i.y + 1); 108 | glVertex3i(i.x + 1, 1, i.y + 1); 109 | glVertex3i(i.x + 1, 0, i.y + 1); 110 | } 111 | 112 | if (!maze.get_opened(Point2i(i.x + pos.x, i.y - 1 + pos.y))) { 113 | glNormal3f(0.0f, 0.0f, 1.0f); 114 | 115 | glVertex3i(i.x + 1, 0, i.y); 116 | glVertex3i(i.x + 1, 1, i.y); 117 | glVertex3i(i.x, 1, i.y); 118 | glVertex3i(i.x, 0, i.y); 119 | } 120 | } else { 121 | glNormal3f(0.0f, 1.0f, 0.0f); 122 | 123 | glVertex3i(i.x, 1, i.y); 124 | glVertex3i(i.x, 1, i.y + 1); 125 | glVertex3i(i.x + 1, 1, i.y + 1); 126 | glVertex3i(i.x + 1, 1, i.y); 127 | } 128 | 129 | glEnd(); 130 | 131 | glPopMatrix(); 132 | 133 | glEndList(); 134 | 135 | compiled[num] = true; 136 | } 137 | 138 | void 139 | Gray::on_tick(float) { 140 | } 141 | 142 | void 143 | Gray::render_chunks(int chunks[]) { 144 | float light0_diffuse[] = { 1.0f, 0.9f , 0.8f }; 145 | float light0_ambient[] = { 0.5f, 0.55f, 0.75f }; 146 | float light0_position[] = { 0.5f, 0.75f, 0.25f, 0.0f }; 147 | 148 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); 149 | glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); 150 | glLightfv(GL_LIGHT0, GL_POSITION, light0_position); 151 | 152 | glEnable(GL_LIGHTING); 153 | MazeRenderer::render_chunks(chunks); 154 | glDisable(GL_LIGHTING); 155 | } 156 | 157 | void 158 | Gray::render_sky() { 159 | skybox.render(); 160 | } 161 | 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/MazeRenderers/Gray.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "../MazeRenderer.hpp" 21 | #include "../Skybox.hpp" 22 | 23 | namespace mazemaze { 24 | 25 | class Game; 26 | 27 | namespace renderers { 28 | 29 | class Gray : public MazeRenderer { 30 | public: 31 | explicit Gray(Game& game); 32 | ~Gray() override; 33 | 34 | private: 35 | Game& game; 36 | Skybox skybox; 37 | 38 | void set_states() override; 39 | void on_disable() override; 40 | void compile_chunk(int num) override; 41 | void on_tick(float delta_time) override; 42 | void render_chunks(int chunks[]) override; 43 | void render_sky() override; 44 | }; 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/MazeRenderers/NightBrick.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "NightBrick.hpp" 19 | 20 | #include 21 | 22 | #include "../Logger.hpp" 23 | #include "../utils.hpp" 24 | #include "../Game.hpp" 25 | #include "../Camera.hpp" 26 | 27 | namespace mazemaze { 28 | namespace renderers { 29 | 30 | NightBrick::NightBrick(mazemaze::Game& game) : 31 | Brick(game), 32 | starSky(1024, 0.0f, Rotation(1.5f, 0.7f, 0.0f)) {} 33 | 34 | void 35 | NightBrick::on_tick(float) { 36 | starSky.set_time(game.time()); 37 | } 38 | 39 | void 40 | NightBrick::set_states() { 41 | glEnable(GL_LIGHT0); 42 | glEnable(GL_LIGHT1); 43 | 44 | float light0_diffuse[] = { 0.35f, 0.4f , 0.45f }; 45 | float light0_ambient[] = { 0.05f, 0.055f, 0.06f }; 46 | float light0_position[] = { 0.5f , 0.75f , 0.25f, 0.0f}; 47 | 48 | glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); 49 | glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); 50 | glLightfv(GL_LIGHT0, GL_POSITION, light0_position); 51 | 52 | float light1_diffuse[] = { 0.3f, 0.2f, 0.175f }; 53 | float light1_ambient[] = { 0.0f, 0.0f, 0.0f }; 54 | 55 | glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse); 56 | glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient); 57 | 58 | glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.8f); 59 | glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 1.0f); 60 | 61 | float fogColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; 62 | float g_FogDensity = 0.25f; 63 | 64 | glFogfv(GL_FOG_COLOR, fogColor); 65 | glFogi(GL_FOG_MODE, GL_EXP); 66 | glFogf(GL_FOG_DENSITY, g_FogDensity); 67 | glFogf(GL_FOG_START, 0); 68 | glFogf(GL_FOG_END, 10.0f); 69 | } 70 | 71 | void 72 | NightBrick::render_chunks(int chunks[]) { 73 | const auto& position = game.player().camera().position(); 74 | 75 | float light1_position[] = { position.x, position.y, position.z, 1.0f }; 76 | 77 | glLightfv(GL_LIGHT1, GL_POSITION, light1_position); 78 | 79 | glEnable(GL_FOG); 80 | glEnable(GL_LIGHTING); 81 | 82 | MazeRenderer::render_chunks(chunks); 83 | 84 | glDisable(GL_LIGHTING); 85 | glDisable(GL_FOG); 86 | } 87 | 88 | void 89 | NightBrick::render_sky() { 90 | starSky.render(); 91 | } 92 | 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/MazeRenderers/NightBrick.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "Brick.hpp" 21 | 22 | #include "../StarSky.hpp" 23 | 24 | namespace mazemaze { 25 | 26 | class Game; 27 | 28 | namespace renderers { 29 | 30 | class NightBrick : public Brick 31 | { 32 | public: 33 | explicit NightBrick(Game& game); 34 | 35 | private: 36 | StarSky starSky; 37 | 38 | void on_tick(float delta_time) override; 39 | void set_states() override; 40 | void render_chunks(int chunks[]) override; 41 | void render_sky() override; 42 | }; 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Player.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "ITickable.hpp" 21 | 22 | #include 23 | 24 | #include "Camera.hpp" 25 | #include "CameraBobbing.hpp" 26 | #include "TickableHandler.hpp" 27 | #include "Point.hpp" 28 | #include "Point2.hpp" 29 | #include "Rotation.hpp" 30 | 31 | namespace mazemaze { 32 | 33 | class Maze; 34 | class Game; 35 | class Settings; 36 | 37 | class Player : public ITickable { 38 | public: 39 | explicit Player(Pointf position); 40 | ~Player(); 41 | 42 | void start(Maze& maze); 43 | void tick(Game& game, float delta_time) override; 44 | 45 | Camera& camera(); 46 | 47 | bool is_moving() const; 48 | 49 | Pointf& position(); 50 | 51 | private: 52 | Camera m_camera; 53 | TickableHandler tickable_handler; 54 | CameraBobbing* camera_bobbing; 55 | 56 | Pointf m_position; 57 | Point2f m_move_vector; 58 | 59 | float speed; 60 | float height; 61 | float width; 62 | 63 | void try_move(Maze& maze, Pointf position); 64 | bool check_collision(Maze& maze, Pointf position); 65 | void sum_vector(float angle, Point2f& vec); 66 | void setup_camera_bobbing(const Settings& settings); 67 | }; 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/Point.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Point.hpp" 19 | 20 | namespace mazemaze { 21 | 22 | template 23 | Point::Point(T x, T y, T z) : x(x), y(y), z(z) { 24 | } 25 | 26 | template 27 | Point::Point() : x(0), y(0), z(0) { 28 | } 29 | 30 | template 31 | void 32 | Point::set(Point point) { 33 | x = point.x; 34 | y = point.y; 35 | z = point.z; 36 | } 37 | 38 | template 39 | bool 40 | Point::operator==(Point point) { 41 | return x == point.x && y == point.y && z == point.z; 42 | } 43 | 44 | template 45 | bool 46 | Point::operator!=(Point point) { 47 | return !operator==(point); 48 | } 49 | 50 | template class Point; 51 | template class Point; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/Point.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | namespace mazemaze { 21 | 22 | template 23 | class Point { 24 | public: 25 | explicit Point(T x, T y, T z); 26 | Point(); 27 | 28 | void set(Point point); 29 | 30 | bool operator==(Point point); 31 | bool operator!=(Point point); 32 | 33 | T x; 34 | T y; 35 | T z; 36 | }; 37 | 38 | typedef Point Pointf; 39 | typedef Point Pointi; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/Point2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Point2.hpp" 19 | 20 | namespace mazemaze { 21 | 22 | template 23 | Point2::Point2(T x, T y) : x(x), y(y) { 24 | } 25 | 26 | template 27 | Point2::Point2() : x(0), y(0) { 28 | } 29 | 30 | template 31 | void 32 | Point2::set(Point2 point) { 33 | x = point.x; 34 | y = point.y; 35 | } 36 | 37 | template 38 | bool 39 | Point2::operator==(Point2 point) { 40 | return x == point.x && y == point.y; 41 | } 42 | 43 | template 44 | bool 45 | Point2::operator!=(Point2 point) { 46 | return !operator==(point); 47 | } 48 | 49 | template class Point2; 50 | template class Point2; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/Point2.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | namespace mazemaze { 21 | 22 | template 23 | class Point2 { 24 | public: 25 | explicit Point2(T x, T y); 26 | Point2(); 27 | 28 | void set(Point2 point); 29 | 30 | bool operator==(Point2 point); 31 | bool operator!=(Point2 point); 32 | 33 | T x; 34 | T y; 35 | }; 36 | 37 | typedef Point2 Point2f; 38 | typedef Point2 Point2i; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/Rotation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Rotation.hpp" 19 | 20 | #include 21 | 22 | namespace mazemaze { 23 | 24 | Rotation::Rotation(float pitch, float yaw, float roll) : Rotation() { 25 | set_pitch(pitch); 26 | set_yaw (yaw); 27 | set_roll (roll); 28 | } 29 | 30 | Rotation::Rotation() : 31 | m_pitch(0.0f), 32 | m_yaw (0.0f), 33 | m_roll (0.0f) { 34 | } 35 | 36 | void 37 | Rotation::set(Rotation rotation) { 38 | m_pitch = rotation.m_pitch; 39 | m_yaw = rotation.m_yaw; 40 | m_roll = rotation.m_roll; 41 | } 42 | 43 | float 44 | Rotation::pitch() const { 45 | return m_pitch; 46 | } 47 | 48 | float 49 | Rotation::yaw() const { 50 | return m_yaw; 51 | } 52 | 53 | float 54 | Rotation::roll() const { 55 | return m_roll; 56 | } 57 | 58 | void 59 | Rotation::set_pitch(float pitch) { 60 | m_pitch = normalize(pitch); 61 | } 62 | 63 | void 64 | Rotation::set_yaw(float yaw) { 65 | m_yaw = normalize(yaw); 66 | } 67 | 68 | void 69 | Rotation::set_roll(float roll) { 70 | m_roll = normalize(roll); 71 | } 72 | 73 | float 74 | Rotation::normalize(float value) { 75 | float pi2 = M_PI * 2.0f; 76 | 77 | return value - (static_cast(value / pi2) * pi2); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/Rotation.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | namespace mazemaze { 21 | 22 | class Rotation { 23 | public: 24 | explicit Rotation(float pitch, float yaw, float roll); 25 | Rotation(); 26 | 27 | void set(Rotation rotation); 28 | 29 | float pitch() const; 30 | float yaw () const; 31 | float roll () const; 32 | 33 | void set_pitch(float pitch); 34 | void set_yaw (float yaw ); 35 | void set_roll (float roll ); 36 | 37 | private: 38 | float m_pitch; 39 | float m_yaw; 40 | float m_roll; 41 | 42 | float normalize(float value); 43 | }; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/Saver.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace mazemaze { 25 | namespace gui { 26 | 27 | class MainMenu; 28 | 29 | } 30 | 31 | class Game; 32 | class Chunk; 33 | class Settings; 34 | 35 | class Saver { 36 | public: 37 | static const char version[]; 38 | 39 | static bool save_exists(Settings& settings); 40 | 41 | Saver(Settings& settings); 42 | ~Saver(); 43 | 44 | Game* load(gui::MainMenu& main_menu); 45 | void save(); 46 | void delete_save(); 47 | 48 | float last_save_time() const; 49 | 50 | void set_game(Game& game); 51 | 52 | private: 53 | Game* game; 54 | Settings& settings; 55 | float m_last_save_time; 56 | bool virgin; 57 | 58 | std::mutex mutex; 59 | 60 | void save_game (std::ostream& stream); 61 | void save_player(std::ostream& stream); 62 | void save_maze (std::ostream& stream); 63 | void save_chunks(std::ostream& stream); 64 | 65 | static std::string get_filename(const Settings& settings); 66 | 67 | static void save_chunk(std::ostream& stream, Chunk& chunk); 68 | static void load_chunk(std::istream& stream, Chunk& chunk); 69 | }; 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/Settings.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2023, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | namespace mazemaze { 27 | 28 | class Game; 29 | 30 | namespace gui { 31 | 32 | class MainMenu; 33 | 34 | } 35 | 36 | class Settings { 37 | public: 38 | struct Language { 39 | const std::wstring name; 40 | const std::string code; 41 | 42 | Language (const wchar_t* name, const char* code) : 43 | name(name), 44 | code(code) {} 45 | }; 46 | 47 | explicit Settings(bool read_config=true); 48 | ~Settings(); 49 | 50 | void save(); 51 | 52 | std::string lang() const; 53 | unsigned int antialiasing() const; 54 | unsigned int max_antialiasing() const; 55 | bool fullscreen() const; 56 | bool vsync() const; 57 | bool autosave() const; 58 | float autosave_time() const; 59 | int renderer() const; 60 | bool show_fps() const; 61 | sf::Keyboard::Key key(const std::string& control); 62 | const std::vector& supported_langs() const; 63 | float sensitivity() const; 64 | std::string data_dir() const; 65 | bool camera_bobbing() const; 66 | 67 | void set_main_menu(gui::MainMenu* main_menu); 68 | 69 | void set_lang(const std::string &lang); 70 | void set_antialiasing(unsigned int antialiasing); 71 | void set_fullscreen(bool fullscreen); 72 | void set_vsync(bool vsync); 73 | void set_autosave(bool autosave); 74 | void set_autosave_time(float autosave_time); 75 | void set_renderer(int id); 76 | void set_show_fps(bool show_fps); 77 | void set_key(const std::string& control, sf::Keyboard::Key key); 78 | void set_sensitivity(float sensitivity); 79 | void set_camera_bobbing(float camera_bobbing); 80 | 81 | private: 82 | std::string m_data_dir; 83 | std::string m_config_file; 84 | 85 | gui::MainMenu* m_main_menu; 86 | 87 | std::string m_lang; 88 | std::vector m_supported_langs; 89 | unsigned int m_antialiasing; 90 | bool m_autosave; 91 | float m_autosave_time; 92 | int m_renderer; 93 | bool m_show_fps; 94 | float m_sensitivity; 95 | bool m_camera_bobbing; 96 | 97 | std::map controls; 98 | 99 | std::string reset_locales(); 100 | 101 | #ifdef _WIN32 102 | 103 | void set_environment(); 104 | 105 | #endif 106 | 107 | void init_data_dir(); 108 | void write_config(); 109 | bool read_config(); 110 | }; 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/Skybox.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "Skybox.hpp" 19 | 20 | #include 21 | 22 | namespace mazemaze { 23 | 24 | Skybox::Skybox(int size, float red, float green, float blue) : 25 | size(size), 26 | red(red), 27 | green(green), 28 | blue(blue), 29 | list(0) {} 30 | 31 | Skybox::~Skybox() = default; 32 | 33 | void 34 | Skybox::render() { 35 | if (list == 0) 36 | compile(); 37 | 38 | glCallList(list); 39 | } 40 | 41 | void 42 | Skybox::compile() { 43 | list = glGenLists(1); 44 | 45 | glNewList(list, GL_COMPILE); 46 | 47 | glColor3f(red, green, blue); 48 | 49 | glBegin(GL_QUADS); 50 | glVertex3i( size, -size, -size); 51 | glVertex3i( size, -size, size); 52 | glVertex3i( size, size, size); 53 | glVertex3i( size, size, -size); 54 | 55 | glVertex3i(-size, size, -size); 56 | glVertex3i(-size, size, size); 57 | glVertex3i(-size, -size, size); 58 | glVertex3i(-size, -size, -size); 59 | 60 | glVertex3i( size, size, -size); 61 | glVertex3i( size, size, size); 62 | glVertex3i(-size, size, size); 63 | glVertex3i(-size, size, -size); 64 | 65 | glVertex3i(-size, -size, -size); 66 | glVertex3i(-size, -size, size); 67 | glVertex3i( size, -size, size); 68 | glVertex3i( size, -size, -size); 69 | 70 | glVertex3i(-size, -size, size); 71 | glVertex3i(-size, size, size); 72 | glVertex3i( size, size, size); 73 | glVertex3i( size, -size, size); 74 | 75 | glVertex3i( size, -size, -size); 76 | glVertex3i( size, size, -size); 77 | glVertex3i(-size, size, -size); 78 | glVertex3i(-size, -size, -size); 79 | glEnd(); 80 | 81 | glEndList(); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/Skybox.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "IRenderable.hpp" 21 | 22 | namespace mazemaze { 23 | 24 | class Skybox : public IRenderable { 25 | public: 26 | explicit Skybox(int size, float red, float green, float blue); 27 | ~Skybox() override; 28 | 29 | public: 30 | int size; 31 | float red; 32 | float green; 33 | float blue; 34 | int list; 35 | 36 | void render() override; 37 | void compile(); 38 | }; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/StarSky.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2022, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "StarSky.hpp" 19 | 20 | #include 21 | #include 22 | 23 | #include "utils.hpp" 24 | 25 | #include 26 | 27 | namespace mazemaze { 28 | 29 | StarSky::StarSky(int star_count, float time_speed, Rotation rotation) : 30 | star_count(star_count), 31 | distance(90.0f), 32 | m_rotation(rotation), 33 | time(0.0f), 34 | time_speed(time_speed), 35 | stars(star_count) { 36 | std::mt19937 rand_gen(0); 37 | std::uniform_real_distribution coord_interval(-1.0, 1.0); 38 | std::uniform_int_distribution<> size_interval(0, 11); 39 | 40 | for (auto star = stars.begin(); star < stars.end();) { 41 | Pointf rand( 42 | coord_interval(rand_gen), 43 | coord_interval(rand_gen), 44 | coord_interval(rand_gen) 45 | ); 46 | 47 | int size_rand = size_interval(rand_gen); 48 | 49 | float distance = powfi(rand.x, 2) + powfi(rand.y, 2) + powfi(rand.z, 2); 50 | 51 | if (distance <= 1.0f) { 52 | distance = std::sqrt(distance); 53 | 54 | star->x = rand.x / distance; 55 | star->y = rand.y / distance; 56 | star->z = rand.z / distance; 57 | 58 | if (size_rand <= 7) 59 | star->size = 1; 60 | 61 | else if (size_rand <= 10) 62 | star->size = 2; 63 | 64 | else 65 | star->size = 3; 66 | 67 | star++; 68 | } 69 | } 70 | 71 | std::normal_distribution temp_interval(7300.0f, 1500.0f); 72 | 73 | for (auto& star : stars) { 74 | float temp = temp_interval(rand_gen); 75 | 76 | auto color = temp_to_color(temp); 77 | 78 | star.r = color.x; 79 | star.g = color.y; 80 | star.b = color.z; 81 | } 82 | 83 | compile(); 84 | } 85 | 86 | StarSky::~StarSky() { 87 | glDeleteLists(draw_list, 1); 88 | } 89 | 90 | void 91 | StarSky::render() { 92 | glPushMatrix(); 93 | 94 | float todeg = static_cast(180.0 / M_PI); 95 | 96 | m_rotation.set_roll(time * static_cast((2.0 * M_PI) / 24.0 / 60.0 / 60.0)); 97 | 98 | glRotatef(m_rotation.pitch() * todeg, 1.0f, 0.0f, 0.0f); 99 | glRotatef(m_rotation.yaw() * todeg, 0.0f, 1.0f, 0.0f); 100 | glRotatef(m_rotation.roll() * todeg, 0.0f, 0.0f, 1.0f); 101 | 102 | glScalef(distance, distance, distance); 103 | 104 | glCallList(draw_list); 105 | 106 | glPopMatrix(); 107 | } 108 | 109 | void 110 | StarSky::tick(void*, float delta_time) { 111 | time += delta_time * time_speed; 112 | } 113 | 114 | void 115 | StarSky::set_time(float time) { 116 | StarSky::time = time; 117 | } 118 | 119 | void 120 | StarSky::compile() { 121 | draw_list = glGenLists(1); 122 | glNewList(draw_list, GL_COMPILE); 123 | 124 | for (auto star = stars.begin(); star < stars.end(); star++) { 125 | if (star->size == 1) 126 | glColor3f(star->r * 0.33f, star->g * 0.33f, star->b * 0.33f); 127 | 128 | else if (star->size == 2) 129 | glColor3f(star->r * 0.5f, star->g * 0.5f, star->b * 0.5f); 130 | 131 | else if (star->size == 3) 132 | glColor3f(star->r * 0.75f, star->g * 0.75f, star->b * 0.75f); 133 | 134 | glPointSize(star->size); 135 | glBegin(GL_POINTS); 136 | glVertex3f(star->x, star->y, star->z); 137 | glEnd(); 138 | } 139 | 140 | glEndList(); 141 | } 142 | 143 | Pointf 144 | StarSky::temp_to_color(float temp) const { 145 | // https://tannerhelland.com/2012/09/18/convert-temperature-rgb-algorithm-code.html 146 | 147 | if (temp < 1000) 148 | temp = 1000; 149 | 150 | if (temp > 40000) 151 | temp = 40000; 152 | 153 | float r = 0.0f; 154 | float g = 0.0f; 155 | float b = 0.0f; 156 | 157 | temp /= 100.0f; 158 | 159 | if (temp <= 66.0f) { 160 | r = 1.0f; 161 | } else { 162 | r = 1.287885654f * std::pow(temp - 60.0f, -0.1332047592f); 163 | 164 | if (r > 1.0f) 165 | r = 1.0f; 166 | 167 | if (r < 0.0f) 168 | r = 0.0f; 169 | } 170 | 171 | if (temp <= 66.0f) { 172 | g = 0.388557823f * std::log(temp) - 0.629373313f; 173 | } else { 174 | g = 1.125477225f * std::pow(temp - 60.0f, -0.0755148492f); 175 | } 176 | 177 | if (g > 1.0f) 178 | g = 1.0f; 179 | 180 | if (g < 0.0f) 181 | g = 0.0f; 182 | 183 | if (temp >= 66.0f) { 184 | b = 1.0f; 185 | } else if (temp <= 19.0f) { 186 | b = 0.0f; 187 | } else { 188 | b = 0.541084888f * std::log(temp - 10.0f) - 1.191581222f; 189 | 190 | if (b > 1.0f) 191 | b = 1.0f; 192 | 193 | if (b < 0.0f) 194 | b = 0.0f; 195 | } 196 | 197 | return Pointf(r, g, b); 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /src/StarSky.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2022, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | #include "IRenderable.hpp" 23 | #include "ITickable.hpp" 24 | #include "Rotation.hpp" 25 | #include "Point.hpp" 26 | 27 | namespace mazemaze { 28 | 29 | class StarSky : public IRenderable, public ITickable { 30 | public: 31 | explicit StarSky(int star_count, float time_speed, Rotation rotation); 32 | ~StarSky() override; 33 | 34 | void generate(); 35 | 36 | void render() override; 37 | void tick(void*, float delta_time) override; 38 | void set_time(float time); 39 | 40 | private: 41 | struct Star { 42 | float x; 43 | float y; 44 | float z; 45 | float r; 46 | float g; 47 | float b; 48 | int size; 49 | }; 50 | 51 | int star_count; 52 | 53 | float distance; 54 | 55 | Rotation m_rotation; 56 | 57 | float time; 58 | float time_speed; 59 | 60 | unsigned int draw_list; 61 | 62 | std::vector stars; 63 | 64 | void compile(); 65 | Pointf temp_to_color(float temp) const; 66 | }; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/TickableHandler.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include "ITickable.hpp" 24 | 25 | namespace mazemaze { 26 | 27 | template 28 | class TickableHandler : public ITickable{ 29 | public: 30 | TickableHandler(); 31 | 32 | void addTickable(ITickable* tickable); 33 | void removeTickable(ITickable* tickable); 34 | 35 | void tick(T t, float deltaTime) override; 36 | 37 | private: 38 | std::vector*> tickables; 39 | }; 40 | 41 | template 42 | TickableHandler::TickableHandler() : tickables(0) { 43 | } 44 | 45 | template 46 | void 47 | TickableHandler::addTickable(ITickable* tickable) { 48 | tickables.emplace_back(tickable); 49 | } 50 | 51 | template 52 | void 53 | TickableHandler::removeTickable(ITickable* tickable) { 54 | tickables.erase(std::remove(tickables.begin(), tickables.end(), tickable), tickables.end()); 55 | } 56 | 57 | template 58 | void 59 | TickableHandler::tick(T t, float deltaTime) { 60 | for (auto* tickable: tickables) { 61 | tickable->tick(t, deltaTime); 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | #include "GraphicEngine.hpp" 24 | #include "Settings.hpp" 25 | #include "Logger.hpp" 26 | #include "utils.hpp" 27 | 28 | #include "Gui/MainMenu.hpp" 29 | 30 | using namespace mazemaze; 31 | 32 | int 33 | main() { 34 | { 35 | using namespace std::chrono; 36 | 37 | auto init_time = Logger::inst().init_time().time_since_epoch(); 38 | 39 | auto time_string = fmt( 40 | "%d.%03d", 41 | duration_cast(init_time).count(), 42 | duration_cast(init_time).count() % 1000 43 | ); 44 | 45 | Logger::inst().log_status(fmt("Starting at %s", time_string.c_str())); 46 | } 47 | 48 | bindtextdomain("mazemaze", "locale"); 49 | textdomain("mazemaze"); 50 | bind_textdomain_codeset("mazemaze", "UTF-8"); 51 | 52 | Settings settings; 53 | sfg::SFGUI sfgui; 54 | GraphicEngine& engine = GraphicEngine::inst(); 55 | 56 | engine.open_window(); 57 | 58 | gui::MainMenu main_menu(settings); 59 | 60 | settings.set_main_menu(&main_menu); 61 | 62 | engine.loop(sfgui, main_menu); 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /src/path_separator.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #if defined _WIN32 || defined __CYGWIN__ 21 | # define PATH_SEPARATOR "\\" 22 | #else 23 | # define PATH_SEPARATOR "/" 24 | #endif 25 | -------------------------------------------------------------------------------- /src/utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #include "utils.hpp" 19 | 20 | #include 21 | #include 22 | 23 | namespace mazemaze { 24 | 25 | static std::string 26 | _fmt(const char *fmt, va_list args) { 27 | std::vector v(64); 28 | 29 | while (true) { 30 | va_list args2; 31 | va_copy(args2, args); 32 | int res = vsnprintf(v.data(), v.size(), fmt, args2); 33 | 34 | if ((res >= 0) && (res < static_cast(v.size()))) { 35 | va_end(args); 36 | va_end(args2); 37 | return std::string(v.data()); 38 | } 39 | 40 | size_t size; 41 | 42 | if (res < 0) 43 | size = v.size() * 2; 44 | else 45 | size = static_cast(res) + 1; 46 | 47 | v.clear(); 48 | v.resize(size); 49 | va_end(args2); 50 | } 51 | } 52 | 53 | std::string 54 | fmt(const char *fmt, ...) { 55 | va_list args; 56 | va_start(args, fmt); 57 | 58 | std::string tmp = _fmt(fmt, args); 59 | 60 | va_end(args); 61 | 62 | return tmp; 63 | } 64 | 65 | void 66 | side_to_coords(int side, int& x, int& y) { 67 | static const int sidesX[4] {-1, 1, 0, 0}; 68 | static const int sidesY[4] {0, 0, -1, 1}; 69 | 70 | x = sidesX[side]; 71 | y = sidesY[side]; 72 | } 73 | 74 | int opposite_side(int side) { 75 | static const int oppSide[4] {1, 0, 3, 2}; 76 | 77 | return oppSide[side]; 78 | } 79 | 80 | sf::String 81 | pgtx(const char* text, const char* id) { 82 | std::string tmp = pgettext_expr(text, id); 83 | 84 | return sf::String::fromUtf8(tmp.begin(), tmp.end()); 85 | } 86 | 87 | sf::String 88 | pgtxf(const char* text, const char* id, ...) { 89 | std::string tmp = pgettext_expr(text, id); 90 | 91 | va_list args; 92 | va_start(args, id); 93 | 94 | tmp = _fmt(tmp.c_str(), args); 95 | 96 | va_end(args); 97 | 98 | return sf::String::fromUtf8(tmp.begin(), tmp.end()); 99 | } 100 | 101 | sf::String 102 | npgtxf(const char* text, const char* id, const char* plural, int n) { 103 | std::string tmp = fmt(npgettext_expr(text, id, plural, n), n); 104 | 105 | return sf::String::fromUtf8(tmp.begin(), tmp.end()); 106 | } 107 | 108 | float 109 | powfi(float value, int power) { 110 | float result = 1.0f; 111 | 112 | for (int i = 0; i < power; i++) 113 | result *= value; 114 | 115 | return result; 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/utils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2021, Мира Странная 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 2 7 | * of the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | namespace mazemaze { 27 | 28 | std::string fmt(const char *fmt, ...); 29 | void side_to_coords(int side, int& x, int& y); 30 | int opposite_side(int side); 31 | float powfi(float value, int power); 32 | 33 | sf::String pgtx (const char* text, const char* id); 34 | sf::String pgtxf (const char* text, const char* id, ...); 35 | sf::String npgtxf(const char* text, const char* id, const char* plural, int n); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /win/resource.rc: -------------------------------------------------------------------------------- 1 | 0 ICON icon.ico 2 | 3 | --------------------------------------------------------------------------------