├── .gitattributes ├── .gitignore ├── .vscode ├── .gitkeep ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── Font └── monogram.ttf ├── Makefile ├── README.md ├── Sounds ├── clear.mp3 ├── music.mp3 └── rotate.mp3 ├── lib ├── libgcc_s_dw2-1.dll └── libstdc++-6.dll ├── main.code-workspace ├── preview.jpg └── src ├── block.cpp ├── block.h ├── blocks.cpp ├── colors.cpp ├── colors.h ├── game.cpp ├── game.h ├── grid.cpp ├── grid.h ├── main.cpp ├── position.cpp └── position.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | Makefile linguist-generated=true 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | *.dsym 3 | main -------------------------------------------------------------------------------- /.vscode/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/educ8s/Cpp-Tetris-Game-with-raylib/663d96b2c15fb6fb62a7f35a1664192643ad91da/.vscode/.gitkeep -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "C:/raylib/raylib/src/**", 7 | "${workspaceFolder}/**" 8 | ], 9 | "defines": [ 10 | "_DEBUG", 11 | "UNICODE", 12 | "_UNICODE", 13 | "GRAPHICS_API_OPENGL_33", 14 | "PLATFORM_DESKTOP" 15 | ], 16 | "compilerPath": "C:/raylib/w64devkit/bin/gcc.exe", 17 | "cStandard": "c99", 18 | "cppStandard": "c++14", 19 | "intelliSenseMode": "gcc-x64", 20 | "configurationProvider": "ms-vscode.makefile-tools" 21 | }, 22 | { 23 | "name": "Mac", 24 | "includePath": [ 25 | "${workspaceFolder}/**", 26 | "/opt/homebrew/include" 27 | ], 28 | "defines": [ 29 | "_DEBUG", 30 | "UNICODE", 31 | "_UNICODE", 32 | "GRAPHICS_API_OPENGL_33", 33 | "PLATFORM_DESKTOP" 34 | ], 35 | "macFrameworkPath": [ 36 | "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks" 37 | ], 38 | "compilerPath": "/usr/bin/clang", 39 | "cStandard": "c11", 40 | "cppStandard": "c++14", 41 | "intelliSenseMode": "clang-x64" 42 | }, 43 | { 44 | "name": "Linux", 45 | "includePath": [ 46 | "/home/linuxbrew/.linuxbrew/include", 47 | "${workspaceFolder}/**" 48 | ], 49 | "defines": [ 50 | "_DEBUG", 51 | "UNICODE", 52 | "_UNICODE", 53 | "GRAPHICS_API_OPENGL_33", 54 | "PLATFORM_DESKTOP" 55 | ], 56 | "cStandard": "c11", 57 | "cppStandard": "c++14", 58 | "intelliSenseMode": "gcc-x64" 59 | } 60 | ], 61 | "version": 4 62 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Debug", 9 | "type": "cppdbg", 10 | "request": "launch", 11 | "program": "${workspaceFolder}/${fileBasenameNoExtension}", 12 | "args": [], 13 | "stopAtEntry": false, 14 | "cwd": "${workspaceFolder}", 15 | "environment": [], 16 | "externalConsole": false, 17 | "MIMode": "gdb", 18 | "setupCommands": [ 19 | { 20 | "description": "Enable pretty-printing for gdb", 21 | "text": "-enable-pretty-printing", 22 | "ignoreFailures": false 23 | } 24 | ], 25 | "windows": { 26 | "miDebuggerPath": "C:/raylib/w64devkit/bin/gdb.exe", 27 | }, 28 | "osx": { 29 | "MIMode": "lldb" 30 | }, 31 | "linux": { 32 | "miDebuggerPath": "/usr/bin/gdb", 33 | }, 34 | "preLaunchTask": "build debug" 35 | }, 36 | { 37 | "name": "Run", 38 | "type": "cppdbg", 39 | "request": "launch", 40 | "args": [], 41 | "stopAtEntry": false, 42 | "cwd": "${workspaceFolder}", 43 | "environment": [], 44 | "externalConsole": false, 45 | "program": "${workspaceFolder}/${fileBasenameNoExtension}", 46 | "MIMode": "gdb", 47 | "windows": { 48 | "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", 49 | "miDebuggerPath": "C:/raylib/w64devkit/bin/gdb.exe" 50 | }, 51 | "osx": { 52 | "MIMode": "lldb" 53 | }, 54 | "linux": { 55 | "miDebuggerPath": "/usr/bin/gdb" 56 | }, 57 | "preLaunchTask": "build release", 58 | } 59 | ] 60 | } 61 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.exclude": { 3 | "**/.git": true, 4 | "**/.svn": true, 5 | "**/.hg": true, 6 | "**/CVS": true, 7 | "**/.DS_Store": true, 8 | "**/*.o": true, 9 | "**/*.exe": true, 10 | } 11 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "build debug", 8 | "type": "process", 9 | "command": "make", 10 | "args": [ 11 | "PLATFORM=PLATFORM_DESKTOP", 12 | "BUILD_MODE=DEBUG" 13 | ], 14 | "windows": { 15 | "command": "C:/raylib/w64devkit/bin/mingw32-make.exe", 16 | "args": [ 17 | "RAYLIB_PATH=C:/raylib/raylib", 18 | "PROJECT_NAME=${fileBasenameNoExtension}", 19 | "OBJS=src/*.cpp", 20 | "BUILD_MODE=DEBUG" 21 | ] 22 | }, 23 | "osx": { 24 | "args": [ 25 | "PROJECT_NAME=${fileBasenameNoExtension}", 26 | "OBJS=src/*.cpp", 27 | "BUILD_MODE=DEBUG" 28 | ] 29 | }, 30 | "linux": { 31 | "args": [ 32 | "PROJECT_NAME=${fileBasenameNoExtension}", 33 | "DESTDIR=/home/linuxbrew/.linuxbrew", 34 | "RAYLIB_LIBTYPE=SHARED", 35 | "EXAMPLE_RUNTIME_PATH=/home/linuxbrew/.linuxbrew/lib", 36 | "OBJS=src/*.cpp", 37 | "BUILD_MODE=DEBUG" 38 | ] 39 | }, 40 | "group": { 41 | "kind": "build", 42 | "isDefault": true 43 | }, 44 | "problemMatcher": [ 45 | "$gcc" 46 | ] 47 | }, 48 | { 49 | "label": "build release", 50 | "type": "process", 51 | "command": "make", 52 | "args": [ 53 | "PLATFORM=PLATFORM_DESKTOP" 54 | ], 55 | "windows": { 56 | "command": "C:/raylib/w64devkit/bin/mingw32-make.exe", 57 | "args": [ 58 | "RAYLIB_PATH=C:/raylib/raylib", 59 | "PROJECT_NAME=${fileBasenameNoExtension}", 60 | "OBJS=*.cpp" 61 | ] 62 | }, 63 | "osx": { 64 | "args": [ 65 | "PROJECT_NAME=${fileBasenameNoExtension}", 66 | "OBJS=*.cpp" 67 | ] 68 | }, 69 | "linux": { 70 | "args": [ 71 | "PROJECT_NAME=${fileBasenameNoExtension}", 72 | "DESTDIR=/home/linuxbrew/.linuxbrew", 73 | "RAYLIB_LIBTYPE=SHARED", 74 | "EXAMPLE_RUNTIME_PATH=/home/linuxbrew/.linuxbrew/lib", 75 | "OBJS=*.cpp" 76 | ] 77 | }, 78 | "problemMatcher": [ 79 | "$gcc" 80 | ], 81 | "group": { 82 | "kind": "build", 83 | "isDefault": false 84 | }, 85 | "detail": "compiler: C:\\raylib\\mingw\\bin\\g++.exe" 86 | } 87 | ] 88 | } 89 | -------------------------------------------------------------------------------- /Font/monogram.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/educ8s/Cpp-Tetris-Game-with-raylib/663d96b2c15fb6fb62a7f35a1664192643ad91da/Font/monogram.ttf -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #************************************************************************************************** 2 | # 3 | # raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5 4 | # 5 | # Copyright (c) 2013-2019 Ramon Santamaria (@raysan5) 6 | # 7 | # This software is provided "as-is", without any express or implied warranty. In no event 8 | # will the authors be held liable for any damages arising from the use of this software. 9 | # 10 | # Permission is granted to anyone to use this software for any purpose, including commercial 11 | # applications, and to alter it and redistribute it freely, subject to the following restrictions: 12 | # 13 | # 1. The origin of this software must not be misrepresented; you must not claim that you 14 | # wrote the original software. If you use this software in a product, an acknowledgment 15 | # in the product documentation would be appreciated but is not required. 16 | # 17 | # 2. Altered source versions must be plainly marked as such, and must not be misrepresented 18 | # as being the original software. 19 | # 20 | # 3. This notice may not be removed or altered from any source distribution. 21 | # 22 | #************************************************************************************************** 23 | 24 | .PHONY: all clean 25 | 26 | # Define required raylib variables 27 | PROJECT_NAME ?= game 28 | RAYLIB_VERSION ?= 4.5.0 29 | RAYLIB_PATH ?= ..\.. 30 | 31 | # Define compiler path on Windows 32 | COMPILER_PATH ?= C:/raylib/w64devkit/bin 33 | 34 | # Define default options 35 | # One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB 36 | PLATFORM ?= PLATFORM_DESKTOP 37 | 38 | # Locations of your newly installed library and associated headers. See ../src/Makefile 39 | # On Linux, if you have installed raylib but cannot compile the examples, check that 40 | # the *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations. 41 | # To enable system-wide compile-time and runtime linking to libraylib.so, run ../src/$ sudo make install RAYLIB_LIBTYPE_SHARED. 42 | # To enable compile-time linking to a special version of libraylib.so, change these variables here. 43 | # To enable runtime linking to a special version of libraylib.so, see EXAMPLE_RUNTIME_PATH below. 44 | # If there is a libraylib in both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, at runtime, 45 | # the library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over the one at RAYLIB_INSTALL_PATH. 46 | # RAYLIB_INSTALL_PATH should be the desired full path to libraylib. No relative paths. 47 | DESTDIR ?= /usr/local 48 | RAYLIB_INSTALL_PATH ?= $(DESTDIR)/lib 49 | # RAYLIB_H_INSTALL_PATH locates the installed raylib header and associated source files. 50 | RAYLIB_H_INSTALL_PATH ?= $(DESTDIR)/include 51 | 52 | # Library type used for raylib: STATIC (.a) or SHARED (.so/.dll) 53 | RAYLIB_LIBTYPE ?= STATIC 54 | 55 | # Build mode for project: DEBUG or RELEASE 56 | BUILD_MODE ?= RELEASE 57 | 58 | # Use external GLFW library instead of rglfw module 59 | # TODO: Review usage on Linux. Target version of choice. Switch on -lglfw or -lglfw3 60 | USE_EXTERNAL_GLFW ?= FALSE 61 | 62 | # Use Wayland display server protocol on Linux desktop 63 | # by default it uses X11 windowing system 64 | USE_WAYLAND_DISPLAY ?= FALSE 65 | 66 | # Determine PLATFORM_OS in case PLATFORM_DESKTOP selected 67 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) 68 | # No uname.exe on MinGW!, but OS=Windows_NT on Windows! 69 | # ifeq ($(UNAME),Msys) -> Windows 70 | ifeq ($(OS),Windows_NT) 71 | PLATFORM_OS=WINDOWS 72 | export PATH := $(COMPILER_PATH):$(PATH) 73 | else 74 | UNAMEOS=$(shell uname) 75 | ifeq ($(UNAMEOS),Linux) 76 | PLATFORM_OS=LINUX 77 | endif 78 | ifeq ($(UNAMEOS),FreeBSD) 79 | PLATFORM_OS=BSD 80 | endif 81 | ifeq ($(UNAMEOS),OpenBSD) 82 | PLATFORM_OS=BSD 83 | endif 84 | ifeq ($(UNAMEOS),NetBSD) 85 | PLATFORM_OS=BSD 86 | endif 87 | ifeq ($(UNAMEOS),DragonFly) 88 | PLATFORM_OS=BSD 89 | endif 90 | ifeq ($(UNAMEOS),Darwin) 91 | PLATFORM_OS=OSX 92 | endif 93 | endif 94 | endif 95 | ifeq ($(PLATFORM),PLATFORM_RPI) 96 | UNAMEOS=$(shell uname) 97 | ifeq ($(UNAMEOS),Linux) 98 | PLATFORM_OS=LINUX 99 | endif 100 | endif 101 | 102 | # RAYLIB_PATH adjustment for different platforms. 103 | # If using GNU make, we can get the full path to the top of the tree. Windows? BSD? 104 | # Required for ldconfig or other tools that do not perform path expansion. 105 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) 106 | ifeq ($(PLATFORM_OS),LINUX) 107 | RAYLIB_PREFIX ?= .. 108 | RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX)) 109 | endif 110 | endif 111 | # Default path for raylib on Raspberry Pi, if installed in different path, update it! 112 | # This is not currently used by src/Makefile. Not sure of its origin or usage. Refer to wiki. 113 | # TODO: update install: target in src/Makefile for RPI, consider relation to LINUX. 114 | ifeq ($(PLATFORM),PLATFORM_RPI) 115 | RAYLIB_PATH ?= /home/pi/raylib 116 | endif 117 | 118 | ifeq ($(PLATFORM),PLATFORM_WEB) 119 | # Emscripten required variables 120 | EMSDK_PATH ?= C:/emsdk 121 | EMSCRIPTEN_VERSION ?= 1.38.31 122 | CLANG_VERSION = e$(EMSCRIPTEN_VERSION)_64bit 123 | PYTHON_VERSION = 2.7.13.1_64bit\python-2.7.13.amd64 124 | NODE_VERSION = 8.9.1_64bit 125 | export PATH = $(EMSDK_PATH);$(EMSDK_PATH)\clang\$(CLANG_VERSION);$(EMSDK_PATH)\node\$(NODE_VERSION)\bin;$(EMSDK_PATH)\python\$(PYTHON_VERSION);$(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION);C:\raylib\MinGW\bin:$$(PATH) 126 | EMSCRIPTEN = $(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION) 127 | endif 128 | 129 | # Define raylib release directory for compiled library. 130 | # RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version 131 | RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src 132 | 133 | # EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries 134 | # into each example binary compiled with RAYLIB_LIBTYPE=SHARED. It defaults to RAYLIB_RELEASE_PATH 135 | # so that these examples link at runtime with your version of libraylib.so in ../release/libs/linux 136 | # without formal installation from ../src/Makefile. It aids portability and is useful if you have 137 | # multiple versions of raylib, have raylib installed to a non-standard location, or want to 138 | # bundle libraylib.so with your game. Change it to your liking. 139 | # NOTE: If, at runtime, there is a libraylib.so at both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, 140 | # The library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over RAYLIB_INSTALL_PATH, 141 | # Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH) 142 | # To see the result, run readelf -d core/core_basic_window; looking at the RPATH or RUNPATH attribute. 143 | # To see which libraries a built example is linking to, ldd core/core_basic_window; 144 | # Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 or similar listing. 145 | EXAMPLE_RUNTIME_PATH ?= $(RAYLIB_RELEASE_PATH) 146 | 147 | # Define default C compiler: gcc 148 | # NOTE: define g++ compiler if using C++ 149 | CC = g++ 150 | 151 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) 152 | ifeq ($(PLATFORM_OS),OSX) 153 | # OSX default compiler 154 | CC = clang++ 155 | endif 156 | ifeq ($(PLATFORM_OS),BSD) 157 | # FreeBSD, OpenBSD, NetBSD, DragonFly default compiler 158 | CC = clang 159 | endif 160 | endif 161 | ifeq ($(PLATFORM),PLATFORM_RPI) 162 | ifeq ($(USE_RPI_CROSS_COMPILER),TRUE) 163 | # Define RPI cross-compiler 164 | #CC = armv6j-hardfloat-linux-gnueabi-gcc 165 | CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc 166 | endif 167 | endif 168 | ifeq ($(PLATFORM),PLATFORM_WEB) 169 | # HTML5 emscripten compiler 170 | # WARNING: To compile to HTML5, code must be redesigned 171 | # to use emscripten.h and emscripten_set_main_loop() 172 | CC = emcc 173 | endif 174 | 175 | # Define default make program: Mingw32-make 176 | MAKE = mingw32-make 177 | 178 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) 179 | ifeq ($(PLATFORM_OS),LINUX) 180 | MAKE = make 181 | endif 182 | ifeq ($(PLATFORM_OS),OSX) 183 | MAKE = make 184 | endif 185 | endif 186 | 187 | # Define compiler flags: 188 | # -O0 defines optimization level (no optimization, better for debugging) 189 | # -O1 defines optimization level 190 | # -g include debug information on compilation 191 | # -s strip unnecessary data from build -> do not use in debug builds 192 | # -Wall turns on most, but not all, compiler warnings 193 | # -std=c99 defines C language mode (standard C from 1999 revision) 194 | # -std=gnu99 defines C language mode (GNU C from 1999 revision) 195 | # -Wno-missing-braces ignore invalid warning (GCC bug 53119) 196 | # -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec 197 | CFLAGS += -Wall -std=c++14 -D_DEFAULT_SOURCE -Wno-missing-braces 198 | 199 | ifeq ($(BUILD_MODE),DEBUG) 200 | CFLAGS += -g -O0 201 | else 202 | CFLAGS += -s -O1 203 | endif 204 | 205 | # Additional flags for compiler (if desired) 206 | #CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes 207 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) 208 | ifeq ($(PLATFORM_OS),WINDOWS) 209 | # resource file contains windows executable icon and properties 210 | # -Wl,--subsystem,windows hides the console window 211 | CFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data 212 | endif 213 | ifeq ($(PLATFORM_OS),LINUX) 214 | ifeq ($(RAYLIB_LIBTYPE),STATIC) 215 | CFLAGS += -D_DEFAULT_SOURCE 216 | endif 217 | ifeq ($(RAYLIB_LIBTYPE),SHARED) 218 | # Explicitly enable runtime link to libraylib.so 219 | CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH) 220 | endif 221 | endif 222 | endif 223 | ifeq ($(PLATFORM),PLATFORM_RPI) 224 | CFLAGS += -std=gnu99 225 | endif 226 | ifeq ($(PLATFORM),PLATFORM_WEB) 227 | # -Os # size optimization 228 | # -O2 # optimization level 2, if used, also set --memory-init-file 0 229 | # -s USE_GLFW=3 # Use glfw3 library (context/input management) 230 | # -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing -> WARNING: Audio buffers could FAIL! 231 | # -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB) 232 | # -s USE_PTHREADS=1 # multithreading support 233 | # -s WASM=0 # disable Web Assembly, emitted by default 234 | # -s EMTERPRETIFY=1 # enable emscripten code interpreter (very slow) 235 | # -s EMTERPRETIFY_ASYNC=1 # support synchronous loops by emterpreter 236 | # -s FORCE_FILESYSTEM=1 # force filesystem to load/save files data 237 | # -s ASSERTIONS=1 # enable runtime checks for common memory allocation errors (-O1 and above turn it off) 238 | # --profiling # include information for code profiling 239 | # --memory-init-file 0 # to avoid an external memory initialization code file (.mem) 240 | # --preload-file resources # specify a resources folder for data compilation 241 | CFLAGS += -Os -s USE_GLFW=3 -s TOTAL_MEMORY=16777216 --preload-file resources 242 | ifeq ($(BUILD_MODE), DEBUG) 243 | CFLAGS += -s ASSERTIONS=1 --profiling 244 | endif 245 | 246 | # Define a custom shell .html and output extension 247 | CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html 248 | EXT = .html 249 | endif 250 | 251 | # Define include paths for required headers 252 | # NOTE: Several external required libraries (stb and others) 253 | INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external 254 | ifneq ($(wildcard /opt/homebrew/include/.*),) 255 | INCLUDE_PATHS += -I/opt/homebrew/include 256 | endif 257 | 258 | # Define additional directories containing required header files 259 | ifeq ($(PLATFORM),PLATFORM_RPI) 260 | # RPI required libraries 261 | INCLUDE_PATHS += -I/opt/vc/include 262 | INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux 263 | INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads 264 | endif 265 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) 266 | ifeq ($(PLATFORM_OS),BSD) 267 | # Consider -L$(RAYLIB_H_INSTALL_PATH) 268 | INCLUDE_PATHS += -I/usr/local/include 269 | endif 270 | ifeq ($(PLATFORM_OS),LINUX) 271 | # Reset everything. 272 | # Precedence: immediately local, installed version, raysan5 provided libs -I$(RAYLIB_H_INSTALL_PATH) -I$(RAYLIB_PATH)/release/include 273 | INCLUDE_PATHS = -I$(RAYLIB_H_INSTALL_PATH) -isystem. -isystem$(RAYLIB_PATH)/src -isystem$(RAYLIB_PATH)/release/include -isystem$(RAYLIB_PATH)/src/external 274 | endif 275 | endif 276 | 277 | # Define library paths containing required libs. 278 | LDFLAGS = -L. 279 | 280 | ifneq ($(wildcard $(RAYLIB_RELEASE_PATH)/.*),) 281 | LDFLAGS += -L$(RAYLIB_RELEASE_PATH) 282 | endif 283 | ifneq ($(wildcard $(RAYLIB_PATH)/src/.*),) 284 | LDFLAGS += -L$(RAYLIB_PATH)/src 285 | endif 286 | ifneq ($(wildcard /opt/homebrew/lib/.*),) 287 | LDFLAGS += -L/opt/homebrew/lib 288 | endif 289 | 290 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) 291 | ifeq ($(PLATFORM_OS),BSD) 292 | # Consider -L$(RAYLIB_INSTALL_PATH) 293 | LDFLAGS += -L. -Lsrc -L/usr/local/lib 294 | endif 295 | ifeq ($(PLATFORM_OS),LINUX) 296 | # Reset everything. 297 | # Precedence: immediately local, installed version, raysan5 provided libs 298 | LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH) 299 | endif 300 | endif 301 | 302 | ifeq ($(PLATFORM),PLATFORM_RPI) 303 | LDFLAGS += -L/opt/vc/lib 304 | endif 305 | 306 | # Define any libraries required on linking 307 | # if you want to link libraries (libname.so or libname.a), use the -lname 308 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) 309 | ifeq ($(PLATFORM_OS),WINDOWS) 310 | # Libraries for Windows desktop compilation 311 | # NOTE: WinMM library required to set high-res timer resolution 312 | LDLIBS = -lraylib -lopengl32 -lgdi32 -lwinmm 313 | # Required for physac examples 314 | #LDLIBS += -static -lpthread 315 | endif 316 | ifeq ($(PLATFORM_OS),LINUX) 317 | # Libraries for Debian GNU/Linux desktop compiling 318 | # NOTE: Required packages: libegl1-mesa-dev 319 | LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt 320 | 321 | # On X11 requires also below libraries 322 | LDLIBS += -lX11 323 | # NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them 324 | #LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor 325 | 326 | # On Wayland windowing system, additional libraries requires 327 | ifeq ($(USE_WAYLAND_DISPLAY),TRUE) 328 | LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon 329 | endif 330 | # Explicit link to libc 331 | ifeq ($(RAYLIB_LIBTYPE),SHARED) 332 | LDLIBS += -lc 333 | endif 334 | endif 335 | ifeq ($(PLATFORM_OS),OSX) 336 | # Libraries for OSX 10.9 desktop compiling 337 | # NOTE: Required packages: libopenal-dev libegl1-mesa-dev 338 | LDLIBS = -lraylib -framework OpenGL -framework OpenAL -framework Cocoa -framework IOKit 339 | endif 340 | ifeq ($(PLATFORM_OS),BSD) 341 | # Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling 342 | # NOTE: Required packages: mesa-libs 343 | LDLIBS = -lraylib -lGL -lpthread -lm 344 | 345 | # On XWindow requires also below libraries 346 | LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor 347 | endif 348 | ifeq ($(USE_EXTERNAL_GLFW),TRUE) 349 | # NOTE: It could require additional packages installed: libglfw3-dev 350 | LDLIBS += -lglfw 351 | endif 352 | endif 353 | ifeq ($(PLATFORM),PLATFORM_RPI) 354 | # Libraries for Raspberry Pi compiling 355 | # NOTE: Required packages: libasound2-dev (ALSA) 356 | LDLIBS = -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl 357 | endif 358 | ifeq ($(PLATFORM),PLATFORM_WEB) 359 | # Libraries for web (HTML5) compiling 360 | LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.bc 361 | endif 362 | 363 | # Define a recursive wildcard function 364 | rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) 365 | 366 | # Define all source files required 367 | SRC_DIR = src 368 | OBJ_DIR = obj 369 | 370 | # Define all object files from source files 371 | SRC = $(call rwildcard, *.c, *.h) 372 | #OBJS = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) 373 | OBJS ?= main.c 374 | 375 | # For Android platform we call a custom Makefile.Android 376 | ifeq ($(PLATFORM),PLATFORM_ANDROID) 377 | MAKEFILE_PARAMS = -f Makefile.Android 378 | export PROJECT_NAME 379 | export SRC_DIR 380 | else 381 | MAKEFILE_PARAMS = $(PROJECT_NAME) 382 | endif 383 | 384 | # Default target entry 385 | # NOTE: We call this Makefile target or Makefile.Android target 386 | all: 387 | $(MAKE) $(MAKEFILE_PARAMS) 388 | 389 | # Project target defined by PROJECT_NAME 390 | $(PROJECT_NAME): $(OBJS) 391 | $(CC) -o $(PROJECT_NAME)$(EXT) $(OBJS) $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) 392 | 393 | # Compile source files 394 | # NOTE: This pattern will compile every module defined on $(OBJS) 395 | #%.o: %.c 396 | $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c 397 | $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) 398 | 399 | # Clean everything 400 | clean: 401 | ifeq ($(PLATFORM),PLATFORM_DESKTOP) 402 | ifeq ($(PLATFORM_OS),WINDOWS) 403 | del *.o *.exe /s 404 | endif 405 | ifeq ($(PLATFORM_OS),LINUX) 406 | find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -fv 407 | endif 408 | ifeq ($(PLATFORM_OS),OSX) 409 | find . -type f -perm +ugo+x -delete 410 | rm -f *.o 411 | endif 412 | endif 413 | ifeq ($(PLATFORM),PLATFORM_RPI) 414 | find . -type f -executable -delete 415 | rm -fv *.o 416 | endif 417 | ifeq ($(PLATFORM),PLATFORM_WEB) 418 | del *.o *.html *.js 419 | endif 420 | @echo Cleaning done 421 | 422 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C++ Tetris Game using raylib 2 | 3 | 🕹️🐍🎮 This GitHub repository is home to the full source code for a Tetris game built with the C++ programming language and the raylib library. 💻🎨🎧 The game uses various raylib functions for graphics, input handling, and audio and can be played on Windows, macOS, and Linux computers. 🔍📖 The code is well-structured and easy to read, making it a valuable resource for aspiring game developers looking to learn about raylib game programming. 4 | 5 | If you want to learn how to build your own Tetris game with raylib, check out the accompanying Video Tutorial on YouTube. 🎬👨💻 The tutorial guides you through every line of code, explaining the logic behind it and demonstrating how it affects the game. You'll discover how to set up the game window, create the Grid and block classes, add collision detection, and implement sound effects. By the end of the tutorial, you'll have a fully functional Tetris game that you can play and modify however you like. ☕ So, grab a cup of coffee and let's dive into the exciting world of game development with raylib! 🚀 6 | 7 | # Video Tutorial 8 | 9 |
10 |
11 |
14 | 🎥 Video Tutorial on YouTube 15 |
16 | 17 |
20 | | 📺 My YouTube Channel
21 | | 🌍 My Website |
22 |