How To Code The Snake Game In Javascript

Поделиться
HTML-код
  • Опубликовано: 1 июн 2020
  • 🚨 IMPORTANT:
    Land A Job With Remote.work: remote.work/?Web%2...
    In this video I show you how to build the classic snake game using pure JavaScript. That means we will use no libraries or frameworks at all. We won't even need to use canvas in this tutorial since CSS grid makes working with snake incredibly easy.
    📚 Materials/References:
    GitHub Code: github.com/WebDevSimplified/J...
    🧠 Concepts Covered:
    - How to create a game loop
    - How to position elements in a CSS grid
    - Best practices for game development
    - Best practices for breaking up large files
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    #SnakeGame #WDS #JavaScript

Комментарии • 559

  • @maskman4821
    @maskman4821 4 года назад +89

    This is exactly what I am expecting ~ a snake game with pure html, css, javascript instead of using canvas API. Kyle is trully a vanilla html, css, js master !!!

  • @nsharma4981
    @nsharma4981 4 года назад +145

    Hey Kyle, before I watch the video (and after I've liked it) I just wanna tell you HOW GRATEFUL I am to you for all your awesome videos. Your teaching pace suits my learning style to the T, you are concise yet amazingly clear and easy to follow, you do not waste time in useless banter but you are also not at all boring as your love for what you do shows, and you come across as a pleasant (looks wise too!), polite and genuinely nice guy. I started learning front end last month on a whim and was enjoying it a lot, but you have made this journey even better. In fact, I am so hooked to your videos, that while my friends watch Netflix, I learn and simultaneously entertain myself watching you, lol! Though I'm not in a position to buy any of your courses, I make sure to play through all the ads in your videos, hoping to express some of my gratitude that way. You are my favorite person on the net and I hope your channel grows infinitely. God bless you!

    • @WebDevSimplified
      @WebDevSimplified  4 года назад +31

      Thank you so much! You are far too kind to me. I am really glad you enjoy my teaching style.

    • @techtipsuk
      @techtipsuk 4 года назад +1

      Well said

    • @maskman4821
      @maskman4821 4 года назад +1

      I am deeply touched, your words make me cry ...

    • @Pdxron
      @Pdxron 3 года назад +1

      is this your school project?

    • @kyle6754
      @kyle6754 2 года назад

      This person hit the nail on the head so to speak. I've been really enjoying his videos and I'll probably be checking out his courses soon.

  • @flingflang69
    @flingflang69 3 года назад +32

    Even though I copied your code exactly, as a beginner, it's extremely satisfying getting this right. Thanks for being the teacher of my first coding project.

  • @sharmashivanand
    @sharmashivanand 4 года назад +4

    Had been looking for a beginner friendly gaming tutorial. This is an excellent tutorial for getting started with game development. So much to learn, explained in extremely simple terms while polishing js skills.

  • @mrahamed5985
    @mrahamed5985 4 года назад +17

    This is the channel where i always Learn with joy.

  • @fionat.6411
    @fionat.6411 4 года назад +32

    Hey Kyle! Nice video :)
    I happened to develop snake myself a week ago and I think the movement of the snake is much easier when you:
    - delete the last body part (except for when the snake ate some food)
    - add a new body part in the direction your snake is heading to
    This way you can simply ignore everything in between.

    • @WebDevSimplified
      @WebDevSimplified  4 года назад +14

      That is a really smart way to think about the problem!

    • @maskman4821
      @maskman4821 4 года назад +1

      yeah you are so right, this approach is what everybody use, get rid of tail, add new part in same direction, we don't need to consider body !!!

    • @whoman7930
      @whoman7930 4 года назад +1

      This is what I also did!

    • @DannyHille
      @DannyHille 3 года назад

      yes just keep track of the x,y of the head, then body.push(head), while(body.length>snake_length)body.shift()

    • @jaykay7932
      @jaykay7932 2 года назад

      as the old saying goes KISS - keep it simple stupid!

  • @medhashree2416
    @medhashree2416 4 года назад +10

    I m totally enjoying your lessons . Thank you for this wonderful series of knowledge 😊

  • @mbouweeric2512
    @mbouweeric2512 4 года назад +5

    Excellent! clean code and a nice explanation. You are doing great work with your videos, thank you so much for that Kyle.

  • @Maxtasy888
    @Maxtasy888 4 года назад +10

    Another great video Kyle. I already did Snake with Canvas, but I learned so many new things in this tutorial. Like how to organize functions for each different part of the game in their own files.

  • @goldfinch5522
    @goldfinch5522 4 года назад

    before I watch the video I want to tell you how much I appreciate what you do on RUclips .. really impressive

  • @madeyeatreides4055
    @madeyeatreides4055 4 года назад +7

    Dude you’re like a mind reader or something thank you this is just what I needed

  • @asimkoirala8074
    @asimkoirala8074 2 года назад

    Woah! I has watched a video on the same topic a few weeks back but failed. Your way made me clearly understand all the steps you did, especially the module method you used made it far easier to understand. Thank you, Kyle.

  • @___Kevin
    @___Kevin 2 года назад

    Hi, I've just completed your tutorial and it works fine.
    Thank you very much for the time you take to explain each function in a very instructive way + you made it very easy to follow/enjoyable

  • @shobhitpreetamsahoo4267
    @shobhitpreetamsahoo4267 3 года назад

    Thanks Kyle, your tutorials are really great. Appreciated man. Learned a lot today.

  • @asherintech
    @asherintech 4 года назад

    Thanks for this Kyle! You're videos are always top notch, keep it up :)

  • @caseymccray3861
    @caseymccray3861 4 года назад +1

    You code so well. I'm so impressed.

  • @clairecontemporary
    @clairecontemporary 2 года назад

    wow excellent and fluent explaination without redundants , this is so impressive

  • @hasanal-haddad8016
    @hasanal-haddad8016 4 года назад +13

    in this video, i learned about how
    - RequestAnimationFrame works
    - js module(import and export)
    thx kyle..

  • @Aniket5224
    @Aniket5224 3 года назад

    Amazing video. This is first time I created a game and it was just so simple thanks to all of your explanations.I also like how to discuss each approach and fix issues on the go.I am definitely subscribing to you channel.Keep it up.

  • @kikevanegazz325
    @kikevanegazz325 Год назад

    Brother, you deserve a medal for this video-tutorial. Everything was well explained, smooth, clear, and connected. Great job!

  • @shreymehrotra5408
    @shreymehrotra5408 3 года назад +2

    Amazing!!!!!! Very helpful tutorial...you are such a hardworking guy. :)

  • @OnlineTutorialsYT
    @OnlineTutorialsYT 4 года назад +84

    1:30 Wow....its really amazing

    • @WebDevSimplified
      @WebDevSimplified  4 года назад +8

      Thanks!

    • @OnlineTutorialsYT
      @OnlineTutorialsYT 4 года назад +6

      Welcome bro :)

    • @dnynu
      @dnynu 4 года назад +6

      I have been watching your videos since March 2020 & i think I gained some knowledge about html,css,js to come into the web development.
      This two channels are just awesome
      Keep growing keep teaching us
      Thanks for all your suggestions that helps us alot.
      Html,css - online tutorials
      JS - web dev simplified

    • @LabaranLabs
      @LabaranLabs 4 года назад +3

      sure i agree

    • @dnynu
      @dnynu 4 года назад +2

      @Dev Ed ko kaise bhul sakte hai 🔥👍

  • @colbyryan6884
    @colbyryan6884 2 года назад

    Awesome video! Great practice for people learning javascript but wanting to branch into things that aren't normally touched on in front end website type courses.

  • @Al_Gonzo
    @Al_Gonzo 4 года назад +14

    I love that every of his projects teach something new. This time I've learned:
    RequestAnimationFrame
    How grid can work in a video game
    How to have a cleaner structure with export & import

    • @harag9
      @harag9 4 года назад +1

      Now go and learn OOP / Classes and make it a better structure. It's a great starting point for new developers.

    • @tyrrelldavis9919
      @tyrrelldavis9919 4 года назад +1

      JavaScript technically doesn't need semicolons , whole code has no semicolons
      I do this too when I've been working with python then go back to JS

  • @RameenFallschirmjager
    @RameenFallschirmjager 4 года назад +3

    Your voice has become so deep! I thought you said hello darkness my friend at first!😂

  • @alissonarboleda9493
    @alissonarboleda9493 2 года назад

    Thank you, I am just learning and even though I was only able to copy the code it this was sooo helpful!

  • @jospichal1872
    @jospichal1872 2 года назад

    Hey man what an awesome video!
    Thank you so mutch from Italy ;)

  • @bernardozelaya2685
    @bernardozelaya2685 3 года назад

    Hi...im from Argentina and I'm an amateur on this...really really is impressive how you teach to code. Really good, thanks for sharing your knowledge !!

  • @pleasurface
    @pleasurface 3 года назад

    Wow, this tutorial is awesome! Thank you so much

  • @kengthe5949
    @kengthe5949 4 года назад

    you're doing an incredible job! thank you :)

  • @mounir101
    @mounir101 4 года назад

    The video was great! I liked it. Thanks so much.

  • @kevklash
    @kevklash 4 года назад +5

    Amazing! Pretty well explained, it has been really useful. This is why I love this channel, thanks for sharing.

  • @enochlin2567
    @enochlin2567 3 года назад

    Mind Blown. Thanks Kyle!

  • @rajeshbudhathoki7888
    @rajeshbudhathoki7888 4 года назад

    Wow! 😍😍 Thanks for the tutorial! 🙏🙏

  • @luise6124
    @luise6124 4 года назад

    Thank you so much for sharing your knowledge!

  • @yadneshkhode3091
    @yadneshkhode3091 4 года назад

    Thank you so much. And I am waiting for your course JavaScript intermediate to master and beyond.

  • @bedrockcoder5169
    @bedrockcoder5169 4 года назад

    Nice, I love your videos! Subbed

  • @samehfarouk500
    @samehfarouk500 4 года назад

    Absolutely wonderful, Thank you

  • @nickeax
    @nickeax 4 года назад

    Great work, as with all your presentations. Thank you very much.

  • @DannyFJhonstonB
    @DannyFJhonstonB 4 года назад

    Awesome video. Snake Game in JavaScript without frameworks or libraries. Very useful!

  • @frankfernandezavila
    @frankfernandezavila 3 года назад

    Great tutorial mate!

  • @wealthyvisions2081
    @wealthyvisions2081 2 года назад

    I just want to take the time out and give you a sincere Thank You from the bottom of my heart, this is the first time i went to a youtubers GitHub, cloned the code, and did not have an errors or bugs, everytime i go to a youtubers github, the code doesnt render what they showed in the video at all this is also the first time where i felt obligated to use that tip thanks feature youtbe just added. Dude the code was flawlessly written thank you so much. L

    • @wealthyvisions2081
      @wealthyvisions2081 2 года назад

      was literally on the verge of giving up until i came across this video, agiain thank you

  • @rishabhjain9349
    @rishabhjain9349 2 года назад

    Fallen in love with you after seeing your approach and code 👏👏

  • @mysiph
    @mysiph 3 года назад

    you explain things so well thank you so much

  • @anthonywoodworth3251
    @anthonywoodworth3251 Год назад

    Great functionality thanks man 🤙

  • @vikramjeetsingh1766
    @vikramjeetsingh1766 3 года назад

    thank you brother for this great tutorial

  • @prashoonbhattacharjee8211
    @prashoonbhattacharjee8211 3 года назад

    Amazing tutorial👍!!

  • @KratosVS
    @KratosVS 3 года назад

    kyle thank you for all the help you the best

  • @AgressivePigeon
    @AgressivePigeon 4 года назад

    This is a great solid tutorial. I don't know if anyone already pointed it out, but when you touch the tip of the tail (last piece of the snake's body) you don't lose the game, it just goes through it. Or maybe I just messed up my code.

  • @kochgamers
    @kochgamers 4 года назад

    you're INCREDIBLE!

  • @MaxProgramming
    @MaxProgramming 4 года назад

    Amazing. I still fear from canvas but I can follow this tutorial without canvas. Thanks a lot

  • @vijaykumarvijay7309
    @vijaykumarvijay7309 4 года назад

    your explanation is really awesome

  • @sofiavidal8461
    @sofiavidal8461 3 года назад

    It's wonderful !! Thanks so much!!!!!!

  • @yoanbello6891
    @yoanbello6891 4 года назад

    for me is the best channel for learn web development. Thanks

  • @whoman7930
    @whoman7930 4 года назад

    We want more of them Kyle please fasst!

  • @emmanuelsani4123
    @emmanuelsani4123 4 года назад

    This is what I needed

  • @patty_d.4773
    @patty_d.4773 Год назад

    Thank you so much!

  • @esse_apfel6448
    @esse_apfel6448 3 года назад

    Thats the video I have looked for hours

  • @LabaranLabs
    @LabaranLabs 4 года назад +1

    Great job keep the hard work

  • @devgarg7469
    @devgarg7469 3 года назад +2

    Thank you kyle, love from India

  • @enricoferaldokalengkongang6905
    @enricoferaldokalengkongang6905 4 года назад

    Awesome, I love this

  • @evgeniy4etok
    @evgeniy4etok 2 года назад

    good lesson! thanks a lot!

  • @sonukumar-if2fm
    @sonukumar-if2fm 11 месяцев назад

    a lot of thanks for the video

  • @mike_case
    @mike_case 4 года назад

    Thank you great work :)

  • @avigilben741
    @avigilben741 4 года назад

    Thank you I learned a lot from you

  • @Weibenfalk
    @Weibenfalk 4 года назад

    Awesome tutorial! =)

  • @milanradinovic6770
    @milanradinovic6770 4 года назад

    Awesome!!! I love your every video.

  • @malditobajista
    @malditobajista 3 года назад

    Muchas muchas gracias!!! awesome video

  • @glitchti9948
    @glitchti9948 3 года назад

    thanks i have made my first game ever yay, your really awsome

  • @casenetso245
    @casenetso245 3 года назад

    its complicated but easy to do thanks kyle

  • @Victor_Marius
    @Victor_Marius 3 года назад +1

    Nice! I've done few years ago rubik's cube with div elements for each piece faces and css transforms. It works well for desktop and mobile (with >=3 GB RAM) :)

  • @davitnazaryan5028
    @davitnazaryan5028 4 года назад

    This was awesome

  • @saeednoruzic
    @saeednoruzic 4 года назад

    awesome keep the good work on

  • @technova3629
    @technova3629 3 года назад +1

    Great bro....great

  • @superJerrySong
    @superJerrySong 3 года назад

    this is awesome!!! we need a spanish version of this chanel

  • @abulfazlhaidary2002
    @abulfazlhaidary2002 4 года назад

    You're AWESOME!!!

  • @aqibsaeed3229
    @aqibsaeed3229 3 года назад

    You actually make web simplified for us. Add reply here. Great work Kyle.
    Thumbs up from Pakistan.

  • @VojtaHraje
    @VojtaHraje 3 года назад +2

    So good video, thanks for it! Just one thing for people 45:30 the current location make like this:
    window.location = './'
    Kyle doesn't have the dot before slash here.

  • @GMannTheSFMGuy
    @GMannTheSFMGuy 2 года назад

    thanks! i used to code to make my first javascript game!

  • @aidanbenbow6682
    @aidanbenbow6682 2 года назад

    Can't believe that I actually managed to create this!

  • @cyril7104
    @cyril7104 4 года назад

    JUST At last!! Thx

  • @yambasankara3855
    @yambasankara3855 2 года назад

    grand merci, t'es super fort

  • @vashupandey2212
    @vashupandey2212 4 года назад +1

    thanku sooooooooooooooooo much!!!!😊😊😊😊😊👌👌👌👌👌

  • @Tech_Doctor788
    @Tech_Doctor788 4 года назад

    This is awesome

  • @ThinkSoumya
    @ThinkSoumya 2 года назад

    Amazingly Amazing
    "
    ''

  • @MuhammadAkbar-sy7zm
    @MuhammadAkbar-sy7zm Год назад

    Wonderful, thank you for the tutorial. newSubscriber ++

  • @VuongTran-pm4dg
    @VuongTran-pm4dg 4 года назад +1

    I had to add " window.location = '/index.html' " for it to restart. Great tutorial!

    • @deadaccount6327
      @deadaccount6327 3 года назад

      a simpler version of that would be window.location.reload()

  • @Ath9493
    @Ath9493 4 года назад

    Thank you so much 💓

  • @deepakarya5310
    @deepakarya5310 4 года назад

    Wow rwally loved this one..please make more videos related to vanilla js...and a video about workflow of creating big website like E-commerce website.(using MERN stack)

  • @the_awakening_msaha5132
    @the_awakening_msaha5132 4 года назад

    It's just awesome.

  • @sarifulislampatowari.2584
    @sarifulislampatowari.2584 4 года назад

    Love you bro. Would you make any video about front end development

  • @meganallred1915
    @meganallred1915 4 года назад +1

    Kyle, I love how you say "whoops" all the time.. it's adorable.. if you could throw in a "whoopsie daisy" next time it would make my day (winky face emoji)... great video!

  • @quak9144
    @quak9144 Год назад

    thanks bro that direction bug was the only problem i could not solve

  • @MewVSMewtwo89
    @MewVSMewtwo89 3 года назад +5

    if anyone is running into the CORS error.
    (In VS code) type: npm install --global http-server
    once it's installed, type: http-server
    then you can navigate to your specific page.

    • @lucas_lb_cube
      @lucas_lb_cube 3 года назад +1

      Here is a link to fix it: ruclips.net/video/wD4mR7f2YIk/видео.html

    • @MewVSMewtwo89
      @MewVSMewtwo89 3 года назад +1

      @@lucas_lb_cube nice addition! I fixed it via google, I'm sure this video will help someone!

  • @indeep6820
    @indeep6820 3 года назад

    nice video, tks u somuch

  • @dipenchavda6988
    @dipenchavda6988 3 года назад

    Super cool

  • @itamarzil1231
    @itamarzil1231 3 года назад

    Thank you very much. Can you share what camera, microphone you use ?

  • @tristanlanner8086
    @tristanlanner8086 4 года назад +1

    I really enjoy your videos and I do learn a lot with them, also the comments as we see can see you do attract intelligent and interesting people. For a long time I have been trying to create a SLOT MACHINE like the fruit machines in a casino and it is not working and I never found anything online that was made only with Vanilla JS. Do you think it would be possible to have something similar to that without the use of frameworks? If anyone have any good idea please do share with me.

  • @patrickc.6183
    @patrickc.6183 4 года назад +8

    Hey Kyle, since your milliseconds of time between frames is so low, do you have a 144hz monitor?

    • @WebDevSimplified
      @WebDevSimplified  4 года назад +12

      I do have a 144hz monitor. I just got it a few weeks ago

  • @priyankashahasane7758
    @priyankashahasane7758 3 года назад

    Hello, Thank you for your videos i always love them, just one request please increase the size of the text. It's really difficult to see.