You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+51-26Lines changed: 51 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,18 +2,12 @@
2
2
3
3
A child-hood memory Tetris game built with Angular 10 and Akita.
4
4
5
-
Tetris was the first game that my dad bought to me. It costed him about 1 dollar at that time. It didn't sound a lot today, but at the time of more than 20 years ago. 1$ can feed my family for at least few days. Put it that way, 1$ can buy 2 dozens of eggs. This is the only one gaming "machine" that I ever had until my first computer arrived. I have never had a SNES or PS1 at home. I saw people still selling it online for about few bucks the other day.
6
-
7
-
Why not build the same with Angular? And here you go.
8
-
9
-
> I designed the game to hold maximum score of 999999 (one million minus one 😂) and I have never reached to that very end.
10
-
>
11
-
> I will give <u>a free gift</u> for the **first** amazing gamer. Please tweet your screenshot together with hashtag `angulartetris` and tag my name as well `@tuantrungvo`.
12
-
13
5
## Working Game
14
6
15
7
Check out the **working game** -> https://tetris.trungk18.com
16
8
9
+
The game has sounds, wear your 🎧 or turn on your 🔊 for a better experience.
10
+
17
11
![A child-hood memory Tetris game built with Angular 10 and Akita][demo]
18
12
19
13
If you like my work, feel free to:
@@ -25,42 +19,73 @@ Thanks a bunch for stopping by and supporting me!
Tetris was the first game that my dad bought to me and It costed about $1 US at that time. It didn't sound a lot today. But 20 years ago, 1$ can feed my family for at least few days. Put it that way, with 1\$ you can buy 2 dozens of eggs.
25
+
This is the only one gaming "machine" that I ever had until my first computer arrived. I have never had a SNES or PS1 at home.
26
+
27
+
My Tetris was exactly in the same yellow color and it was so big, running on 2 AA battery. It is how it looks.
28
+
29
+
![Retro Tetris][tetris]
30
+
31
+
Why not build the same <u>Tetris with Angular</u>? And here you go.
32
+
33
+
> I designed the game to hold maximum score of 999999 (one million minus one 😂) and I have never reached to that very end.
34
+
>
35
+
> I will give <u>a free gift</u> for the **first five** amazing gamer. Please tweet your screenshot together with hashtag `angulartetris` and tag my name as well `@tuantrungvo`.
36
+
28
37
## Who is this for?
29
38
30
39
I built this game dedicated to:
31
40
32
-
-Anyone tha grew up with Tetris as a part of your childhood. It was definitely my childhood memory and I hope you enjoy the game and it helps bring some good memory back to you as well.
33
-
- For Angular developer community, I have never really see a game that built with Angular and that's my answer. Using Akita as the underlying state management really helps me to see all of the data at a specific point of time, very good for debugging. I wanted to see more game from you guys.
41
+
-For anyone that grew up with Tetris as a part of your memory. It was definitely my childhood memory and I hope you enjoy the game as well.
42
+
- For Angular developer community, I have never really see a game that built with Angular and that's my answer. Using Akita as the underlying state management really helps me to see all of the data flow, it is great for debugging. I wanted to see more Angular game from you guys 💪💪💪
34
43
35
44
## How to play
36
45
37
-
### Control
46
+
### Before playing
38
47
39
-
- You can use both keyboard and mouse to play. But prefer to use keyboard
40
-
- Press arrow left and right to change the speed of the game (1 - 6)
41
-
- Press arrow up and down to change how many of lines has been filled before starting the game (1 - 10)
42
-
- Press Space to start the game
43
-
- Press P for pause/resume game
44
-
- Press R for reset the game
45
-
- Press S for the turn on/off music
48
+
- You can use both keyboard and mouse to play. But prefer to use <u>keyboard</u>
49
+
- Press arrow left and right to change the speed of the game **(1 - 6)**. The higher the number, the faster the piece will fall.
50
+
- Press arrow up and down to change how many of lines has been filled before starting the game **(1 - 10)**
51
+
- Press `Space` to start the game
52
+
- Press `P` for pause/resume game
53
+
- Press `R` for reset the game
54
+
- Press `S` for the turn on/off music
46
55
47
-
## Playing game
56
+
###Playing game
48
57
49
-
- Press Space make the piece drop quickly
50
-
- Press arrow left and right for moving left and right
51
-
- Press arrow up to rotate the piece
52
-
- Press arrow down to move a piece faster
58
+
- Press `Space` make the piece drop quickly
59
+
- Press `Arrow left` and `right` for moving left and right
60
+
- Press `Arrow up` to rotate the piece
61
+
- Press `Arrow down` to move a piece faster
53
62
54
63
## Techstack
55
64
56
65
I built it barely with Angular and Akita, no additional UI framework/library was required.
57
66
67
+
![Angular Tetris][techstack]
68
+
69
+
## Development Challenge
70
+
71
+
I got the inspiration from the same same but different [Tetris game built with Vue][vue]. To not reinvented the wheel, I started to look at Vue code and thought it would be very identical to Angular. But later one, I realized a few catches:
72
+
73
+
- The Vue source code was written few years ago with pure JS. I could find several problems that the complier didn't tell you. Such as giving `parseInt` a number. It is still working though, but I don't really like it.
74
+
- There was an extensively uses of `setTimeout` and `setInterval` for making animations. I rewrote all of the animation logic using RxJS. You will see the detail below.
75
+
- The brain of the game also used `setTimeout` for the game loop. It was not a problem, but I was having a <u>hard time</u> understanding the code on some essential elements: how to render the piece to the UI, how the calculation make senses with xy axis. In the end, I changed all of the logic to a proper OOP way using TypeScript class, based on [@chrum/ngx-tetris][ngx-tetris].
|[@Binaryify/vue-tetris][vue]| Vue Tetris, I reused part of HTML, CSS and static assets from that project |
82
+
|[@chrum/ngx-tetris][ngx-tetris]| A comprehensive core Tetris written with Angular, I reused part of that for the brain of the game. |
83
+
|[Game Development: Tetris in Angular][medium]| A detailed excellent article about how to built a complete Tetris game. I didn't check the code but I learned much more from the article |
84
+
|[Super Rotation System][srs]| A standard for how the piece behave. I didn't follow everything but it is good to know as wells |
0 commit comments