Welcome to this simple rendition of the classic Tetris game, built using Python and the pygame library.
Tetris is a tile-matching puzzle game. The objective is to manipulate the falling tetrominoes, which move downwards one space at a time, in order to create a horizontal line without gaps. When such a line is created, it disappears, and any tetrominoes above move down. The game ends if the playing field is filled. The goal is to achieve the highest score possible.
- Left and Right Arrow Keys: Shifts the tetrominoes left or right.
- Up Arrow Key: Rotates the tetrominoes.
- Down Arrow Key: Drops the tetrominoes into place.
For those interested in learning how the game is coded, here's a brief explanation of the main components:
This is where the game's main functionalities are looped through, handling user input, updating game state, and rendering the game.
pygame.event.get()
: Collects all the events that happen during the game, like pressing keys or clicking the mouse.self.game.run()
: Runs the game logic.self.score.run()
: Updates the score.self.preview.run(self.next_shapes)
: Shows a preview of the next shape.
This class manages the logic for moving the tetrominoes, checking for collisions, and clearing lines.
Manages the player's score, based on the number of lines cleared.
Shows the next shape(s) that will fall.
-
Clone or download this repository.
Open a terminal and navigate to the location where you want to save the file.
Then run:
git clone https://github.com/MrStealYoCurls/PyTetris.git
-
Install the Pygame library using:
pip install pygame-ce
pip3 install pygame-ce
-
Navigate to the directory and run the game script.
python PyTetris.py
python3 PyTetris.py
-
Enjoy and try to beat your high score!