├── .github └── workflows │ └── ci.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── bin ├── explosion.json └── explosion.png ├── cmake ├── FindBox2D.cmake └── FindThor.cmake └── src ├── Core ├── Application.cpp ├── Application.hpp └── Resources.hpp ├── Entity ├── Base │ ├── Animation.cpp │ ├── Animation.hpp │ └── Entity.hpp ├── Button.cpp ├── Button.hpp ├── Explosion.cpp └── Explosion.hpp ├── External └── json.hpp ├── State ├── Base │ ├── State.cpp │ └── State.hpp ├── MenuState.cpp ├── MenuState.hpp ├── PlayState.cpp └── PlayState.hpp └── main.cpp /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | name: ${{ matrix.platform.name }} ${{ matrix.config.name }} 8 | runs-on: ${{ matrix.platform.os }} 9 | 10 | strategy: 11 | fail-fast: false 12 | matrix: 13 | platform: 14 | - { name: Windows VS2019, os: windows-2019 } 15 | - { name: Windows VS2022, os: windows-2022 } 16 | - { name: Linux GCC, os: ubuntu-latest } 17 | - { name: Linux Clang, os: ubuntu-latest, flags: -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ } 18 | - { name: MacOS XCode, os: macos-latest } 19 | config: 20 | - { name: Shared, flags: -DBUILD_SHARED_LIBS=TRUE -DTHOR_SHARED_LIBS=TRUE } 21 | - { name: Static, flags: -DBUILD_SHARED_LIBS=FALSE -DTHOR_SHARED_LIBS=FALSE } 22 | 23 | steps: 24 | - name: Install Linux Dependencies 25 | if: runner.os == 'Linux' 26 | run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libudev-dev libopenal-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev 27 | 28 | - name: SmallGameFramework - Checkout Code 29 | uses: actions/checkout@v3 30 | 31 | - name: SFML - Checkout Code 32 | uses: actions/checkout@v3 33 | with: 34 | repository: SFML/SFML 35 | path: SFML 36 | ref: 2.6.x 37 | 38 | - name: SFML - Configure CMake 39 | shell: bash 40 | run: cmake -S $GITHUB_WORKSPACE/SFML -B $GITHUB_WORKSPACE/SFML/build -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/SFML/install -DCMAKE_VERBOSE_MAKEFILE=ON ${{matrix.platform.flags}} ${{matrix.config.flags}} 41 | 42 | - name: SFML - Build 43 | shell: bash 44 | run: cmake --build $GITHUB_WORKSPACE/SFML/build --config Release --target install 45 | 46 | - name: Thor - Checkout Code 47 | uses: actions/checkout@v3 48 | with: 49 | repository: Bromeon/Thor 50 | path: Thor 51 | 52 | - name: Thor - Configure CMake 53 | shell: bash 54 | run: cmake -S $GITHUB_WORKSPACE/Thor -B $GITHUB_WORKSPACE/Thor/build -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/Thor/install -DCMAKE_VERBOSE_MAKEFILE=ON -DSFML_DIR=$GITHUB_WORKSPACE/SFML/install/lib/cmake/SFML ${{matrix.platform.flags}} ${{matrix.config.flags}} 55 | 56 | - name: Thor - Build 57 | shell: bash 58 | run: cmake --build $GITHUB_WORKSPACE/Thor/build --config Release --target install 59 | 60 | - name: SmallGameFramework - Configure CMake 61 | shell: bash 62 | run: cmake -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install -DCMAKE_VERBOSE_MAKEFILE=ON -DSFML_DIR=$GITHUB_WORKSPACE/SFML/install/lib/cmake/SFML -DTHOR_ROOT=$GITHUB_WORKSPACE/Thor/install ${{matrix.platform.flags}} ${{matrix.config.flags}} 63 | 64 | - name: SmallGameFramework - Build 65 | shell: bash 66 | run: cmake --build $GITHUB_WORKSPACE/build --config Release --target install -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # CMake 36 | out/ 37 | CMakeSettings.json 38 | 39 | # Visual Studio 2015/2017 cache/options directory 40 | .vs/ 41 | # Uncomment if you have tasks that create the project's static files in wwwroot 42 | #wwwroot/ 43 | 44 | # Visual Studio 2017 auto generated files 45 | Generated\ Files/ 46 | 47 | # MSTest test Results 48 | [Tt]est[Rr]esult*/ 49 | [Bb]uild[Ll]og.* 50 | 51 | # NUnit 52 | *.VisualState.xml 53 | TestResult.xml 54 | nunit-*.xml 55 | 56 | # Build Results of an ATL Project 57 | [Dd]ebugPS/ 58 | [Rr]eleasePS/ 59 | dlldata.c 60 | 61 | # Benchmark Results 62 | BenchmarkDotNet.Artifacts/ 63 | 64 | # .NET Core 65 | project.lock.json 66 | project.fragment.lock.json 67 | artifacts/ 68 | 69 | # ASP.NET Scaffolding 70 | ScaffoldingReadMe.txt 71 | 72 | # StyleCop 73 | StyleCopReport.xml 74 | 75 | # Files built by Visual Studio 76 | *_i.c 77 | *_p.c 78 | *_h.h 79 | *.ilk 80 | *.meta 81 | *.obj 82 | *.iobj 83 | *.pch 84 | *.pdb 85 | *.ipdb 86 | *.pgc 87 | *.pgd 88 | *.rsp 89 | *.sbr 90 | *.tlb 91 | *.tli 92 | *.tlh 93 | *.tmp 94 | *.tmp_proj 95 | *_wpftmp.csproj 96 | *.log 97 | *.vspscc 98 | *.vssscc 99 | .builds 100 | *.pidb 101 | *.svclog 102 | *.scc 103 | 104 | # Chutzpah Test files 105 | _Chutzpah* 106 | 107 | # Visual C++ cache files 108 | ipch/ 109 | *.aps 110 | *.ncb 111 | *.opendb 112 | *.opensdf 113 | *.sdf 114 | *.cachefile 115 | *.VC.db 116 | *.VC.VC.opendb 117 | 118 | # Visual Studio profiler 119 | *.psess 120 | *.vsp 121 | *.vspx 122 | *.sap 123 | 124 | # Visual Studio Trace Files 125 | *.e2e 126 | 127 | # TFS 2012 Local Workspace 128 | $tf/ 129 | 130 | # Guidance Automation Toolkit 131 | *.gpState 132 | 133 | # ReSharper is a .NET coding add-in 134 | _ReSharper*/ 135 | *.[Rr]e[Ss]harper 136 | *.DotSettings.user 137 | 138 | # TeamCity is a build add-in 139 | _TeamCity* 140 | 141 | # DotCover is a Code Coverage Tool 142 | *.dotCover 143 | 144 | # AxoCover is a Code Coverage Tool 145 | .axoCover/* 146 | !.axoCover/settings.json 147 | 148 | # Coverlet is a free, cross platform Code Coverage Tool 149 | coverage*.json 150 | coverage*.xml 151 | coverage*.info 152 | 153 | # Visual Studio code coverage results 154 | *.coverage 155 | *.coveragexml 156 | 157 | # NCrunch 158 | _NCrunch_* 159 | .*crunch*.local.xml 160 | nCrunchTemp_* 161 | 162 | # MightyMoose 163 | *.mm.* 164 | AutoTest.Net/ 165 | 166 | # Web workbench (sass) 167 | .sass-cache/ 168 | 169 | # Installshield output folder 170 | [Ee]xpress/ 171 | 172 | # DocProject is a documentation generator add-in 173 | DocProject/buildhelp/ 174 | DocProject/Help/*.HxT 175 | DocProject/Help/*.HxC 176 | DocProject/Help/*.hhc 177 | DocProject/Help/*.hhk 178 | DocProject/Help/*.hhp 179 | DocProject/Help/Html2 180 | DocProject/Help/html 181 | 182 | # Click-Once directory 183 | publish/ 184 | 185 | # Publish Web Output 186 | *.[Pp]ublish.xml 187 | *.azurePubxml 188 | # Note: Comment the next line if you want to checkin your web deploy settings, 189 | # but database connection strings (with potential passwords) will be unencrypted 190 | *.pubxml 191 | *.publishproj 192 | 193 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 194 | # checkin your Azure Web App publish settings, but sensitive information contained 195 | # in these scripts will be unencrypted 196 | PublishScripts/ 197 | 198 | # NuGet Packages 199 | *.nupkg 200 | # NuGet Symbol Packages 201 | *.snupkg 202 | # The packages folder can be ignored because of Package Restore 203 | **/[Pp]ackages/* 204 | # except build/, which is used as an MSBuild target. 205 | !**/[Pp]ackages/build/ 206 | # Uncomment if necessary however generally it will be regenerated when needed 207 | #!**/[Pp]ackages/repositories.config 208 | # NuGet v3's project.json files produces more ignorable files 209 | *.nuget.props 210 | *.nuget.targets 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio LightSwitch build output 301 | **/*.HTMLClient/GeneratedArtifacts 302 | **/*.DesktopClient/GeneratedArtifacts 303 | **/*.DesktopClient/ModelManifest.xml 304 | **/*.Server/GeneratedArtifacts 305 | **/*.Server/ModelManifest.xml 306 | _Pvt_Extensions 307 | 308 | # Paket dependency manager 309 | .paket/paket.exe 310 | paket-files/ 311 | 312 | # FAKE - F# Make 313 | .fake/ 314 | 315 | # CodeRush personal settings 316 | .cr/personal 317 | 318 | # Python Tools for Visual Studio (PTVS) 319 | __pycache__/ 320 | *.pyc 321 | 322 | # Cake - Uncomment if you are using it 323 | # tools/** 324 | # !tools/packages.config 325 | 326 | # Tabs Studio 327 | *.tss 328 | 329 | # Telerik's JustMock configuration file 330 | *.jmconfig 331 | 332 | # BizTalk build output 333 | *.btp.cs 334 | *.btm.cs 335 | *.odx.cs 336 | *.xsd.cs 337 | 338 | # OpenCover UI analysis results 339 | OpenCover/ 340 | 341 | # Azure Stream Analytics local run output 342 | ASALocalRun/ 343 | 344 | # MSBuild Binary and Structured Log 345 | *.binlog 346 | 347 | # NVidia Nsight GPU debugger configuration file 348 | *.nvuser 349 | 350 | # MFractors (Xamarin productivity tool) working folder 351 | .mfractor/ 352 | 353 | # Local History for Visual Studio 354 | .localhistory/ 355 | 356 | # BeatPulse healthcheck temp database 357 | healthchecksdb 358 | 359 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 360 | MigrationBackup/ 361 | 362 | # Ionide (cross platform F# VS Code tools) working folder 363 | .ionide/ 364 | 365 | # Fody - auto-generated XML schema 366 | FodyWeavers.xsd -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | 3 | project(SmallGameFramework LANGUAGES CXX) 4 | 5 | # SmallGameFramework uses C++17 features 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 9 | 10 | # CMake options 11 | option(SMALLGAMEFRAMEWORK_STATIC_STD_LIBS "Use statically linked standard/runtime libraries? This option must match the one used for SFML." OFF) 12 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 13 | 14 | if(NOT BUILD_SHARED_LIBS) 15 | set(SFML_STATIC_LIBRARIES TRUE) 16 | endif() 17 | 18 | # Find SFML 19 | find_package(SFML 2.5 COMPONENTS audio graphics REQUIRED) 20 | 21 | if(NOT SFML_FOUND) 22 | message(FATAL_ERROR "SFML couldn't be located!") 23 | endif() 24 | 25 | # Find Thor 26 | find_package(Thor REQUIRED) 27 | 28 | if(NOT THOR_FOUND) 29 | message(FATAL_ERROR "Thor couldn't be located!") 30 | endif() 31 | 32 | include_directories(${THOR_INCLUDE_DIR}) 33 | 34 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) 35 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/External) 36 | 37 | # Compile target 38 | set(SOURCE_FILES 39 | "src/main.cpp" 40 | "src/Core/Application.hpp" 41 | "src/Core/Application.cpp" 42 | "src/State/Base/State.hpp" 43 | "src/State/Base/State.cpp" 44 | "src/State/PlayState.hpp" 45 | "src/State/PlayState.cpp" 46 | "src/State/MenuState.hpp" 47 | "src/State/MenuState.cpp" 48 | "src/Entity/Base/Animation.hpp" 49 | "src/Entity/Base/Animation.cpp" 50 | "src/Entity/Base/Entity.hpp" 51 | "src/Entity/Explosion.hpp" 52 | "src/Entity/Explosion.cpp" 53 | "src/Entity/Button.hpp" 54 | "src/Entity/Button.cpp" 55 | "src/Core/Resources.hpp") 56 | add_executable(SmallGameFramework ${SOURCE_FILES}) 57 | 58 | # Static Runtime 59 | if(SMALLGAMEFRAMEWORK_STATIC_STD_LIBS) 60 | if(NOT SFML_STATIC_LIBRARIES) 61 | message("\n-> If you check SMALLGAMEFRAMEWORK_STATIC_STD_LIBS, you also need to check SFML_STATIC_LIBRARIES.") 62 | message("-> It would lead to multiple runtime environments which results in undefined behavior.\n") 63 | elseif(WIN32 AND MSVC) 64 | set_property(TARGET SmallGameFramework PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") 65 | elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 66 | target_link_options(SmallGameFramework PRIVATE -static) 67 | endif() 68 | endif() 69 | 70 | # Link libraries 71 | target_link_libraries(SmallGameFramework ${THOR_LIBRARY} sfml-audio sfml-graphics) 72 | 73 | # Install executable 74 | install(TARGETS SmallGameFramework 75 | RUNTIME DESTINATION .) 76 | 77 | # Install game data 78 | install(DIRECTORY bin/ 79 | DESTINATION .) -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eXpl0it3r/SmallGameFramework/b7bb6f0a392948999867e2958ca5b4df59bae389/LICENSE.md -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SmallGameFramework 2 | 3 | The SmallGameFramework provides the basic tools to quickly kick-off an SFML game project. 4 | 5 | This project is not a library where you code against an API, instead it provides a set of classes that you can and 6 | should directly use for your project. The name is a reference to my 7 | [SmallGameEngine](https://github.com/eXpl0it3r/SmallGameEngine), which in itself is more a proof of concept and is 8 | often too complex for simple games. The SmallGameFramework could be especially useful for the 9 | [SFML Game Jam](https://sfmlgamejam.com/), [Ludum Dare](https://ldjam.com/) or any other game jam where you 10 | intend to use SFML. 11 | 12 | ## Features 13 | 14 | * Simple state machine 15 | * Basic entity class 16 | * Animated entity class 17 | * Animation loader 18 | 19 | ## License 20 | 21 | This software is available under 2 licenses -- choose whichever you prefer. 22 | For further details take a look at the [LICENSE.md](https://github.com/eXpl0it3r/SmallGameFramework/blob/master/LICENSE.md) file. 23 | 24 | - Public Domain 25 | - MIT 26 | -------------------------------------------------------------------------------- /bin/explosion.json: -------------------------------------------------------------------------------- 1 | { 2 | "explosion": { 3 | "duration": 0.7, 4 | "frames": { 5 | "0": [1, 0, 0, 256, 256], 6 | "1": [1, 256, 0, 256, 256], 7 | "2": [1, 512, 0, 256, 256], 8 | "3": [1, 768, 0, 256, 256], 9 | "4": [1, 1024, 0, 256, 256], 10 | "5": [1, 1280, 0, 256, 256], 11 | "6": [1, 1536, 0, 256, 256], 12 | "7": [1, 1792, 0, 256, 256], 13 | "8": [1, 0, 256, 256, 256], 14 | "9": [1, 256, 256, 256, 256], 15 | "10": [1, 512, 256, 256, 256], 16 | "11": [1, 768, 256, 256, 256], 17 | "12": [1, 1024, 256, 256, 256], 18 | "13": [1, 1280, 256, 256, 256], 19 | "14": [1, 1536, 256, 256, 256], 20 | "15": [1, 1792, 256, 256, 256], 21 | "16": [1, 0, 512, 256, 256], 22 | "17": [1, 256, 512, 256, 256], 23 | "18": [1, 512, 512, 256, 256], 24 | "19": [1, 768, 512, 256, 256], 25 | "20": [1, 1024, 512, 256, 256], 26 | "21": [1, 1280, 512, 256, 256], 27 | "22": [1, 1536, 512, 256, 256], 28 | "23": [1, 1792, 512, 256, 256], 29 | "24": [1, 0, 768, 256, 256], 30 | "25": [1, 256, 768, 256, 256], 31 | "26": [1, 512, 768, 256, 256], 32 | "27": [1, 768, 768, 256, 256], 33 | "28": [1, 1024, 768, 256, 256], 34 | "29": [1, 1280, 768, 256, 256], 35 | "30": [1, 1536, 768, 256, 256], 36 | "31": [1, 1792, 768, 256, 256], 37 | "32": [1, 0, 1024, 256, 256], 38 | "33": [1, 256, 1024, 256, 256], 39 | "34": [1, 512, 1024, 256, 256], 40 | "35": [1, 768, 1024, 256, 256], 41 | "36": [1, 1024, 1024, 256, 256], 42 | "37": [1, 1280, 1024, 256, 256], 43 | "38": [1, 1536, 1024, 256, 256], 44 | "39": [1, 1792, 1024, 256, 256], 45 | "40": [1, 0, 1280, 256, 256], 46 | "41": [1, 256, 1280, 256, 256], 47 | "42": [1, 512, 1280, 256, 256], 48 | "43": [1, 768, 1280, 256, 256], 49 | "44": [1, 1024, 1280, 256, 256], 50 | "45": [1, 1280, 1280, 256, 256], 51 | "46": [1, 1536, 1280, 256, 256], 52 | "47": [1, 1792, 1280, 256, 256], 53 | "48": [1, 0, 1536, 256, 256], 54 | "49": [1, 256, 1536, 256, 256], 55 | "50": [1, 512, 1536, 256, 256], 56 | "51": [1, 768, 1536, 256, 256], 57 | "52": [1, 1024, 1536, 256, 256], 58 | "53": [1, 1280, 1536, 256, 256], 59 | "54": [1, 1536, 1536, 256, 256], 60 | "55": [1, 1792, 1536, 256, 256], 61 | "56": [1, 0, 1792, 256, 256], 62 | "57": [1, 256, 1792, 256, 256], 63 | "58": [1, 512, 1792, 256, 256], 64 | "59": [1, 768, 1792, 256, 256], 65 | "60": [1, 1024, 1792, 256, 256], 66 | "61": [1, 1280, 1792, 256, 256], 67 | "62": [1, 1536, 1792, 256, 256], 68 | "63": [1, 1792, 1792, 256, 256] 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /bin/explosion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eXpl0it3r/SmallGameFramework/b7bb6f0a392948999867e2958ca5b4df59bae389/bin/explosion.png -------------------------------------------------------------------------------- /cmake/FindBox2D.cmake: -------------------------------------------------------------------------------- 1 | # This script locates eXpl0it3r's port of the Box2D library. 2 | # 3 | # USAGE 4 | # 5 | # By default, the dynamic version of Box2D will be found. To find the static 6 | # one instead, you must set the BOX2D_STATIC_LIBRARIES variable to TRUE before 7 | # calling find_package(BOX2D). In that case BOX2D_STATIC will also be defined 8 | # by this script. Example: 9 | # 10 | # set(BOX2D_STATIC_LIBRARIES TRUE) 11 | # find_package(BOX2D) 12 | # 13 | # If Box2D is not installed in a standard path, you can use the BOX2DDIR or 14 | # BOX2D_ROOT CMake (or environment) variables to tell CMake where to look for 15 | # Box2D. 16 | # 17 | # 18 | # OUTPUT 19 | # 20 | # This script defines the following variables: 21 | # - BOX2D_LIBRARY_DEBUG: the path to the debug library 22 | # - BOX2D_LIBRARY_RELEASE: the path to the release library 23 | # - BOX2D_LIBRARY: the path to the library to link to 24 | # - BOX2D_FOUND: true if the Box2D library is found 25 | # - BOX2D_INCLUDE_DIR: the path where Box2D headers are located (the directory containing the Box2D/Box2D.hpp file) 26 | # 27 | # 28 | # EXAMPLE 29 | # 30 | # find_package(Box2D REQUIRED) 31 | # include_directories(${BOX2D_INCLUDE_DIR}) 32 | # add_executable(myapp ...) 33 | # target_link_libraries(myapp ${BOX2D_LIBRARY} ...) 34 | 35 | set(BOX2D_FOUND FALSE) 36 | 37 | if(BOX2D_STATIC_LIBRARIES) 38 | set(BOX2D_SUFFIX "-s") 39 | add_definitions(-DBOX2D_STATIC) 40 | else() 41 | set(BOX2D_SUFFIX "") 42 | endif() 43 | 44 | find_path( 45 | BOX2D_INCLUDE_DIR 46 | Box2D/Box2D.hpp 47 | PATH_SUFFIXES 48 | include 49 | PATHS 50 | /usr 51 | /usr/local 52 | ${BOX2DDIR} 53 | ${BOX2D_ROOT} 54 | $ENV{BOX2DDIR} 55 | $ENV{BOX2D_ROOT} 56 | ) 57 | 58 | find_library( 59 | BOX2D_LIBRARY_RELEASE 60 | box2d${BOX2D_SUFFIX} 61 | PATH_SUFFIXES 62 | lib 63 | lib64 64 | PATHS 65 | /usr 66 | /usr/local 67 | ${BOX2DDIR} 68 | ${BOX2D_ROOT} 69 | $ENV{BOX2DDIR} 70 | $ENV{BOX2D_ROOT} 71 | ) 72 | 73 | find_library( 74 | BOX2D_LIBRARY_DEBUG 75 | box2d${BOX2D_SUFFIX}-d 76 | PATH_SUFFIXES 77 | lib 78 | lib64 79 | PATHS 80 | /usr 81 | /usr/local 82 | ${BOX2DDIR} 83 | ${BOX2D_ROOT} 84 | $ENV{BOX2DDIR} 85 | $ENV{BOX2D_ROOT} 86 | ) 87 | 88 | if(BOX2D_LIBRARY_RELEASE AND BOX2D_LIBRARY_DEBUG) 89 | set(BOX2D_LIBRARY debug ${BOX2D_LIBRARY_DEBUG} optimized ${BOX2D_LIBRARY_RELEASE}) 90 | endif() 91 | 92 | if(BOX2D_LIBRARY_RELEASE AND NOT BOX2D_LIBRARY_DEBUG) 93 | set(BOX2D_LIBRARY_DEBUG ${BOX2D_LIBRARY_RELEASE}) 94 | set(BOX2D_LIBRARY ${BOX2D_LIBRARY_RELEASE}) 95 | endif() 96 | 97 | if(BOX2D_LIBRARY_DEBUG AND NOT BOX2D_LIBRARY_RELEASE) 98 | set(BOX2D_LIBRARY_RELEASE ${BOX2D_LIBRARY_DEBUG}) 99 | set(BOX2D_LIBRARY ${BOX2D_LIBRARY_DEBUG}) 100 | endif() 101 | 102 | if(NOT BOX2D_INCLUDE_DIR OR NOT BOX2D_LIBRARY) 103 | if(BOX2D_FIND_REQUIRED) 104 | message(FATAL_ERROR "Box2D not found.") 105 | elseif(NOT BOX2D_FIND_QUIETLY) 106 | message("Box2D not found.") 107 | endif() 108 | else() 109 | set(BOX2D_FOUND true) 110 | if (NOT BOX2D_FIND_QUIETLY) 111 | message(STATUS "Box2D found: ${BOX2D_INCLUDE_DIR}") 112 | endif() 113 | endif() 114 | -------------------------------------------------------------------------------- /cmake/FindThor.cmake: -------------------------------------------------------------------------------- 1 | ################################################################################# 2 | ## 3 | ## Thor C++ Library 4 | ## Copyright (c) 2011-2014 Jan Haller 5 | ## 6 | ## This software is provided 'as-is', without any express or implied 7 | ## warranty. In no event will the authors be held liable for any damages 8 | ## arising from the use of this software. 9 | ## 10 | ## Permission is granted to anyone to use this software for any purpose, 11 | ## including commercial applications, and to alter it and redistribute it 12 | ## freely, subject to the following restrictions: 13 | ## 14 | ## 1. The origin of this software must not be misrepresented; you must not 15 | ## claim that you wrote the original software. If you use this software 16 | ## in a product, an acknowledgment in the product documentation would be 17 | ## appreciated but is not required. 18 | ## 19 | ## 2. Altered source versions must be plainly marked as such, and must not be 20 | ## misrepresented as being the original software. 21 | ## 22 | ## 3. This notice may not be removed or altered from any source distribution. 23 | ## 24 | ################################################################################# 25 | 26 | # This script locates the Thor C++ Library 27 | # Based on the FindSFML.cmake module 28 | # ======================================== 29 | # 30 | # Usage 31 | # ----- 32 | # 33 | # Thor's libraries use the same configuration (static/dynamic linking) as SFML's. 34 | # If the variable SFML_STATIC_LIBRARIES is set to TRUE before calling find_package(Thor), 35 | # the static libraries of Thor are found. Otherwise, the dynamic ones are found. 36 | # 37 | # If Thor is not installed in a standard path, you can use the THOR_ROOT CMake (or environment) variable 38 | # to tell CMake where Thor is. 39 | # 40 | # Output 41 | # ------ 42 | # 43 | # This script defines the following variables: 44 | # - THOR_LIBRARY_DEBUG: Name of the debug library (set to THOR_LIBRARY_RELEASE if no debug version is found) 45 | # - THOR_LIBRARY_RELEASE: Name of the release library (set to THOR_LIBRARY_DEBUG if no release version is found) 46 | # - THOR_LIBRARY: Name of the library to link to (includes both debug and release names if necessary) 47 | # - THOR_INCLUDE_DIR: The path where Thor headers are located (the directory containing the Thor/Config.hpp file) 48 | # - THOR_FOUND: Is TRUE if at least one of the debug or release library is found 49 | # 50 | # Usage example: 51 | # 52 | # find_package(Thor 2 REQUIRED) 53 | # include_directories(${THOR_INCLUDE_DIR}) 54 | # target_link_libraries(MyProject ${THOR_LIBRARY}) 55 | 56 | 57 | # Deduce the libraries suffix from the options 58 | set(FINDTHOR_LIB_SUFFIX "") 59 | if(SFML_STATIC_LIBRARIES) 60 | set(FINDTHOR_LIB_SUFFIX "-s") 61 | endif() 62 | 63 | # Find the SFML include directory 64 | find_path(THOR_INCLUDE_DIR Thor/Config.hpp 65 | PATH_SUFFIXES include 66 | PATHS 67 | ${THOR_ROOT} 68 | $ENV{THOR_ROOT} 69 | /usr/local/ 70 | /usr/ 71 | /sw # Fink 72 | /opt/local/ # DarwinPorts 73 | /opt/csw/ # Blastwave 74 | /opt/) 75 | 76 | # Find the requested modules 77 | set(THOR_FOUND TRUE) # will be set to false if one of the required modules is not found 78 | set(FINDTHOR_LIB_PATHS 79 | ${THOR_ROOT} 80 | $ENV{THOR_ROOT} 81 | /usr/local 82 | /usr 83 | /sw 84 | /opt/local 85 | /opt/csw 86 | /opt) 87 | 88 | # Debug library 89 | find_library(THOR_LIBRARY_DEBUG 90 | NAMES thor${FINDTHOR_LIB_SUFFIX}-d 91 | PATH_SUFFIXES lib64 lib 92 | PATHS ${FINDTHOR_LIB_PATHS}) 93 | 94 | # Release library 95 | find_library(THOR_LIBRARY_RELEASE 96 | NAMES thor${FINDTHOR_LIB_SUFFIX} 97 | PATH_SUFFIXES lib64 lib 98 | PATHS ${FINDTHOR_LIB_PATHS}) 99 | 100 | if(THOR_LIBRARY_DEBUG OR THOR_LIBRARY_RELEASE) 101 | # Library found 102 | set(THOR_FOUND TRUE) 103 | 104 | # If both are found, set THOR_LIBRARY to contain both 105 | if(THOR_LIBRARY_DEBUG AND THOR_LIBRARY_RELEASE) 106 | set(THOR_LIBRARY debug ${THOR_LIBRARY_DEBUG} 107 | optimized ${THOR_LIBRARY_RELEASE}) 108 | endif() 109 | 110 | # If only one debug/release variant is found, set the other to be equal to the found one 111 | if(THOR_LIBRARY_DEBUG AND NOT THOR_LIBRARY_RELEASE) 112 | # debug and not release 113 | set(THOR_LIBRARY_RELEASE ${THOR_LIBRARY_DEBUG}) 114 | set(THOR_LIBRARY ${THOR_LIBRARY_DEBUG}) 115 | endif() 116 | if(THOR_LIBRARY_RELEASE AND NOT THOR_LIBRARY_DEBUG) 117 | # release and not debug 118 | set(THOR_LIBRARY_DEBUG ${THOR_LIBRARY_RELEASE}) 119 | set(THOR_LIBRARY ${THOR_LIBRARY_RELEASE}) 120 | endif() 121 | else() 122 | # Library not found 123 | set(THOR_FOUND FALSE) 124 | set(THOR_LIBRARY "") 125 | set(FINDTHOR_MISSING "${FINDTHOR_MISSING} THOR_LIBRARY") 126 | endif() 127 | 128 | # Mark variables as advanced 129 | mark_as_advanced(THOR_INCLUDE_DIR 130 | THOR_LIBRARY 131 | THOR_LIBRARY_RELEASE 132 | THOR_LIBRARY_DEBUG) 133 | 134 | # Result 135 | if(THOR_FOUND) 136 | # Success 137 | message("Found Thor: ${THOR_INCLUDE_DIR}") 138 | else() 139 | # include directory or library not found 140 | set(FINDTHOR_ERROR "Could NOT find Thor (missing: ${FINDTHOR_MISSING})") 141 | 142 | if(THOR_FIND_REQUIRED) 143 | # Fatal error 144 | message(FATAL_ERROR ${FINDTHOR_ERROR}) 145 | elseif(NOT THOR_FIND_QUIETLY) 146 | # Error, but continue 147 | message("${FINDTHOR_ERROR}") 148 | endif() 149 | endif() 150 | -------------------------------------------------------------------------------- /src/Core/Application.cpp: -------------------------------------------------------------------------------- 1 | #include "Application.hpp" 2 | 3 | #include "State/MenuState.hpp" 4 | 5 | #include 6 | 7 | Application::Application() 8 | : m_window{ { 1024, 768 }, "SmallGameFramework", sf::Style::Titlebar | sf::Style::Close, sf::ContextSettings{ 0, 0, 8 } } 9 | { 10 | m_window.setVerticalSyncEnabled(true); 11 | } 12 | 13 | void Application::run() 14 | { 15 | loadResources(); 16 | 17 | // Simple state machine 18 | std::unique_ptr state = std::make_unique(m_window, m_resources); 19 | 20 | while (state != nullptr) 21 | { 22 | state = state->run(); 23 | } 24 | } 25 | 26 | void Application::loadResources() 27 | { 28 | m_resources.Fonts.acquire(Font::SpaceGrotesk, thor::Resources::fromFile("SpaceGrotesk-Regular.ttf")); 29 | m_resources.Textures.acquire(Texture::Explosion, thor::Resources::fromFile("explosion.png")); 30 | } 31 | -------------------------------------------------------------------------------- /src/Core/Application.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Core/Resources.hpp" 6 | 7 | class Application 8 | { 9 | public: 10 | Application(); 11 | 12 | void run(); 13 | 14 | private: 15 | void loadResources(); 16 | 17 | sf::RenderWindow m_window; 18 | Resources m_resources; 19 | }; 20 | -------------------------------------------------------------------------------- /src/Core/Resources.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Font 7 | { 8 | const auto SpaceGrotesk = std::string{ "SpaceGrotesk" }; 9 | } 10 | 11 | namespace Texture 12 | { 13 | const auto Explosion = std::string{ "Explosion" }; 14 | } 15 | 16 | struct Resources 17 | { 18 | thor::ResourceHolder Textures; 19 | thor::ResourceHolder Fonts; 20 | }; 21 | -------------------------------------------------------------------------------- /src/Entity/Base/Animation.cpp: -------------------------------------------------------------------------------- 1 | #include "Entity/Base/Animation.hpp" 2 | 3 | #include 4 | 5 | #include "json.hpp" 6 | 7 | Animation::Animation(const std::string& filename) 8 | : m_animator{ m_map } 9 | { 10 | parse(filename); 11 | } 12 | 13 | void Animation::parse(const std::string& filename) 14 | { 15 | auto animations = nlohmann::json{}; 16 | 17 | auto file = std::fstream{ filename, std::ios::in | std::ios::binary }; 18 | 19 | if (!file.is_open()) 20 | { 21 | throw std::runtime_error{ "Failed to open animation file \"" + filename + "\"." }; 22 | } 23 | 24 | try 25 | { 26 | file >> animations; 27 | } 28 | catch (std::exception& e) 29 | { 30 | throw std::runtime_error{ "The animation file \"" + filename + "\" contains invalid JSON data. Inner exception: " + e.what() }; 31 | } 32 | 33 | for (auto animation = animations.begin(); animation != animations.end(); ++animation) 34 | { 35 | m_animations.emplace_back(); 36 | 37 | for (auto& frame : animation.value()["frames"]) 38 | { 39 | m_animations.back().addFrame(frame[0], { frame[1], frame[2], frame[3], frame[4] }); 40 | } 41 | 42 | m_map.addAnimation(animation.key(), m_animations.back(), sf::seconds(animation.value()["duration"])); 43 | } 44 | } 45 | 46 | thor::Animator& Animation::animator() 47 | { 48 | return m_animator; 49 | } 50 | -------------------------------------------------------------------------------- /src/Entity/Base/Animation.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | class Animation 10 | { 11 | public: 12 | explicit Animation(const std::string& filename); 13 | 14 | thor::Animator& animator(); 15 | 16 | protected: 17 | thor::Animator m_animator; 18 | 19 | private: 20 | void parse(const std::string& filename); 21 | 22 | thor::AnimationMap m_map; 23 | std::vector m_animations; 24 | }; 25 | -------------------------------------------------------------------------------- /src/Entity/Base/Entity.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Entity : public sf::Drawable, public sf::Transformable 6 | { 7 | public: 8 | virtual void update(sf::Time delta_time) = 0; 9 | 10 | protected: 11 | Entity() = default; 12 | ~Entity() override = default; 13 | 14 | Entity(const Entity&) = default; 15 | Entity& operator=(const Entity&) = default; 16 | 17 | Entity(Entity&&) noexcept = default; 18 | Entity& operator=(Entity&&) noexcept = default; 19 | }; 20 | -------------------------------------------------------------------------------- /src/Entity/Button.cpp: -------------------------------------------------------------------------------- 1 | #include "Entity/Button.hpp" 2 | 3 | #include 4 | 5 | #include "Core/Resources.hpp" 6 | 7 | Button::Button(const std::string& text, const Resources& resources) 8 | : m_text{ text, resources.Fonts[Font::SpaceGrotesk], 80 } 9 | { 10 | m_text.setFillColor(sf::Color{ 0xDDDDDDFF }); 11 | m_text.setOrigin(m_text.getLocalBounds().getSize() / 2.f + m_text.getLocalBounds().getPosition()); 12 | m_text.setOrigin({ std::round(m_text.getOrigin().x), std::round(m_text.getOrigin().y) }); 13 | } 14 | 15 | void Button::update(sf::Time delta_time) 16 | { 17 | } 18 | 19 | sf::FloatRect Button::globalBounds() const 20 | { 21 | return getTransform().transformRect(m_text.getGlobalBounds()); 22 | } 23 | 24 | void Button::mouseOver() 25 | { 26 | m_text.setOutlineColor(sf::Color{ 0xDDDDDDFF }); 27 | m_text.setOutlineThickness(1.f); 28 | m_text.setOutlineColor(sf::Color{ 0xAAAAAAFF }); 29 | } 30 | 31 | void Button::mouseLeave() 32 | { 33 | m_text.setFillColor(sf::Color{ 0xFFFFFFFF }); 34 | m_text.setOutlineThickness(0.f); 35 | } 36 | 37 | void Button::draw(sf::RenderTarget& target, sf::RenderStates states) const 38 | { 39 | states.transform *= getTransform(); 40 | target.draw(m_text, states); 41 | } 42 | -------------------------------------------------------------------------------- /src/Entity/Button.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Entity/Base/Entity.hpp" 4 | #pragma once 5 | 6 | struct Resources; 7 | 8 | class Button final : public Entity 9 | { 10 | public: 11 | Button(const std::string& text, const Resources& resources); 12 | 13 | void update(sf::Time delta_time) override; 14 | sf::FloatRect globalBounds() const; 15 | 16 | void mouseOver(); 17 | void mouseLeave(); 18 | 19 | protected: 20 | void draw(sf::RenderTarget& target, sf::RenderStates states) const override; 21 | 22 | private: 23 | sf::Text m_text; 24 | }; 25 | -------------------------------------------------------------------------------- /src/Entity/Explosion.cpp: -------------------------------------------------------------------------------- 1 | #include "Entity/Explosion.hpp" 2 | 3 | Explosion::Explosion(const sf::Texture& texture) 4 | : Animation{ "explosion.json" } 5 | { 6 | m_animator.play() << "explosion" << thor::Playback::loop("explosion"); 7 | m_sprite.setTexture(texture, true); 8 | } 9 | 10 | void Explosion::update(const sf::Time delta_time) 11 | { 12 | m_animator.update(delta_time); 13 | m_animator.animate(m_sprite); 14 | } 15 | 16 | void Explosion::draw(sf::RenderTarget& target, const sf::RenderStates states) const 17 | { 18 | target.draw(m_sprite, states); 19 | } 20 | -------------------------------------------------------------------------------- /src/Entity/Explosion.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Entity/Base/Entity.hpp" 4 | #include "Entity/Base/Animation.hpp" 5 | 6 | #include 7 | 8 | class Explosion final : public Entity, public Animation 9 | { 10 | public: 11 | explicit Explosion(const sf::Texture& texture); 12 | 13 | void update(sf::Time delta_time) override; 14 | 15 | protected: 16 | void draw(sf::RenderTarget& target, sf::RenderStates states) const override; 17 | 18 | private: 19 | sf::Sprite m_sprite; 20 | }; 21 | -------------------------------------------------------------------------------- /src/State/Base/State.cpp: -------------------------------------------------------------------------------- 1 | #include "State/Base/State.hpp" 2 | #include "Core/Resources.hpp" 3 | 4 | State::State(sf::RenderWindow& window, Resources& resources) 5 | : m_window{ window } 6 | , m_resources{ resources } 7 | { 8 | } 9 | 10 | std::unique_ptr State::run() 11 | { 12 | const auto clock = sf::Clock{}; 13 | auto last_frame_time = sf::Time{}; 14 | 15 | while (m_next == nullptr && m_window.isOpen()) 16 | { 17 | const auto delta_time = clock.getElapsedTime() - last_frame_time; 18 | last_frame_time = clock.getElapsedTime(); 19 | 20 | update(delta_time); 21 | render(); 22 | } 23 | 24 | return std::move(m_next); 25 | } 26 | -------------------------------------------------------------------------------- /src/State/Base/State.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | struct Resources; 8 | 9 | class State 10 | { 11 | public: 12 | explicit State(sf::RenderWindow& window, Resources& resources); 13 | virtual ~State() = default; 14 | 15 | State(const State&) = delete; 16 | State& operator=(const State&) = delete; 17 | 18 | State(State&&) = default; 19 | State& operator=(State&&) = default; 20 | 21 | std::unique_ptr run(); 22 | 23 | protected: 24 | virtual void processEvents() = 0; 25 | virtual void update(sf::Time delta_time) = 0; 26 | virtual void render() = 0; 27 | 28 | sf::RenderWindow& m_window; 29 | Resources& m_resources; 30 | 31 | std::unique_ptr m_next; 32 | }; 33 | -------------------------------------------------------------------------------- /src/State/MenuState.cpp: -------------------------------------------------------------------------------- 1 | #include "State/MenuState.hpp" 2 | 3 | #include 4 | 5 | #include "State/PlayState.hpp" 6 | 7 | struct Resources; 8 | 9 | MenuState::MenuState(sf::RenderWindow& window, Resources& resources) 10 | : State{ window, resources } 11 | , m_mouse_button_released{ false } 12 | , m_start{ "Start", m_resources } 13 | , m_options{ "Options", m_resources } 14 | , m_exit{ "Exit", m_resources } 15 | { 16 | const auto window_size = sf::Vector2f{ window.getSize() }; 17 | 18 | m_start.setPosition(sf::Vector2f{ window_size.x / 2, window_size.y / 2 } - sf::Vector2f{ 0.f, std::round(m_exit.globalBounds().height * 2.5f) }); 19 | m_options.setPosition({ window_size.x / 2, window_size.y / 2 }); 20 | m_exit.setPosition(sf::Vector2f{ window_size.x / 2, window_size.y / 2 } + sf::Vector2f{ 0.f, std::round(m_exit.globalBounds().height * 2.5f) }); 21 | } 22 | 23 | void MenuState::processEvents() 24 | { 25 | for (auto event = sf::Event{}; m_window.pollEvent(event);) 26 | { 27 | if (event.type == sf::Event::Closed) 28 | { 29 | m_window.close(); 30 | } 31 | else if (event.type == sf::Event::MouseMoved) 32 | { 33 | m_current_mouse_position = m_window.mapPixelToCoords({ event.mouseMove.x, event.mouseMove.y }); 34 | } 35 | else if (event.type == sf::Event::MouseButtonReleased) 36 | { 37 | m_current_mouse_position = m_window.mapPixelToCoords({ event.mouseButton.x, event.mouseButton.y }); 38 | m_mouse_button_released = true; 39 | } 40 | else 41 | { 42 | m_mouse_button_released = false; 43 | } 44 | } 45 | } 46 | 47 | void MenuState::handleButtonMouseInteraction(Button& button) const 48 | { 49 | if (button.globalBounds().contains(m_current_mouse_position)) 50 | { 51 | button.mouseOver(); 52 | } 53 | else 54 | { 55 | button.mouseLeave(); 56 | } 57 | } 58 | 59 | void MenuState::update(const sf::Time delta_time) 60 | { 61 | processEvents(); 62 | 63 | handleButtonMouseInteraction(m_start); 64 | handleButtonMouseInteraction(m_options); 65 | handleButtonMouseInteraction(m_exit); 66 | 67 | if (m_start.globalBounds().contains(m_current_mouse_position) && m_mouse_button_released) 68 | { 69 | m_next = std::make_unique(m_window, m_resources); 70 | } 71 | if (m_exit.globalBounds().contains(m_current_mouse_position) && m_mouse_button_released) 72 | { 73 | m_window.close(); 74 | } 75 | } 76 | 77 | void MenuState::render() 78 | { 79 | m_window.clear(); 80 | m_window.draw(m_start); 81 | m_window.draw(m_options); 82 | m_window.draw(m_exit); 83 | m_window.display(); 84 | } 85 | -------------------------------------------------------------------------------- /src/State/MenuState.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Entity/Button.hpp" 4 | #include "State/Base/State.hpp" 5 | 6 | struct Resources; 7 | 8 | class MenuState final : public State 9 | { 10 | public: 11 | explicit MenuState(sf::RenderWindow& window, Resources& resources); 12 | 13 | private: 14 | void processEvents() override; 15 | void update(sf::Time delta_time) override; 16 | void render() override; 17 | 18 | void handleButtonMouseInteraction(Button& button) const; 19 | 20 | sf::Vector2f m_current_mouse_position; 21 | bool m_mouse_button_released; 22 | 23 | Button m_start; 24 | Button m_options; 25 | Button m_exit; 26 | }; 27 | -------------------------------------------------------------------------------- /src/State/PlayState.cpp: -------------------------------------------------------------------------------- 1 | #include "State/PlayState.hpp" 2 | #include "Core/Resources.hpp" 3 | 4 | PlayState::PlayState(sf::RenderWindow& window, Resources& resources) 5 | : State{ window, resources } 6 | , m_explosion{ m_resources.Textures[Texture::Explosion] } 7 | { 8 | } 9 | 10 | void PlayState::processEvents() 11 | { 12 | for (auto event = sf::Event{}; m_window.pollEvent(event);) 13 | { 14 | if (event.type == sf::Event::Closed) 15 | { 16 | m_window.close(); 17 | } 18 | } 19 | } 20 | 21 | void PlayState::update(const sf::Time delta_time) 22 | { 23 | processEvents(); 24 | 25 | m_explosion.update(delta_time); 26 | } 27 | 28 | void PlayState::render() 29 | { 30 | m_window.clear(); 31 | m_window.draw(m_explosion); 32 | m_window.display(); 33 | } 34 | -------------------------------------------------------------------------------- /src/State/PlayState.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "State/Base/State.hpp" 4 | #include "Entity/Explosion.hpp" 5 | 6 | struct Resources; 7 | 8 | class PlayState final : public State 9 | { 10 | public: 11 | explicit PlayState(sf::RenderWindow& window, Resources& resources); 12 | 13 | private: 14 | void processEvents() override; 15 | void update(sf::Time delta_time) override; 16 | void render() override; 17 | 18 | Explosion m_explosion; 19 | }; 20 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Core/Application.hpp" 4 | 5 | int main() 6 | { 7 | try 8 | { 9 | auto app = Application{}; 10 | app.run(); 11 | } 12 | catch (std::exception& e) 13 | { 14 | std::cerr << "SmallGameFramework detected an error: " << e.what() << '\n'; 15 | std::cerr << "Due to this error the SmallGameFramework unfortunately needs to terminate." << std::endl; 16 | } 17 | } 18 | --------------------------------------------------------------------------------