A simple tetris game built using RxJS, Javascript and TypeScript
Demo here
![Screenshot 2023-11-28 at 1 09 32 AM](https://private-user-images.githubusercontent.com/77480421/285952735-28ad51af-2553-4d30-b2d2-647dd0b091ee.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ2NzI4NjQsIm5iZiI6MTcyNDY3MjU2NCwicGF0aCI6Ii83NzQ4MDQyMS8yODU5NTI3MzUtMjhhZDUxYWYtMjU1My00ZDMwLWIyZDItNjQ3ZGQwYjA5MWVlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI2VDExNDI0NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTAyZTEyYTg4YzNjOTlhN2M5YThlODA2ZmMwNTk2YTVkOGM1ZTAzZjQ4MTU1YWEyODlkYWE5NjRmZTY1MjhmMGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.zrKAgOiHNpRXWd-9awQdmIE1Fmw7Mul7GpgANEszdXI)
Setup (requires node.js):
> npm install
Serve up the App (and ctrl-click the URL that appears in the console)
> npm run dev
Cube
is a 1x1 object
Block
is an object made up of 4 cubes in any tetris shape
Rotation
system used is a Super Rotation System (SRS) where it is possible to rotate a block 90 degrees clockwise or anticlockwise
constants.ts
: contains constants used in the gamegame.ts
: contains the game logictypes.ts
: contains the types used in the gameobservables.ts
: sets up the observables used in the gamegenerics.ts
contains generic functions that can be used anywhere where the types are relevantviews.ts
: contains the functions that render the gameshapes.ts
: contains the functions that generate the various tetris shaped blocksutil.ts
: contains utility function(s)main.ts
: contains the main function that runs the game loop
- The game is over when a block reaches the top of the game board
- 100 points are awarded for each row cleared
- The game speed increases after reaching 200 score
- The game restarts automatically after showing game over box briefly
- Highscore is tracked until page is refreshed
factors like game speed, difficulty based on score, scoring etc. can be tweaked in the constants.ts file
A
button: Move block leftD
button: Move block rightS
button: Move block downH
button: Hold the block (more on this in Report)E
button: Rotate block clockwiseQ
button: Rotate block anti-clockwiseR
button: Restart game