Initial release: SDL Windows Tetris

This commit is contained in:
2025-08-15 11:01:48 +02:00
commit d161b2c550
196 changed files with 5944 additions and 0 deletions

44
.github/copilot-instructions.md vendored Normal file
View File

@ -0,0 +1,44 @@
# Copilot Instructions — Tetris (C++ SDL3)
Purpose: Speed up development on this native SDL3 Tetris. Follow these conventions to keep builds reproducible and packages shippable.
## Project shape
- C++20 app using SDL3 + SDL3_ttf via vcpkg.
- Build system: CMake; Windows-focused, but portable with proper toolchain.
- Sources: `src/` (Game.cpp, Scores.cpp, Starfield*.cpp, Audio.cpp, LineEffect.cpp, Font.cpp, SoundEffect.cpp, main.cpp).
- Assets: `assets/` (images/music/fonts), plus `FreeSans.ttf` at repo root.
## Build and run
- Configure and build Release:
- CMake picks up vcpkg toolchain if found (`VCPKG_ROOT`, local `vcpkg/`, or user path). Required packages: `sdl3`, `sdl3-ttf` (see `vcpkg.json`).
- Typical sequence (PowerShell): `cmake -S . -B build-release -DCMAKE_BUILD_TYPE=Release` then `cmake --build build-release --config Release`.
- Packaging: `.\build-production.ps1` creates `dist/TetrisGame/` with exe, DLLs, assets, README, and ZIP; it can clean via `-Clean` and package-only via `-PackageOnly`.
- MSVC generator builds are under `build-msvc/` when using Visual Studio.
## Runtime dependencies
- Links: `SDL3::SDL3`, `SDL3_ttf::SDL3_ttf`; on Windows also `mfplat`, `mfreadwrite`, `mfuuid` for media.
- The package step copies `SDL3.dll` and `SDL3_ttf.dll` from `vcpkg_installed/x64-windows/bin/` if present. If changing triplet or layout, update paths in `build-production.ps1`.
## Key modules and responsibilities
- Game loop and state: `Game.cpp/h` (core), `main.cpp` (entry), `Scores.cpp/h` (high-scores/local), `LineEffect.cpp` (row clear visuals), `Starfield.cpp` and `Starfield3D.cpp` (background effects), `Audio.cpp` + `SoundEffect.cpp` (music/SFX), `Font.cpp` (TTF text rendering).
- Keep drawing and update timing consistent; prefer updating effects modules rather than inlining in `Game.cpp`.
## Assets and fonts
- Expect `assets/` folder adjacent to the executable; `FreeSans.ttf` is copied next to the exe by packaging scripts.
- When adding assets, ensure packaging script includes new folders/files; use BMP/PNG consistently with existing loaders.
## Conventions
- C++20, no exceptions policy not enforced; match current code style in each file.
- Use SDL_ttf for text; dont vendor fonts in code—load from filesystem as done in `Font.cpp`.
- Avoid hardcoding absolute paths; rely on relative paths within the package layout.
## Useful files
- `CMakeLists.txt` — targets, toolchain detection, link libs.
- `vcpkg.json` and `vcpkg-configuration.json` — dependencies and registry.
- `build-production.ps1` — authoritative packaging steps and expected layout.
- `cmake/ProductionBuild.cmake` — extra flags if needed (included by `CMakeLists.txt`).
## When extending
- Add new modules under `src/` and register them in `CMakeLists.txt` target sources.
- If new DLLs are required, extend the copy list in `build-production.ps1` and document them in the generated README.
- Validate with a Release build before packaging to catch optimizer-related issues.

