Initial release: SDL Windows Tetris
44
.github/copilot-instructions.md
vendored
Normal 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; don’t 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
@ -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
@ -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
@ -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)
|
||||
BIN
assets/favicon/android-chrome-192x192.png
Normal file
|
After Width: | Height: | Size: 62 KiB |
BIN
assets/favicon/android-chrome-512x512.png
Normal file
|
After Width: | Height: | Size: 460 KiB |
BIN
assets/favicon/apple-touch-icon.png
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
assets/favicon/favicon-144x144.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
assets/favicon/favicon-152x152.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
assets/favicon/favicon-16x16.png
Normal file
|
After Width: | Height: | Size: 788 B |
BIN
assets/favicon/favicon-180x180.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
assets/favicon/favicon-192x192.png
Normal file
|
After Width: | Height: | Size: 57 KiB |
BIN
assets/favicon/favicon-32x32.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
assets/favicon/favicon-384x384.png
Normal file
|
After Width: | Height: | Size: 196 KiB |
BIN
assets/favicon/favicon-512x512.png
Normal file
|
After Width: | Height: | Size: 438 KiB |
BIN
assets/favicon/favicon-72x72.png
Normal file
|
After Width: | Height: | Size: 9.0 KiB |
BIN
assets/favicon/favicon-96x96.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
assets/favicon/favicon.ico
Normal file
|
After Width: | Height: | Size: 15 KiB |
3
assets/favicon/favicon.svg
Normal file
|
After Width: | Height: | Size: 2.0 MiB |
BIN
assets/fonts/FreeSans.ttf
Normal file
BIN
assets/fonts/FreeSansBold.ttf
Normal file
BIN
assets/fonts/PressStart2P-Regular.ttf
Normal file
BIN
assets/images/background.bmp
Normal file
|
After Width: | Height: | Size: 12 MiB |
BIN
assets/images/background.png
Normal file
|
After Width: | Height: | Size: 1.9 MiB |
BIN
assets/images/background.webp
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
assets/images/blocks001.bmp
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
assets/images/blocks001.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
assets/images/blocks3.bmp
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
assets/images/blocks3.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
assets/images/blocks90px_001.bmp
Normal file
|
After Width: | Height: | Size: 253 KiB |
BIN
assets/images/blocks90px_001.png
Normal file
|
After Width: | Height: | Size: 106 KiB |
BIN
assets/images/game_over.bmp
Normal file
|
After Width: | Height: | Size: 617 KiB |
BIN
assets/images/game_over.png
Normal file
|
After Width: | Height: | Size: 270 KiB |
BIN
assets/images/gameplay.bmp
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
assets/images/gameplay.webp
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
assets/images/gameplay1.bmp
Normal file
|
After Width: | Height: | Size: 12 MiB |
BIN
assets/images/gameplay1.jpg
Normal file
|
After Width: | Height: | Size: 237 KiB |
BIN
assets/images/gameplay2.bmp
Normal file
|
After Width: | Height: | Size: 14 MiB |
BIN
assets/images/gameplay2.jpg
Normal file
|
After Width: | Height: | Size: 658 KiB |
BIN
assets/images/gameplay3.bmp
Normal file
|
After Width: | Height: | Size: 8.7 MiB |
BIN
assets/images/gameplay3.jpg
Normal file
|
After Width: | Height: | Size: 154 KiB |
BIN
assets/images/logo.bmp
Normal file
|
After Width: | Height: | Size: 930 KiB |
BIN
assets/images/logo.webp
Normal file
|
After Width: | Height: | Size: 195 KiB |
BIN
assets/images/logo_small.bmp
Normal file
|
After Width: | Height: | Size: 110 KiB |
BIN
assets/images/logo_small.webp
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
assets/images/main_background.bmp
Normal file
|
After Width: | Height: | Size: 12 MiB |
BIN
assets/images/main_background.webp
Normal file
|
After Width: | Height: | Size: 66 KiB |
BIN
assets/images/tetris_main_back_level0.bmp
Normal file
|
After Width: | Height: | Size: 12 MiB |
BIN
assets/images/tetris_main_back_level0.jpg
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
assets/images/tetris_main_back_level0x.bmp
Normal file
|
After Width: | Height: | Size: 1.4 MiB |
BIN
assets/images/tetris_main_back_level1.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level1.jpg
Normal file
|
After Width: | Height: | Size: 1.6 MiB |
BIN
assets/images/tetris_main_back_level10.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level10.jpg
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
assets/images/tetris_main_back_level11.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level11.jpg
Normal file
|
After Width: | Height: | Size: 756 KiB |
BIN
assets/images/tetris_main_back_level12.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level12.jpg
Normal file
|
After Width: | Height: | Size: 1007 KiB |
BIN
assets/images/tetris_main_back_level13.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level13.jpg
Normal file
|
After Width: | Height: | Size: 1.0 MiB |
BIN
assets/images/tetris_main_back_level14.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level14.jpg
Normal file
|
After Width: | Height: | Size: 957 KiB |
BIN
assets/images/tetris_main_back_level15.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level15.jpg
Normal file
|
After Width: | Height: | Size: 805 KiB |
BIN
assets/images/tetris_main_back_level16.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level16.jpg
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
assets/images/tetris_main_back_level17.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level17.jpg
Normal file
|
After Width: | Height: | Size: 947 KiB |
BIN
assets/images/tetris_main_back_level18.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level18.jpg
Normal file
|
After Width: | Height: | Size: 1.6 MiB |
BIN
assets/images/tetris_main_back_level19.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level19.jpg
Normal file
|
After Width: | Height: | Size: 1.3 MiB |
BIN
assets/images/tetris_main_back_level2.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level2.jpg
Normal file
|
After Width: | Height: | Size: 1.4 MiB |
BIN
assets/images/tetris_main_back_level20.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level20.jpg
Normal file
|
After Width: | Height: | Size: 825 KiB |
BIN
assets/images/tetris_main_back_level21.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level21.jpg
Normal file
|
After Width: | Height: | Size: 1.7 MiB |
BIN
assets/images/tetris_main_back_level22.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level22.jpg
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
assets/images/tetris_main_back_level23.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level23.jpg
Normal file
|
After Width: | Height: | Size: 1.3 MiB |
BIN
assets/images/tetris_main_back_level24.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level24.jpg
Normal file
|
After Width: | Height: | Size: 970 KiB |
BIN
assets/images/tetris_main_back_level25.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level25.jpg
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
assets/images/tetris_main_back_level26.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level26.jpg
Normal file
|
After Width: | Height: | Size: 1.6 MiB |
BIN
assets/images/tetris_main_back_level27.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level27.jpg
Normal file
|
After Width: | Height: | Size: 2.3 MiB |
BIN
assets/images/tetris_main_back_level28.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level28.jpg
Normal file
|
After Width: | Height: | Size: 1007 KiB |
BIN
assets/images/tetris_main_back_level29.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level29.jpg
Normal file
|
After Width: | Height: | Size: 638 KiB |
BIN
assets/images/tetris_main_back_level3.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level3.jpg
Normal file
|
After Width: | Height: | Size: 1.2 MiB |
BIN
assets/images/tetris_main_back_level30.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level30.jpg
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
BIN
assets/images/tetris_main_back_level31.bmp
Normal file
|
After Width: | Height: | Size: 24 MiB |
BIN
assets/images/tetris_main_back_level31.jpg
Normal file
|
After Width: | Height: | Size: 828 KiB |