Tetris implementation in Rust using the SDL2 library.
Tetris is available on Itch.io at aardhyn.itch.io/Tetris.
Or, download the latest precompiled executable for your platform under Releases.
For building from source.
You will need to Install Rust.
You will need to install the SDL2 libraries. I've had little success with the SDL3 wrapper, plus it's still technically in beta.
I've found Microsoft VCPKG to be a simple (and multiplatform) method.
cargo install cargo-vcpkg
cargo vcpkg build
cargo build
There are other installation methods not involving VCPKG described in the SDL2-Rust Repository, but I've not tested any of these.
I've enabled the unsafe_textures
feature for the sdl2
crate in Cargo.toml
which omits the generic lifetime
annotations for the sdl2::rendering::Texture
struct.
This removes the need to propagate lifetime annotations throughout the codebase when dealing with textures.
As textures are dropped before their "owning" TextureCreator
, there is no risk of dangling references or memory
leaks.
build and run executable for your platform.
make
# or
cargo run # compile and run
Bundling is the process of packaging the application, its dependencies, and resources into a single easily shareable file.
Install all the SDL2 frameworks (.framework
directories) SDL2, SDL_image, SDL_ttf and SDL_mixer.
Make sure these are stored in /Library/Frameworks/
or wherever you store your frameworks.
And run
cargo bundle --release
# or
make bundle
Unfortunately, I've not found any ways to successfully bundle a Rust application on Windows as cargo-bundle does not
build .msi
files correctly.
I've not had success with the WiX Toolset or either.
To ship the application, you can provide the tetris.exe
and the asset/
directory.
See CREDITS.
I do not claim to have created the Tetris game, nor any of the music or sfx used in this software.
ChatGPT 3.5 was used to aid my understanding of algorithmic concepts and design patterns while learning Rust. Not for the generation of production code.
GitHub Copilot was used to generate code I understood and would have written myself. An autocompletion tool.