r/javascript • u/melcor76 • Dec 02 '19
Learning Modern JavaScript with Tetris
https://medium.com/@michael.karen/learning-modern-javascript-with-tetris-92d532bcd057?source=friends_link&sk=a7c22e45395da8322fc55bf3b23a309d5
u/gibran800 Dec 02 '19
Did you make that? It's awesome!!!
6
u/melcor76 Dec 02 '19
Thanks, have been writing and rewriting it for a while. Both the code and article. 😉
1
3
u/GroggyOtter Dec 03 '19
For anyone who wants to hear about the incredible history of Tetris, check out this YouTube video on it.
There's a reason the video for Tetris' history is almost an hour long.
I watched the entire thing and had zero regrets. Pretty damn well done.
2
u/melcor76 Dec 03 '19
Thanks for the tip!
I have been recommended that video before and forgot to watch it. Must do it tonight!
2
u/JSeling Dec 03 '19
This history also is interesting: The history of Tetris randomizers
1
u/melcor76 Dec 04 '19
Interesting!
I added the links to the end of my article.
Thinking of improving the randomizer now. :)
4
u/Bonteq Dec 03 '19 edited Dec 03 '19
I'm running into a bit of issue with this code snippet:
moves = {
[KEY.LEFT]: (p): => ({...p, x: p.x - 1}),
[KEY.RIGHT]: (p): => ({...p, x: p.x + 1}),
[KEY.UP]: (p): => ({...p, y: p.y + 1})
};It's giving me the error: SyntaxError: missing } after property list
The error goes away after deleting the above code. My IDE's are also not liking what's going on.
Mind going a bit more into detail on what is occurring there?
EDIT: Referenced your repo and found the issue, code should look like:
moves = {
[KEY.LEFT]: p => ({ ...p, x: p.x - 1}),
[KEY.RIGHT]: p => ({ ...p, x: p.x + 1}),
[KEY.UP]: p => ({ ...p, y: p.y + 1})
};2
u/melcor76 Dec 03 '19
Thanks, I updated the gist!
Basically what is happening is that we take the object p that we have, create a clone of it using the spread operator (...) and then change either the x or y coordinate.
1
u/Dielectric Dec 03 '19
Very clear and fun tutorial-this will be a great project to work through with my son.
1
u/melcor76 Dec 03 '19
Thanks!
The code in the repository works so if the code snippets in the article don't work then check there.
I'm going through the Gists and I forgot to remove this in some places after refactoring.
1
u/ConspicuouslyBland Dec 03 '19
Was looking into learning how to create games in javascript, your article is a good base to learn from.
I don't want to be a Karen about it but there are some things a bit confusing in your article.
Some files, like your css file aren't included in explanation of the project structure.
And the first constants aren't shown in a code block but in a text block with a grey background. This while it's code for your constants file. You use that text block for code on other parts too.
Sorry, I just couldn't let the Karen-opportunity go, I'll let myself out
1
u/melcor76 Dec 03 '19
Haha is that really a saying with Karen? :D
Yes, I intentionally didn't add everything in the structure but I see now that I should (just did).
Are you saying you want the gists everywhere? It takes a bit of work to add those to Medium so I usually let short code blocks be Medium code blocks (grey). I will update them when I get the time to avoid confusion.
3
3
1
1
0
13
u/mushikyto Dec 02 '19
I love it. Thank you