Code-It-Yourself! Tetris - Programming from Scratch (Quick and Simple C++)

Поділитися
Вставка
  • Опубліковано 2 кві 2017
  • I mentioned in an earlier video that programming a Tetris clone is a good way to get going with programming as it makes you think about algorithms. Putting my money where my mouth is, I went ahead and did just that.
    GitHub: github.com/OneLoneCoder/Javid...
    / discord
    Blog: www.onelonecoder.com
  • Наука та технологія

КОМЕНТАРІ • 1,5 тис.

  • @javidx9
    @javidx9  4 роки тому +735

    lol, because I've answered this 200 times now, please ensure you have unicode enabled for your compiler. In VS, that's Project Properties -> General -> Character Set.

    • @tommy2nes
      @tommy2nes 4 роки тому +8

      I am compiling this from the command prompt using cl, I am having the same problems related to the unicode thing, do you know if there is a way to set this from the command line or will i have to use the IDE? thanks

    • @javidx9
      @javidx9  4 роки тому +20

      Just define UNICODE and _UNICODE with your compile command

    • @VictorPeraltaGomez
      @VictorPeraltaGomez 4 роки тому +31

      @@tommy2nes #ifndef UNICODE
      #define UNICODE
      #endif
      #ifndef _UNICODE
      #define _UNICODE
      #endif
      Before #include

    • @Torchl146
      @Torchl146 4 роки тому +6

      sorry if I ask another easy to answer often asked question, but how is this important?

    • @javidx9
      @javidx9  4 роки тому +37

      Its a good question. Simple answer is, not everyone uses a Latin alphabet. Regular character types and strings dont have enough precision to represent all languages. For hobby needs, this is less important, but professionally your customers might need additional language support. Its also easier to include from the beginning rather than engineer in later.

  • @OxygenMagnet
    @OxygenMagnet 6 років тому +2297

    "Totally unnecessary, but it looks cool" - everything i've ever programmed

    • @bigrafati1221
      @bigrafati1221 4 роки тому +14

      This comment made my day.

    • @SealedKiller
      @SealedKiller 4 роки тому +5

      So true

    • @tylermassey5431
      @tylermassey5431 4 роки тому +7

      Is it bad that I would have just said to hell with this "? 1 : 0" business and added the result of the bool directly?

    • @Anon_581
      @Anon_581 4 роки тому +4

      ​@@tylermassey5431 Nope! I was thinking exactly the same thing. In fact, bool to int conversion is implicit and is guaranteed to be 1 for true and 0 for false by the C++ standard (see the answers on stackoverflow.com/questions/5369770/bool-to-int-conversion).
      I guess the usage of the ternary operator was to be explicit about the assignment for readability purposes.

    • @toxicitzi357
      @toxicitzi357 4 роки тому +1

      If it looks cool on the screen, then it's most likely very necessary.

  • @bredmond812
    @bredmond812 4 роки тому +564

    Me: "I'm sick of long introductions on videos. Wastes my time."
    javidx9: "Hello! Let's make Tetris." *proceeds to begin tutorial*

    • @madhoshyagnik3679
      @madhoshyagnik3679 3 роки тому +7

      That was kinda cool, I appreciate such introductions.

    • @cboyslim5490
      @cboyslim5490 3 роки тому +2

      i agree. love this dude's videos even though i'm late to the party

    • @tractorman7733
      @tractorman7733 2 роки тому

      yeah, I just gotta love it when the intro is longer than the one little piece of info that I forgot when working on a project.

  • @sieyk
    @sieyk 4 роки тому +493

    12:27 "because I don't want this video to be half an hour long..."
    *looks at length of video*

    • @kuchigyz6231
      @kuchigyz6231 4 роки тому +6

      i'd like your comment but i don't want to ruin your likes number

    • @filmcase1683
      @filmcase1683 4 роки тому +5

      @@kuchigyz6231 Your too late... I'm sorry but your noble deed has gone unrecognised.

    • @inigo8740
      @inigo8740 4 роки тому +19

      It, *technically*, isn't half an hour long. It's longer.

    • @vaibhavagale7969
      @vaibhavagale7969 4 роки тому

      Its deserving.

    • @sieyk
      @sieyk 4 роки тому +2

      @@mykyta1235 it was a joke dude, chill

  • @KnutKelkeschoss
    @KnutKelkeschoss 5 років тому +791

    It's like watching Bob Ross using a keyboard instead of a brush - awesome!

    • @superslayerguy
      @superslayerguy 4 роки тому +11

      You hit the nail on the head

    • @dhananjaydeshmukh3469
      @dhananjaydeshmukh3469 4 роки тому +3

      Fucking a right

    • @DrummerJacob
      @DrummerJacob 4 роки тому +2

      This is one of those comments you wrote specifically so that the creator might read and like it.

    • @KnutKelkeschoss
      @KnutKelkeschoss 4 роки тому +12

      @@DrummerJacob I write all of my comments so that the content creators can read those... also, I write most my comments so that the content creators like those. Most of the times there are already sufficiently many they probably don't like, it's a Internet thing...

    • @javidx9
      @javidx9  4 роки тому +78

      And it was read, and liked! Thanks!

  • @waterjackattack2829
    @waterjackattack2829 4 роки тому +62

    If your output looks all wonky but you've followed his code 100% , it's probably that your default console window size is different. Open Command Prompt, right click the window, select properties, go to layout and you can see your window size. Then just change nScreenWidth/Height to the same values as your console window size.

    • @mr_noodler
      @mr_noodler Рік тому +2

      This is golden advice!! Thank you my screen was wonky!

    • @jasonli2400
      @jasonli2400 Рік тому +4

      For Windows11, you need to right-click and go to settings, then in the startup tab change the launch size

    • @federicosalvetti4286
      @federicosalvetti4286 4 місяці тому +1

      I love you

    • @rianlima7785
      @rianlima7785 3 місяці тому

      Thanks you

  • @BenoitAdam
    @BenoitAdam 4 роки тому +336

    00:00 Introduction
    01:34 Create Tetromino (Old Way)
    03:13 Create Tetromino (Algorythmic trick, may not work on slow systems due to usage of multiplication)
    03:30 Explanation by Drawing (rotation trick)
    07:24 Programming the function
    08:13 Playing Field
    09:18 Function (initialization)
    10:30 Game Loops
    12:45 Timing (Not all computer are the same)
    13:40 Collision Detection
    ===== 20:10 TEST N°1 =====
    == 20:10 GAME TIMING
    == 21:00 INPUT LOGIC
    == 22:00 GAME LOGIC
    ===== 23:07 TEST N°2 =====
    ===== 23:32 TEST N°3 =====
    23:52 C++ Optimisation
    24:30 Rotation
    ===== 24:49 TEST N°3 =====
    25:00 Rotation Hold
    26:10 Fall & Speed
    27:25 Force Piece down
    28:25 Block & Next Piece
    ===== 29:30 TEST N°4 =====
    ===== 31:55 TEST N°5 =====
    33:50 Increase Speed & Difficulty

    • @pby1000
      @pby1000 4 роки тому

      Benoit Adam We all appreciate it!

    • @chrissmith1152
      @chrissmith1152 4 роки тому

      thanks capt

    • @robz537
      @robz537 4 роки тому

      thx a lot

    • @sevenedus
      @sevenedus 4 роки тому

      God bless you

    • @SirGeldi
      @SirGeldi 4 роки тому

      Old Way is definitely faster on a C64 in BASIC.
      And pre-calculating is even faster but it consumes much more memory .

  • @JarmamStuff
    @JarmamStuff 5 років тому +43

    I've challenged myself to finally make "my own" app by, well, making Pong in C#, and I find myself revisiting this video constantly to get a sense of how to treat game logic, timing etc. Highly, highly inspirational stuff - you, sir, are a scholar and a gentleman.

    • @javidx9
      @javidx9  5 років тому +24

      Thank you Jarmam, you made a great decision to get stuck in and start coding, good luck!

  • @microtree5392
    @microtree5392 5 років тому +404

    7:03
    0°) i=wy + x
    90°) i=w(w-1) + y - wx
    180°) i= w^2 - 1 - wy - x
    270°) i= w - 1 - y +wx
    Don't mind me, just saving for future reference

  • @Lep_19
    @Lep_19 5 років тому +13

    I'm still blown away by that method of rotation. All other videos on this topic that I've seen have done some method of altering the order of the string (or array in some cases) itself, but reading the same string in different ways is such a clever workaround. I know I'm a little late to this one, but that doesn't mean it isn't still educational and impressive. Good stuff as always!

    • @javidx9
      @javidx9  5 років тому +7

      lol thanks Lep, I've solved many programming problems by turning the problem upside down, I hope seeing this helps the viewers understand there are many routes to the end result.

    • @YourAliasIsNotAvailable
      @YourAliasIsNotAvailable 3 роки тому

      The rotation with multidimensional array could also be done without changing the array itself.
      You just have to change the order in which you read the array.

  • @robertnurss6511
    @robertnurss6511 6 років тому +36

    Fantastic! Thanks Man! I'm going to sit down with my son and daughter to watch this and start game programming! I program a little (more coding than anything else) but my kids have been bugging me for years to show them game programming (which I know practically nothing about). Your explanations, descriptions of concepts, video and graphics are fascinating and all set to a perfectly watchable cadence. Watched several other videos you've posted ~ well done!

    • @javidx9
      @javidx9  6 років тому +11

      Hey thanks Robert, that's a really nice thing to say, and it's great to involve your family in the fun! Cheers!

  • @nomoturtle1788
    @nomoturtle1788 4 роки тому +42

    I had a problem at 12:25, the hash symbols were dispersed all over the console. Unless I've made a mistake, it seems that the nScreenWidth and Height don't affect the console window (though they probably should), but do affect the indexing we use. Setting nScreenWidth to 120 fixed the indexing for me and drew the right thing.
    You didn't mention including the libraries, so that caused me a lot of headache trying to find out why a function wouldn't work, looked at your github eventually though.
    Also the Scoring, it should probably be
    nScore += (1

    • @finesseandstyle
      @finesseandstyle 4 роки тому +2

      Thanks a lot you're a savior!

    • @CB66941
      @CB66941 4 роки тому +3

      Thanks man. I too had that same problem with the hash symbols everywhere.

    • @PeterParker-vn2hv
      @PeterParker-vn2hv 4 роки тому +2

      Thanks dude.

    • @Nick-lx4fo
      @Nick-lx4fo 3 роки тому +2

      Thanks, I was wondering why it did that.

    • @teroton2012
      @teroton2012 Рік тому +2

      For the window error, if you rescale the window with your mouse, it will also adjust that area and realign the grid

  • @daemyno
    @daemyno 5 років тому +46

    Your video was recommended by youtube, by curiosity i wanted to check it, i have nothing to do with C++ my stack is completely different, however, your simple way to explain and your behavior which is basically professional and friendly at the same time made you earn a new subscriber !
    I'm a big fan of you man :) keep it up

    • @javidx9
      @javidx9  5 років тому +2

      lol Daemyno, thanks man, that is much appreciated!

    • @jphvnet
      @jphvnet 4 роки тому

      Exactly, it is a C program. Nice to see how difficult I find my old (and natural) way of thinking in this code. Sometimes OOP sucks (imposible vectorization operations), but sometimes saves developer's mental health.

  • @Judderplush
    @Judderplush 5 років тому +70

    This video has made me realise how straight forward coding can be when it's explained in the correct way, thank you for this!

    • @javidx9
      @javidx9  5 років тому +16

      That's great to hear Corey, I appreciate the feedback!

  • @user-ov5nd1fb7s
    @user-ov5nd1fb7s 6 років тому +773

    There is something very cool about old-school developers. They tend do write simple code to solve complicated problems. These days, newer developers write complicated code to solve simple problems.

    • @purpleice2343
      @purpleice2343 5 років тому +106

      These videos are showing hobbyist projects which are then simplified further just so he can explain in as short amount of time as possible (he already needs over 30mins at the time to do so even when simplifying it), he writes simple code because writing simple code is how you show off an idea...
      It's not built nor is supposed to be robust, it's an example.
      We don't complicate it for fun, we think about what we will need to do with it 5 maybe 10 years later...
      You don't need to be old-school developer to write an example simple enough to get the point across, the problem is that bad developers think they can teach others and then shove their 3k LOC example that barely works when that could be 300 loc and have the same idea

    • @samriviera6299
      @samriviera6299 5 років тому +45

      There are so many developers out there, what do you even base your opinion on?

    • @jordixboy
      @jordixboy 5 років тому +29

      "Good Practices" "solid" "oop" "ddd" "hexagonal architecture", "Value Objects" "DTO's" "Patterns" "Anti-Patterns" ... these days over-engineering is completely fine...

    • @peterbonnema8913
      @peterbonnema8913 5 років тому +34

      @@jordixboy You are naming techniques, ideas and practices that are suitable, if not, absolutely mandatory for any bigger scale project. Specifically things like DDD, hexagonal architecture and value objects (and its companions entities and aggregates) were meant to make webscale architectures tracktable. So no, if you use those ideas in the way they were intended then that is not over-engineering. The definition of DDD even states when to use it's technical aspects and when not to.

    • @talkohavy
      @talkohavy 5 років тому +9

      So... machine-learning of today is trying to solve a simple problem?
      Please help me understand your wits and logic.

  • @jensborgmann2588
    @jensborgmann2588 5 років тому +1

    I stumbled across your Code-It-Yourself videos and as a IT teacher i must say that i really enjoy watching them. Great work !

  • @ScaerieTale
    @ScaerieTale 2 роки тому +5

    I started watching the RPG video in this playlist, and it referenced the platformer, so I started watching that. It referenced the Worms project, so I went back to that. And then I said "YOLO" and started from the beginning. I am *so* glad I did. This is amazing (and I learned how powerful arrays can be - bonus!). Thank you for these incredible videos :)

  • @BDCOMBO
    @BDCOMBO 4 роки тому +6

    absolutely love how friendly you are man, exceptional explanation skills too. Keep it up

  • @AustenValentine
    @AustenValentine 3 роки тому +2

    I love your channel. You have a lovely onscreen personality. One of these days, I'm going to start working through your tutorials. For now, I'm happy to watch you present it in a way that is both accessible and fun. I like how you comment your code to give the essential structure of what you're building - that is always the hardest part for me. Thank you for sharing such high quality content.

    • @javidx9
      @javidx9  3 роки тому

      Thank you Austen, thats very kind of you!

  • @setharnold9764
    @setharnold9764 3 роки тому +4

    Thanks for this, I spend all my time on mature systems, it's fun to see the starting point and how to step it along one feature at a time.

  • @LightLord1870
    @LightLord1870 6 років тому +3

    Just ran into this video, and your way of teaching and explanation is fantastic. Seen plenty of videos of programming and you really have something nice here.

    • @javidx9
      @javidx9  6 років тому

      Thanks LightLord, I appreciate that!

  • @TheBigupz
    @TheBigupz 6 років тому +32

    This is exactly what i was looking for, well explained simple to learn, and loads of great videos, keep it up, instantly subscribed

    • @javidx9
      @javidx9  6 років тому +1

      Thanks NutritiveApple, I hope you find some useful stuff!

    • @Torchl146
      @Torchl146 4 роки тому

      exactly what I'm thinking, thanks

  • @mr_noodler
    @mr_noodler Рік тому +1

    I did a code along to this, and got it working! What a thrill! I had a lot of fun. I like coding along while you are explaining things so I get a feel of how it works. Some of it made my brain numb but I suppose it's just part of learning. Great video! Thanks for making it, I learned a lot, especially about handles to the console window, cool stuff!

  • @jakewhiney2278
    @jakewhiney2278 Рік тому +1

    I've been looking for a fellow like you for months. Thank you for your content it'll help me rise from a basic understanding of programming to a practical tangible experience I've been looking for.

  • @mr-n0-aim42
    @mr-n0-aim42 4 роки тому +291

    Me: "I study Software Engineering, this schouldn't be to hard.... creats first Variable.. wtf is a wString ?" XD

    • @nonsudunk
      @nonsudunk 4 роки тому +46

      It's a W shaped String, duh

    • @thegardenofeatin5965
      @thegardenofeatin5965 4 роки тому +50

      Apparently it's a "wide" string, because though he failed to mention it, this tutorial is Unicode compliant. Just in case.

    • @inigo8740
      @inigo8740 4 роки тому +8

      @@thegardenofeatin5965 apparently it's because Windows.h requires wstring and wchar_t

    • @facelessn0mad
      @facelessn0mad 4 роки тому +4

      @@inigo8740 Thank heavens Linux does Unicode as UTF-8 :P

    • @ferry6700
      @ferry6700 3 роки тому +9

      Every body know w is stand for womboo , sly

  • @Kimchi_Studios
    @Kimchi_Studios 4 роки тому +3

    You are a fantastic teacher. What a great way to learn! I do micros in C but your videos are very helpful for anyone. Going to definitely try this out soon.

  • @weltvonalex
    @weltvonalex 4 роки тому +11

    the best intro in a long time, wow straight to the point an no long story how you spend your childhood with your dad on a lake playing tetris, thank you! thank you!

    • @javidx9
      @javidx9  4 роки тому +3

      Thanks weltvonalex, yeah, nobody wants that....

  • @HalValla01
    @HalValla01 4 роки тому +239

    javid: Because I don't want this video to be half an hour long..."
    Me: *but it is*

  • @Rraccd
    @Rraccd 6 років тому +3

    By far the best tutorial and not just for code but your very user friendly comments and explanations in the video and below. I am going to definitely recommend any new programmer to subscribe.

    • @javidx9
      @javidx9  6 років тому +1

      Hey Thanks D Rrac! That means a lot.

  • @SaifUlIslam-db1nu
    @SaifUlIslam-db1nu 5 років тому +2

    Will start binge watching this from today, after all, I've got a semester break from University. Your videos are helping me start and understand game programming in C++. Thank you for your efforts. :)

    • @javidx9
      @javidx9  5 років тому +1

      Good to hear Saif!

  • @TheCede555
    @TheCede555 3 місяці тому

    Thanks for the content! I'm very new to C++ and programming as a whole, and this was the perfect size to be finished in one sitting as well as being old enough to encourage some simple debugging! Had a blast working through it!

  • @gamesgarden8709
    @gamesgarden8709 Рік тому +3

    Nice one! I used for rotation another approach. To rotate any position (x, y) around center (0, 0) you can use formula x = y; y = -1 for CW rotation, and x = - y; y = x for CCW.

  • @khrissxander
    @khrissxander 5 років тому +9

    Top notch channel, excellent content.
    Keep up the great code teaching friend.

  • @alias4470
    @alias4470 5 років тому +1

    Amazing use of simplicity here. Also loved learning about the screen buffer and how that can be used to manipulate the window instead of CLS. Thanks a lot! You earned a sub

    • @javidx9
      @javidx9  5 років тому +1

      Hey thanks alias, much appreciated! Its a windows specific way of doing these things, but enables loads of fun for those starting out with programming.

    • @alias4470
      @alias4470 5 років тому

      javidx9 yep! Glad I use windows so I can have fun with your engine

  • @hitenterbecomeaprogrammer890
    @hitenterbecomeaprogrammer890 2 роки тому +1

    So cool, you explained it so easily, collisions are always a simple but important point when we develop these games, thank you for sharing.

  • @vaendryl
    @vaendryl 4 роки тому +105

    "Because I don't want this video to be half an hour long..."
    good thing it's only 36 minutes then.

  • @tw7522
    @tw7522 5 років тому +7

    The rotate function is absolutely great! I always had all possible rotations stored in my shapes array, but various addressing functions are absolutely ingenious way to solve this problem in a simple and elegant way!

  • @GodofWar1515
    @GodofWar1515 5 років тому +2

    Hey javidx9! Thanks for this great video. It’s good that you show that graphics is not the only important thing to focus on but also the mechanics and engine that run hidden within the code.

    • @javidx9
      @javidx9  5 років тому

      Hi Lucas, thanks man!

  • @romeo2473
    @romeo2473 4 роки тому +3

    pfew.. wish I had access to these videos back in my days when I started coding... Great job you do for teaching others!

  • @fettigeredgar
    @fettigeredgar 4 роки тому +6

    "Hello! Let's make tetris" is possibly the most efficient video introduction i've ever witnessed :D

  • @ComposingGloves
    @ComposingGloves 6 років тому +25

    Thank you so much for videos like these. They are immensely helpful and bridge the gap between beginner to advanced! If you ever need a sound guy for music for SFX give me a ring!
    I spent forever trying to understand how the print function worked but I couldn't seem to get it to work in another program I had written. I searched all over for an answer, and had given up but upon coming back I finally realized I had a < when I needed >
    Gotta love programming.

    • @javidx9
      @javidx9  6 років тому +4

      No problem Composing Gloves, programming certainly has its moments and frustrations! I might be looking at SFX in an upcoming video, so it would be interesting to hear your thoughts!

    • @BubLblckZ
      @BubLblckZ 5 років тому +2

      Composing Gloves "Because i dont want this video to be half an hour long" and its 36 min

  • @alexandergouddi3284
    @alexandergouddi3284 4 роки тому

    I am fairly new to coding and i also never used c++, i use python and right now i am exploring the dephts of JavaScript/html5 and css naturaly. Anyway i dont understand how people can downvote your tutorials... they are just perfect! you talk about alota important things i dont understand but thx too you i can google them and mostly they are important to me and my ambition. Just wanna say thank you for the great content and your way of teaching!

  • @AaronCMounts
    @AaronCMounts 3 роки тому

    I just finished walking through your tutorial, step by step and it worked! I had to make just a tiny amount of tweaks to make it work with C++ (changes to the way you wrote the 'sleep' lines), but it's incredible! It works exactly as advertised and it plays perfectly, too!

    • @rishabhgupta734
      @rishabhgupta734 2 роки тому

      I am facing the same issue , can you please post any link to the tweaked code?

    • @Ogrodnik95
      @Ogrodnik95 2 роки тому

      @@rishabhgupta734 using namespace std::chrono_literals; right above std::this_thread::sleep_for(50ms); should do the trick if you still need aid.
      still not sure how it works without that in vid and in file from github

    • @udaythakur7464
      @udaythakur7464 2 роки тому

      @@Ogrodnik95 I am still getting error , if u can please post your C++ code here...

    • @Ogrodnik95
      @Ogrodnik95 2 роки тому

      @@udaythakur7464 try: std::this_thread::sleep_for(std::chrono::milliseconds(50));

  • @megabrogames239
    @megabrogames239 6 років тому +7

    great video. I'm not using C++ but have learnt a good technique from you for how to make the blocks

    • @javidx9
      @javidx9  6 років тому +3

      Thanks MegaBro, glad the video was useful!

  • @andrii1701
    @andrii1701 5 років тому +29

    Original Tetris was written in the command promprt as well but it was using double ▓ bars instead of alphanumeric chars.

  • @0x9f000
    @0x9f000 Рік тому +2

    6 Years Later and You Still Reply to Comments, how admirable. thank you for your hard work. I plan to follow most of the "Do-It-Yourself" Series because I want to try and make a 3D Voxel Game with c++ and think they would help.

    • @javidx9
      @javidx9  Рік тому +1

      Hey Cheers Mason! My videos will cover the basics of the techniques involved but to get the performance you might need will require some GPU help.

    • @iamrysheem
      @iamrysheem Рік тому

      @@javidx9 this is actually very impressive that you still reply to old videos. It's new to somebody everyday.

  • @DimitriSabadie
    @DimitriSabadie 3 роки тому

    The ternary expressions inlined to prevent having to write an if made my day. What a brilliant amount of obfuscation. Thanks :D

  • @lukenukem8028
    @lukenukem8028 3 роки тому +3

    [12:25] - When mine prints, I get three single-spaced gapped buckets side-by-side with 28 spaces between the buckets.
    The 1st and 3rd on the same level and the 3rd with the bucket bottom.
    ~The funny thing is, even when I copy and paste your raw code from GitHub, I still get the same three gapped buckets split apart.

    • @lukenukem8028
      @lukenukem8028 3 роки тому

      What I also notice is, the console window doesn't change size like yours does.
      Mine stays at 120x30 despite your 80x30 code.
      How can there be entirely different outcomes from identical raw code???!

    • @lukenukem8028
      @lukenukem8028 3 роки тому

      I have to manually change the console window to 80x30 in the console window properties for it to work.
      Why don't we invoke a function that changes the actual size to our screen size variables? Like in C#.
      Also, changing the window size destroys it, and it doesn't go back to normal.

    • @Meatbrick
      @Meatbrick 2 роки тому

      I wish this would get more attention, or at least an answer.

    • @javidx9
      @javidx9  2 роки тому

      See "Introducing ConsoleGameE gine" and/or any of the next 50 videos or so.

  • @derpythecate6842
    @derpythecate6842 3 роки тому +2

    Funny thing you should mention about too many people doing things about graphics but not about engines.
    I was finding a tutorial on how to make a simple tetris that I could run in my linux terminal for decoration, and wanted to implement something lightweight using ascii like what you did in the video.
    What a serendipitous find!

  • @ralphm786
    @ralphm786 5 років тому +2

    Great tutorial. As simple as possible, but no simpler. Who knew programming Tetris could be so easy?

  • @goldensnitch1614
    @goldensnitch1614 2 роки тому

    right away to the tutorial without any unnecessary intro, love it, subbed

  • @elijahasefa389
    @elijahasefa389 3 роки тому +3

    Javid is the type of guy to have invented the personal computer if he was born in the right place and time. Amazing work.

  • @Komplexitet
    @Komplexitet 4 роки тому +12

    0:37 I like to make ASCII-games and this is really accurate to how everyone is reacting in the beginning.

  • @stupossibleify
    @stupossibleify 5 років тому +2

    Late to the party, but your videos are excellent! Thank you for all the effort you put in and love to see a bit of Vimto on the TV

  • @michaeltennant8312
    @michaeltennant8312 3 роки тому +15

    If you are having issues with the window size you can correct it to the right size with this in the main block before the game loop:
    // Resize window
    HWND hwnd = GetConsoleWindow();
    if (hwnd != NULL)
    {
    MoveWindow(hwnd, 200, 200, 680, 400, TRUE);
    }

  • @twitchEmailOkay
    @twitchEmailOkay 9 місяців тому

    hey this guys pretty good! a lot of entertainment youtubers get comments like "thanks this helps me" but you are actually helping me to sustain my livelihood. Thank you

  • @BrekMartin
    @BrekMartin 7 років тому +124

    What beginner programmers should be watching, but apparently aren't. Interesting... I think I rotated the pieces within their arrays, so the array content changed.

    • @BrekMartin
      @BrekMartin 7 років тому +1

      I'll have to look again now :D not sure you can do that without destroying it.

    • @javidx9
      @javidx9  7 років тому +11

      +Brek Martin thanks for the compliment! Rotating in the array is just as valid. I think the centre of rotation changes per piece in proper Tetris. That's a bit more fiddly though.

    • @BrekMartin
      @BrekMartin 7 років тому +4

      javidx9 I've looked again. This was in 2010, so it's vague! I copped out and defined all rotated shape combinations in a table, but I let myself off the hook because I rotated digits to display the score, the same way you rotate tetris bricks (for portrait display) :D

    • @javidx9
      @javidx9  7 років тому +5

      NIce! I hate looking at code from years ago. Firstly I can barely remember it and obviously I wrote loads of documentation, and secondly, it always looks so inexperienced compared to now. lol. I guess I'll feel the same in 10 years time looking back at these videos.

    • @BrekMartin
      @BrekMartin 7 років тому

      I did it again over two nights :) Bored of the actual game already :D It looks like you expanded the well array to include borders made of set bricks, which I should have done. Checking the borders takes extra code, but the borders included in the well array would be checked naturally with the normal shape collision function. What it appears we both forgot, or maybe you just didn’t want to... I think the well needs a couple of off screen rows to spawn the new shapes to, so they don’t suddenly, and unfairly appear at the top of the well. I did borrow your idea of using values for the brick elements that relate to the shape that each brick came from. It makes the game ready for a colour platform, even if it isn’t running on one.

  • @Huguillon
    @Huguillon 5 років тому +3

    This is the best channel I suscribed in 2018

    • @javidx9
      @javidx9  5 років тому

      Aww, thanks Guillermo!

  • @adamodimattia
    @adamodimattia 4 роки тому +1

    Super cool stuff, the most awesome way to learn C++, practical examples and great training for games.

  • @raztaz826
    @raztaz826 3 роки тому

    Just finished following this. Incredible how good a game can be made with so little code

  • @onuberonly7846
    @onuberonly7846 6 років тому +3

    Thank you Dude! you are an inspiration to intermediate programmers like me. I love this console stuff - The rawness - The unabashed purity of it !!

    • @javidx9
      @javidx9  6 років тому +1

      lol, thanks K Parks, the console is a great and underestimated vehicle for learning even advanced topics!

  • @silverstringsgia-tj9fe
    @silverstringsgia-tj9fe 4 роки тому +93

    next video: How to program Witcher 3

  • @sourcecode6467
    @sourcecode6467 4 роки тому

    Thoroughly enjoyed this. Doing it in the CLI is somewhat beautiful. Codebase is spot on. New sub here

  • @metenrog
    @metenrog 3 роки тому

    I have been looking for something like this forever. Thank you!

  • @rockinpenguin
    @rockinpenguin 4 роки тому +5

    0:38 no... my reaction was actually COOOOL ! Thats perfect for the video : who cares about graphics, as you better get the logic down first...

  • @neuemage
    @neuemage 6 років тому +19

    Wish I had youtube growing up, if you wanted to see programmers code you had to go to a lab and hope they allow you to hang out

  • @anonanon3066
    @anonanon3066 4 роки тому

    Great video!
    This might seem like the novice criticizing the master, but regarding timers i would always write the condition like this:
    timer >= timeToWait
    One ram glitch that causes timer to get incremented by 2 instead of 1 at the last tick and the game soft locks this timer. But if you use >= it will always work without false positives.

  • @everything_programming7096
    @everything_programming7096 3 роки тому

    This is totally a great idea. Trying to increase my portfolio of games and programming projects ontop of my youtube tutorials. Thank you for the very insightful video

  • @xtetn4888
    @xtetn4888 3 роки тому +6

    If you ask google to define a programmer, his face will show up. Love the tutorial man!

  • @zekezandbergen4435
    @zekezandbergen4435 6 років тому +19

    "I don't want this video to be half an hour long" Video is 36 minutes. Teasing aside, nice video and clean code.

    • @javidx9
      @javidx9  6 років тому +4

      Hey thanks Zeke, yeah I learned a lesson there! There's very little planning on this channel. Pleased you enjoyed it though!

  • @FullassDear
    @FullassDear 2 роки тому +2

    Hello, javidx9! Thank you for your videos, it's a pleasure to see and grasp these magic ( at least magic for me) tricks. I am in tears of joy with your r % 4 solution in rotation, I wouldn't ever thought of it. Feel like a mage aspirant really.

    • @javidx9
      @javidx9  2 роки тому

      Thanks, lol, Im pleased youve found it useful :D

  • @recondito
    @recondito 5 років тому +1

    Dude you impress me. I consider myself a new programmer because I really haven't written some serious code. Currently watching this because I have to make a tetris for a college presentation, but I have to do it in SDL. However you caught my attention when I saw your thumbnail.
    Really nice video. Liked and subscribed.

    • @javidx9
      @javidx9  5 років тому +1

      Hey thanks Chico, that's very kind of you! Good luck with your project!

    • @recondito
      @recondito 5 років тому

      Thanks mate.

  • @uuu12343
    @uuu12343 5 років тому +5

    This is exceptional as usual
    Also - i finally completed my dream of making tetris for fun
    Oh, you should do more videos on c++ without the use of the olc engine

    • @javidx9
      @javidx9  5 років тому +1

      Thanks Eternia, I occasionally dont use the olc engines. Ive a series planned later this year which might not use them, we'll see...

    • @uuu12343
      @uuu12343 5 років тому

      @@javidx9
      Many thanks, looking forward to learn more pure c++ tutorials!

  • @raul_castro
    @raul_castro 4 роки тому +3

    you got one more subscriber, excelent videos

  • @UrThysis
    @UrThysis 5 років тому +2

    Yessss I've been looking for something like this for a while...great video , thankssss it was mega useful

    • @javidx9
      @javidx9  5 років тому +2

      You're welcome and thanks Samuel!

  • @FractalMannequin
    @FractalMannequin 3 роки тому

    I like your videos because I can simply open my editor and write stuff right away. This is how teaching should be done.

  • @jakubstastny1327
    @jakubstastny1327 4 роки тому +3

    When you are so good in programming, that you can make cool games that run on command line.

  • @PhilBoswell
    @PhilBoswell 6 років тому +5

    I wonder whether this might be a candidate for updating to use your nifty framework?
    Also, might it be an interesting exercise to encapsulate the Tetromino logic into a class?

    • @javidx9
      @javidx9  6 років тому

      Hi Phil, I've deliberately left this and FPS #1 out of olcCGE. Mainly because I did them before I created olcCGE, but also they make great exercises for other people to have a go at, which you may not be surprised is something people ask me about a fair bit!

  • @csfinch7672
    @csfinch7672 4 роки тому +1

    This was fun!!! I'm glad I found your channel. Just subscribed!!!!

  • @yaelao3337
    @yaelao3337 4 роки тому

    Subscribed, just amazing work, keep going!!! So much you can teach!

  • @mortkebab2849
    @mortkebab2849 4 роки тому +5

    I'm finding that there's way too many dependency errors when trying to get this to compile on my mingw setup. I think what I'll do is to limit my use of VS Code just for Python (which I use most of the time in my projects) and reinstall a fresh copy of Visual Studio with just the options needed (since there are so many, that was a learning curve the first time around) to develop in C++.

  • @NightpireVideos
    @NightpireVideos 6 років тому +4

    Great video man

    • @javidx9
      @javidx9  6 років тому

      Cheers Nightpire!

  • @egw4924
    @egw4924 4 роки тому +1

    I've subbed because of the simple but very effective intro!

  • @NOWG0015
    @NOWG0015 4 роки тому +1

    Why am I just now discovering this channel. Love this video.

  • @randairp
    @randairp 5 років тому +3

    24:18 You don't need the conditional 1 or 0 since bools already evaluate to that. This IS C++ after all ;-)

  • @TheRealFaceyNeck
    @TheRealFaceyNeck 5 років тому +5

    I'm in a C++ class right now. I'm not doing well on the course material, but I'm getting a lot out of your videos!
    Thanks, mate. 7 mins into this video and I've already learned more than I believe I will learn in a half hour during my class this morning. Shit, I should probably hop in the shower... ah, a few more mins on this Tetris project......

  • @pby1000
    @pby1000 4 роки тому +2

    Great idea to show us the program before starting the lesson. Subscribed!

  • @shinichikudo8632
    @shinichikudo8632 4 роки тому +1

    You are that kind of guy I am confident with that you'll solve my broken internet connection once I call the hotline.

  • @yohohohowo
    @yohohohowo 2 роки тому +2

    First time using visual studio and coding in C++. Video was a little quick for following along but the explanation of the rotation algorithm and all the whiteboard stuff was the highlight for me. I ended up copy pasting the code and actually learned a lot by figuring out how to display lines and Level up each ten lines, changed speed increase to level and managed to show next piece. Toughest part was clearing the characters when next piece changes. I was really stumped by the score code till I figured out that

    • @javidx9
      @javidx9  2 роки тому

      I'm pleased you've found it useful! I would use PGE for everything, and the CGE videos can be very easily implemented in PGE.

  • @jakebrowning2373
    @jakebrowning2373 4 роки тому +5

    Some pieces in NES Tetris, and presumably others, spin around units in the piece though, like the L J T I (Z and S?), so this system of rotating would be slightly different I guess

  • @chastitywhiterose
    @chastitywhiterose 9 місяців тому

    5 minutes in and you are showing the exact formula I used in my Tetris game. In my case it was a[x+y*width]

  • @maxgomes92
    @maxgomes92 3 роки тому +1

    This rotation technique is beautiful.

  • @sarlevdiz
    @sarlevdiz 6 років тому +3

    Hi Javidx9. Thanks for your tutorials. I am MacOS user. Is there possibility to run (or adopt) this code for my os?

    • @javidx9
      @javidx9  6 років тому +1

      Hi Имя Фамилие, thanks for the feedback. There are members of this community who have worked on Linux variants, using aalib and or ncurses. Performance has been variable. For programs like Tetris I'm sure there must be a simple way for your OS, but perhaps not for some of the more demanding programs. I too am currently exploring a Linux port of the code which may be available later this year.
      There has also been an SDL port of some of the code. I can't get to the link right now but I'll follow up when at my machine.

    • @sarlevdiz
      @sarlevdiz 6 років тому

      Thanks Javidx9!

  • @nicolaspino9533
    @nicolaspino9533 5 років тому +3

    Hello javidx9, I'm a beginner C++ programmer and have some questions regarding how some parts of the code are working. I will try to explain myself the best I can, as I don't know the technical names for stuff.
    When using the following sentence:
    'for (int k = 0; k < 4; k++)
    bKey[k] = (0x8000 & GetAsyncKeyState((unsigned char)("\x27\x25\x28Z"[k]))) != 0'
    How is the array positioning to take x27, x25 and x28Z (Hexadecimal values for the keys?) respectively when it is only doing 4 loops, meaning only the first 4 characters of the string can be returned (\, x, 2 and 7?) From what I researched, the backlash is playing a factor on how the string gets interpreted, something about literals I believe. When iterating thru an string, does the backlash "encapsulates" a position?
    I saw your video "8-bits of c++ code you should know" and the bit 7 explained about constant arrays. Is this the same thing? On this video you called it 'constant string expression'. Which one is the actual name? I'm trying to look it up on the internet so I can learn more about how it works but I can't find anything similar to what you show.
    I apologize if these are dumb questions.

    • @javidx9
      @javidx9  5 років тому +3

      Hi Nick, no such thing as stupid question! The \x is an "escape character" which tells the compiler to treat the next group of digits as a single hexadecimal number. This means in reality that the string is only 4 characters long once it is compiled. You are correct assuming those codes represent the arrow keys. Im unsure of the naming convention for using a string as an array in this instance, but it is certainly a constant array of characters, therefore a constant string.

  • @guithegood87
    @guithegood87 4 роки тому +1

    Loved this. I'm just a beginner but seem this made so excited!

  • @tomay3000
    @tomay3000 4 роки тому +2

    Good gaming start tutorial. And I like your C++ coding style BTW ;)

  • @stec9524
    @stec9524 4 роки тому +6

    Well done, Gilfoyle!

  • @Democracyphobia
    @Democracyphobia 4 роки тому +5

    There is a huge difference between old-school programmers and the new generation .the new generation programmers are high attention show off kids with one single mission to prove to themselves and others that they are smarter then anyone else .I just code as a hobby and man some people in forums made me think that programming actually cause mental issues due to how toxic they are . We need more chill mature people like this man in this world .

  • @dennisanderson8663
    @dennisanderson8663 4 роки тому +1

    I also did a Tetris clone for my first game without tutorials. I figured the easiest method would be to store the playing field and the pieces in a multidimensional array aka a matrix. Then it was just a matter of figuring out an algorithm to rotate the matrices 90 degrees left & right.

  • @slavocherepov2927
    @slavocherepov2927 3 роки тому +1

    Thank YOU!! Excellent instruction, right in the hot water with all the help to swim. I'm a novice programmer with basic web javascript knowledge, and I've just made this work on my PC ... Aug 2020. Thank you

    • @javidx9
      @javidx9  3 роки тому

      Hey thats cool and thanks Slavo! Taking the leap from JS to C++ will certainly be worth it!