A basic implementation of Tetris in Python.
I originally wrote this in 2019, to learn the basics of pygame. The project was a little rushed, as I wanted to get a feel for how pygame works, and make something playable as soon as possible.
-
This game has been tested on Python 3.9, so having that version installed would be ideal. I have yet to test on other versions of Python.
-
Since pygame is used, make sure that you have the required pygame dependencies installed for your platform.
-
Dependencies are managed via Pipenv, so be sure to have it installed as well.
- I personally use pipx to install Pipenv.
Please see the controls on how to play.
These steps assume the requirements above
are met:
-
Clone this repository and change into the directory, if you haven't done so already:
# Cloning to ./Tetris isn't mandatory, just makes things a little easier git clone https://github.com/thepeoplescoder/python--Tetris Tetris cd Tetris
-
Set up the environment:
pipenv install
-
Run
main.py
inside of the repository (now pipenv environment):pipenv run python main.py
- Left and right arrows move the current block side to side
- Down arrow accelerates the current block downward
- Up arrow rotates the current block clockwise
- Shift+Up arrow rotates the current block counterclockwise
- P pauses/unpauses the game
- Lines clear with a randomized greyscale effect
- An area showing the next block to drop is displayed
- (it also rotates!)
- Grid fills with random colors on game over
- Next block area fills with random shades of purple on game over
- Codebase modifications
- Ultimately make the code more self-documenting
- Add an abstraction layer between pygame and the game logic to allow for the use of other graphics/game libraries, such as arcade
- "Beautify" the game a little bit more:
- Label the area that displays the next block.
- Display the score inside of the game window, instead of keeping track of it on the console.
- Display the number of cleared lines in the game window.
- Display the number of dropped blocks in the game window.
- Update the display when the game is paused, such that the player knows without a doubt that the game is paused.
- Bugs
- Levels advance (and therefore, speed increases) based on score, instead of on number of lines cleared.