114
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,114 @@
name: Build and Package Tetris
on:
push:
branches: [ main, master ]
tags: [ 'v*' ]
pull_request:
branches: [ main, master ]
jobs:
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
with:
vcpkgGitCommitId: 'latest'
- name: Install dependencies
run: |
vcpkg install sdl3 sdl3-image sdl3-ttf --triplet=x64-windows
- name: Configure CMake
run: |
cmake -B build -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Release
- name: Build
run: cmake --build build --config Release
- name: Package
run: cmake --build build --target package
- name: Create distribution package
run: |
mkdir dist
powershell -ExecutionPolicy Bypass -File build-production.ps1 -PackageOnly -OutputDir dist
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: tetris-windows-x64
path: dist/TetrisGame/
- name: Create Release ZIP
if: startsWith(github.ref, 'refs/tags/v')
run: |
cd dist
7z a ../TetrisGame-Windows-x64.zip TetrisGame/
- name: Release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v1
with:
files: TetrisGame-Windows-x64.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake build-essential
# Install SDL3 from source or package manager
# This may need adjustment based on SDL3 availability
- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=Release
- name: Build
run: cmake --build build
- name: Package
run: |
mkdir -p dist/TetrisGame-Linux
cp build/tetris dist/TetrisGame-Linux/
cp -r assets dist/TetrisGame-Linux/
cp FreeSans.ttf dist/TetrisGame-Linux/
echo '#!/bin/bash' > dist/TetrisGame-Linux/launch-tetris.sh
echo 'cd "$(dirname "$0")"' >> dist/TetrisGame-Linux/launch-tetris.sh
echo './tetris' >> dist/TetrisGame-Linux/launch-tetris.sh
chmod +x dist/TetrisGame-Linux/launch-tetris.sh
chmod +x dist/TetrisGame-Linux/tetris
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: tetris-linux-x64
path: dist/TetrisGame-Linux/
- name: Create Release TAR
if: startsWith(github.ref, 'refs/tags/v')
run: |
cd dist
tar -czf ../TetrisGame-Linux-x64.tar.gz TetrisGame-Linux/
- name: Release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v1
with:
files: TetrisGame-Linux-x64.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

73
.gitignore vendored Normal file
View File

@ -0,0 +1,73 @@
# .gitignore for Tetris (native C++ project and web subproject)
# Visual Studio / VS artifacts
.vs/
*.vcxproj.user
*.suo
*.user
*.userosscache
*.sln.docstates
# Build directories and CMake artifacts
/build/
/build-*/
/build-msvc/
/build-release/
/dist/
/CMakeFiles/
CMakeCache.txt
cmake_install.cmake
Makefile
# vcpkg
/vcpkg_installed/
/vcpkg/
# IDEs
.vscode/
.idea/
# OS
Thumbs.db
.DS_Store
# Binaries and object files
*.exe
*.dll
*.pdb
*.lib
*.obj
*.o
# Archives and packages
*.zip
*.7z
*.tar.gz
# Logs, caches, temp
*.log
*.tmp
*.cache
# Node / web build outputs (web project under Tetris/)
Tetris/node_modules/
node_modules/
Tetris/dist/
Tetris/.vite/
Tetris/.cache/
# Python
__pycache__/
*.py[cod]
# Database / misc
*.db
*.sqlite
# Ignore any local packaging outputs
dist_package/
# Local environment files (if any)
.env
# End of .gitignore

45
CMakeLists.txt Normal file
View File

@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.20)
# Integrate vcpkg toolchain if available
if(DEFINED ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
elseif(EXISTS "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
elseif(EXISTS "C:/Users/Gregor Klevže/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_TOOLCHAIN_FILE "C:/Users/Gregor Klevže/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
endif()
project(tetris_sdl3 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Find SDL3 (via package manager or a local build)
# vcpkg example: vcpkg install sdl3
# Homebrew: brew install sdl3
find_package(SDL3 CONFIG REQUIRED)
find_package(SDL3_ttf CONFIG REQUIRED)
add_executable(tetris
src/main.cpp
src/Game.cpp
src/Scores.cpp
src/Starfield.cpp
src/Starfield3D.cpp
src/Font.cpp
src/Audio.cpp
src/LineEffect.cpp
src/SoundEffect.cpp
# State implementations (new)
src/states/LoadingState.cpp
src/states/MenuState.cpp
)
target_link_libraries(tetris PRIVATE SDL3::SDL3 SDL3_ttf::SDL3_ttf)
if (WIN32)
target_link_libraries(tetris PRIVATE mfplat mfreadwrite mfuuid)
endif()
# Include production build configuration
include(cmake/ProductionBuild.cmake)

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
assets/favicon/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 2.0 MiB

BIN
assets/fonts/FreeSans.ttf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
assets/images/blocks001.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
assets/images/blocks001.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
assets/images/blocks3.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
assets/images/blocks3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

BIN
assets/images/game_over.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 617 KiB

BIN
assets/images/game_over.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 KiB

BIN
assets/images/gameplay.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
assets/images/gameplay.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
assets/images/gameplay1.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 MiB

BIN
assets/images/gameplay1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 KiB

BIN
assets/images/gameplay2.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 MiB

BIN
assets/images/gameplay2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 658 KiB

BIN
assets/images/gameplay3.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 MiB

BIN
assets/images/gameplay3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

BIN
assets/images/logo.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 930 KiB

BIN
assets/images/logo.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1007 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 957 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 805 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 947 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 825 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 970 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1007 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 828 KiB

Some files were not shown because too many files have changed in this diff Show More