Skip to content

Latest commit

 

History

History
90 lines (77 loc) · 5.27 KB

README.md

File metadata and controls

90 lines (77 loc) · 5.27 KB

Pixeltetris

A Tetris game written from scratch in C++ using the SDL2 development library. Apart from the core gameplay, the project also includes some extra features like a ghost block to reduce misdrops, a simple main menu, and support for multiple resolutions. All sprites were created by me.

Gallery

Installation

If you just want to try the game on your Windows or Linux machine, go the Releases page and get the latest executable.

  • For Windows you may need the Microsoft Visual C++ Redistributables if you don't have them already installed.
  • For Linux you need to install g++, and the SDL2, SDL2_ttf, and SDL2_image runtime libraries, which should be easily found in your distribution's repository. For Debian-based systems, use:
sudo apt install g++
sudo apt install libsdl2-2.0-0
sudo apt install libsdl2-ttf-2.0-0
sudo apt install libsdl2-image-2.0-0

Build Instructions

This is the first project where I use CMake to support multiple OSes and compilers, so to compile the game yourself you will need CMake.

Windows

  • First of all you need Visual Studio to compile the game. I have only compiled with Visual Studio Community, but I assume that other versions work as well.
  • Clone the repository to your machine using Visual Studio.
  • You will also need the SDL2, SDL_ttf 2.0, and SDL_image 2.0 development libraries. Make sure to download the versions denoted with "Visual C++". Extract all zip files to the root directory of the repository you cloned.
  • Open the project folder with Visual Studio.
  • Select CMakeLists.txt in the root of the project to compile.
  • You may need to change the Build root option in CMakeSettings.json from ${projectDir}\out\build${name} to ${projectDir}\build${name}, so that the font loads correctly.

Linux

  • Firstly, install the g++ compiler using a command like sudo apt install g++ or sudo dnf install gcc-g++. Then, install CMake using a command like sudo apt install cmake or sudo dnf install cmake.
  • You will also need the SDL2, SDL_ttf and SDL_image libaries. Install them on Debian-based systems by running:
sudo apt install libsdl2-dev
sudo apt install libsdl2-ttf-dev
sudo apt install libsdl2-image-dev

or on Fedora-based systems by running:

sudo dnf install SDL2-devel
sudo dnf install SDL2_ttf-devel
sudo dnf install SDL2_image-devel
  • Clone the repository to your PC.
  • Open a terminal window in the root directory of the cloned repository and run these commands one by one:
mkdir build
cmake -B build
cd build
make

You will then find the Pixeltetris executable in build.

MacOS

I do not have a MacOS machine so I cannot test any builds for that OS. However, the process of compilation should not be very different from that in Linux, since the CMake find files work in all OSes.

Controls

  • Left/Right/Down arrow keys: Move the tetromino
  • Up arrow key: Rotate the tetromino
  • Space: Hard drop tetromino
  • Shift/C: Swap with hold block
  • P: Pause the game
  • Q/Esc: Go back

Features to add

  • Create sprites for all objects
  • Add a hold block
  • Add a ghost block (the outline that shows the position of the piece if dropped)
  • Add a simple menu
  • Add an options menu
  • Add support for multiple resolutions
  • Add a pause menu
  • All done!

Third party tools

Acknowledgements

Lazy Foo's SDL tutorials have been extremely helpful, look into them if you are interested in low-level game programming or just want a framework to handle basic graphics for your C/C++ programs.

An Introduction to Modern CMake is great for learning the basics of CMake and avoiding bad practices.

Javier Lopez's Tetris tutorial was my initial inspiration for starting this project. I also use the same tricks he uses to make the management of the pieces and their rotations easier.

License

The source code is licensed under the MIT License. Note that the CMake find files and any fonts are NOT covered by the MIT license. They are distributed under seperate licenses that can be found in their respective folders. The Munro fonts are licensed under the SIL Open Font License.