This game is made of python3 and pygame.
Install via pip:
$ pip install git+git://github.com/mozartilize/tetris.git
Then run it in terminal to play:
$ tetris
↑ - Rotate shape
→ - Move shape to right
← - Move shape to left
↓ - Go down faster
F9 - Pause
This repo is built upon this pygame tutorial.
The original_tetris.py
source code is credit to the tutorial.
-
This game is an improvement from the tutorial which reduces CPU usage from 22% to 8% (tested on my computer) by:
- Change logic for
check_lost
which only check for positions of the latest shape. - Reduce for loop in grid by tracking grid's available positions used in
valid_space
andgrid#update
. - Draw only changed parts on pygame's surface.
- Take advantage of python's generator.
- And some other minor optimizations.
- Change logic for
-
Game pause was added.