This is my version of Tetris made in Java.
You can download it and modify it as you want. If you want to add more pieces to the game, there are instructions at the top of the Tetromino.java
You can also download the .jar file ready to play.
By the time I'm uploading the code the game is NOT complete.
Please, if you distribute the code or the code modified by you, give credit linking this original source.
- Add key to drop directly a key to the bottom
- Add key to change the tetromino and store it for later
- Make the player loose when he/she reaches the top of the board with a piece
- Make the tetromino shadow to see where it is going to fall
- Add sounds
- Add option to change the background
- Main menu
- Game screen
- Top scores screen
- Options screen
This is the Board matrix. Black squares will represent non block values and other colors will represent that value of the matrix is a block.
This is the Tetromino matrix. White squares represent no block and green squares represent blocks. Same matrix, for rotations for each Tetromino (except for the square).
The Tetromino matrix will fall over the Board matrix. When the Board detects if the falling Tetromino collides or not with a block inside it's matrix. If the collision is on the X axis, the board won't let the Tetromino move in that direction, but will continue falling. If the collision is on the Y axis, the Tetromino won't be able to move any more, as it happens in Tetris.
So we will have this situation:
The moment it reaches the bottom or it collides on Y axis with other block, the Tetromino matrix values get attached to the board matrix
When a row is full (no black squares, in out matrix will be no zeros) it is replaced by all black squares and the all blocks above will fall like if they have gravity, to the lowest block they can fall.
- C: Change Tetromino
- Up: Drop Tetromino to bottom
- Down: Drop Tetromino faster
- Right: Move Tetromino to the right
- Left: Move Tertomino to the left
- Space: Rotate Tetromino
- P: pause / resume