How To Code The Snake Game In Javascript

  Рет қаралды 342,632

Web Dev Simplified

Web Dev Simplified

Күн бұрын

Пікірлер: 560
@maskman4821
@maskman4821 4 жыл бұрын
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 жыл бұрын
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 жыл бұрын
Thank you so much! You are far too kind to me. I am really glad you enjoy my teaching style.
@techtipsuk
@techtipsuk 4 жыл бұрын
Well said
@maskman4821
@maskman4821 4 жыл бұрын
I am deeply touched, your words make me cry ...
@Faxtixe
@Faxtixe 4 жыл бұрын
is this your school project?
@kyle6754
@kyle6754 3 жыл бұрын
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.
@fionat.6411
@fionat.6411 4 жыл бұрын
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 жыл бұрын
That is a really smart way to think about the problem!
@maskman4821
@maskman4821 4 жыл бұрын
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 жыл бұрын
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 3 жыл бұрын
as the old saying goes KISS - keep it simple stupid!
@mrahamed5985
@mrahamed5985 4 жыл бұрын
This is the channel where i always Learn with joy.
@Al_Gonzo
@Al_Gonzo 4 жыл бұрын
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 жыл бұрын
Now go and learn OOP / Classes and make it a better structure. It's a great starting point for new developers.
@tyrrelldavis9919
@tyrrelldavis9919 4 жыл бұрын
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
@OnlineTutorialsYT
@OnlineTutorialsYT 4 жыл бұрын
1:30 Wow....its really amazing
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
Thanks!
@OnlineTutorialsYT
@OnlineTutorialsYT 4 жыл бұрын
Welcome bro :)
@dnynu
@dnynu 4 жыл бұрын
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 жыл бұрын
sure i agree
@dnynu
@dnynu 4 жыл бұрын
@Dev Ed ko kaise bhul sakte hai 🔥👍
@hasanal-haddad8016
@hasanal-haddad8016 4 жыл бұрын
in this video, i learned about how - RequestAnimationFrame works - js module(import and export) thx kyle..
@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
@madeyeatreides4055
@madeyeatreides4055 4 жыл бұрын
Dude you’re like a mind reader or something thank you this is just what I needed
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
Glad I could help
@ankitsaiyan6151
@ankitsaiyan6151 3 жыл бұрын
Thanks man for this. There are some questions in my mind-- 1. How to implement level system? 2. How to add obstacles? 3. How to add scores? 4. How to add play game screen? Please add more features in your game. We will have clear understanding over this.
@oibender
@oibender 2 жыл бұрын
I've seen all this implemented on a designated website, and the code can be accessed via the browser's developer tools. Too bad, youtube does not allow any specific mentions of other websites...
@oibender
@oibender 2 жыл бұрын
The author of this video may not want this information to be shared here either for obvious reasons.
@GA-vb1yj
@GA-vb1yj 2 жыл бұрын
@@oibender hey, how can I find that site? Can you ping the url in a private message?
@sharmashivanand
@sharmashivanand 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.
@kikevanegazz325
@kikevanegazz325 Жыл бұрын
Brother, you deserve a medal for this video-tutorial. Everything was well explained, smooth, clear, and connected. Great job!
@goldfinch5522
@goldfinch5522 4 жыл бұрын
before I watch the video I want to tell you how much I appreciate what you do on KZbin .. really impressive
@tj_yt_
@tj_yt_ 3 жыл бұрын
21:15 in case if anyone’s confused, it should be “we’re shifting entire snake, except it’s tail up a position”. This creates 2 head coordinates at the beginning of the array, the original one and its clone that was moved up. We then modify the original head to be at a new position
@pedroalmeida8453
@pedroalmeida8453 3 жыл бұрын
I coded everything just like him, but when I run it, it shows a empty Grey screen... help?
@pedroalmeida8453
@pedroalmeida8453 2 жыл бұрын
@Jawad Khan I’ll do this again alone to see if my knowledge has improved lr not, and ill make sure to check out your comment if ive the same error! Appreciate it!!
@Maxtasy888
@Maxtasy888 4 жыл бұрын
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.
@medhashree2416
@medhashree2416 4 жыл бұрын
I m totally enjoying your lessons . Thank you for this wonderful series of knowledge 😊
@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.
@bernardozelaya2685
@bernardozelaya2685 4 жыл бұрын
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 !!
@VojtaHraje
@VojtaHraje 3 жыл бұрын
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.
@clairecontemporary
@clairecontemporary 2 жыл бұрын
wow excellent and fluent explaination without redundants , this is so impressive
@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.
@VuongTran-pm4dg
@VuongTran-pm4dg 4 жыл бұрын
I had to add " window.location = '/index.html' " for it to restart. Great tutorial!
@deadaccount6327
@deadaccount6327 4 жыл бұрын
a simpler version of that would be window.location.reload()
@mbouweeric2512
@mbouweeric2512 4 жыл бұрын
Excellent! clean code and a nice explanation. You are doing great work with your videos, thank you so much for that Kyle.
@aqibsaeed3229
@aqibsaeed3229 3 жыл бұрын
You actually make web simplified for us. Add reply here. Great work Kyle. Thumbs up from Pakistan.
@___Kevin
@___Kevin 3 жыл бұрын
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
@rishabhjain9349
@rishabhjain9349 3 жыл бұрын
Fallen in love with you after seeing your approach and code 👏👏
@yoanbello6891
@yoanbello6891 4 жыл бұрын
for me is the best channel for learn web development. Thanks
@caseymccray3861
@caseymccray3861 4 жыл бұрын
You code so well. I'm so impressed.
@jlambert12013
@jlambert12013 2 жыл бұрын
"Exactly what we want." - Official Slogan of Web Dev Simplified
@kevklash
@kevklash 4 жыл бұрын
Amazing! Pretty well explained, it has been really useful. This is why I love this channel, thanks for sharing.
@Victor_Marius
@Victor_Marius 3 жыл бұрын
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) :)
@aidanbenbow6682
@aidanbenbow6682 2 жыл бұрын
Can't believe that I actually managed to create this!
@shreymehrotra5408
@shreymehrotra5408 4 жыл бұрын
Amazing!!!!!! Very helpful tutorial...you are such a hardworking guy. :)
@Aniket5224
@Aniket5224 4 жыл бұрын
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.
@colbyryan6884
@colbyryan6884 3 жыл бұрын
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.
@superJerrySong
@superJerrySong 3 жыл бұрын
this is awesome!!! we need a spanish version of this chanel
@DannyFJhonstonB
@DannyFJhonstonB 4 жыл бұрын
Awesome video. Snake Game in JavaScript without frameworks or libraries. Very useful!
@RameenFallschirmjager
@RameenFallschirmjager 4 жыл бұрын
Your voice has become so deep! I thought you said hello darkness my friend at first!😂
@devgarg7469
@devgarg7469 4 жыл бұрын
Thank you kyle, love from India
@shobhitpreetamsahoo4267
@shobhitpreetamsahoo4267 3 жыл бұрын
Thanks Kyle, your tutorials are really great. Appreciated man. Learned a lot today.
@avi12
@avi12 4 жыл бұрын
45:27 ...or just window.location.reload()
@_.sunnyraj._
@_.sunnyraj._ 4 жыл бұрын
Thx
@silentscopez1364
@silentscopez1364 Жыл бұрын
Solid video man! I Easy to follow though you skipped over a single part anyone should be able to figure out if they followed along
@jospichal1872
@jospichal1872 2 жыл бұрын
Hey man what an awesome video! Thank you so mutch from Italy ;)
@asherintech
@asherintech 4 жыл бұрын
Thanks for this Kyle! You're videos are always top notch, keep it up :)
@MewVSMewtwo89
@MewVSMewtwo89 3 жыл бұрын
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 жыл бұрын
Here is a link to fix it: kzbin.info/www/bejne/rXWXnoVtm5eMf80
@MewVSMewtwo89
@MewVSMewtwo89 3 жыл бұрын
@@lucas_lb_cube nice addition! I fixed it via google, I'm sure this video will help someone!
@casenetso245
@casenetso245 4 жыл бұрын
its complicated but easy to do thanks kyle
@nullitx2775
@nullitx2775 3 жыл бұрын
When i tried to run the animation frame thing, I got an error in the console saying “Access to the script at (the game.js location) from origin ‘null’ has been blocked by CORS policy”
@Chris-bv2hz
@Chris-bv2hz 3 жыл бұрын
you have to run it on a live server you cant just open the index.html file in your browser
@ninos163
@ninos163 3 жыл бұрын
@@Chris-bv2hz how can I run it on a live server?
@tsimlaj
@tsimlaj 3 жыл бұрын
@@ninos163 Download an extension called 'Go Live'. It let's you use a live server and go on local host. It's downloadable on VSCode. Not sure if it is available on other code editors.
@vijaykumarvijay7309
@vijaykumarvijay7309 4 жыл бұрын
your explanation is really awesome
@reelstrendingsongs
@reelstrendingsongs 4 жыл бұрын
1000 subs per day.....yo wooooo....🔥🔥
@whoman7930
@whoman7930 4 жыл бұрын
We want more of them Kyle please fasst!
@patrickc.6183
@patrickc.6183 4 жыл бұрын
Hey Kyle, since your milliseconds of time between frames is so low, do you have a 144hz monitor?
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
I do have a 144hz monitor. I just got it a few weeks ago
@enochlin2567
@enochlin2567 3 жыл бұрын
Mind Blown. Thanks Kyle!
@GiovanniCardamone
@GiovanniCardamone 4 жыл бұрын
better approch to move is pop the last element, calculate next position based on the head, and than push it
@alissonarboleda9493
@alissonarboleda9493 3 жыл бұрын
Thank you, I am just learning and even though I was only able to copy the code it this was sooo helpful!
@quak9144
@quak9144 2 жыл бұрын
thanks bro that direction bug was the only problem i could not solve
@KratosVS
@KratosVS 3 жыл бұрын
kyle thank you for all the help you the best
@swayamprajapat6154
@swayamprajapat6154 3 жыл бұрын
23:40 ffeeewwhhhhh!
@GManTheMarioGuy
@GManTheMarioGuy 2 жыл бұрын
thanks! i used to code to make my first javascript game!
@omar-1-28
@omar-1-28 3 жыл бұрын
you are very easy to follow i had no trouble following but i did get some errors but fixed them good job 😊👍
@frankfernandezavila
@frankfernandezavila 3 жыл бұрын
Great tutorial mate!
@zshyman
@zshyman 3 жыл бұрын
If you get an error, even though you're doing exactly what he is, try serving the html on a local node.js live-server and make sure to turn the caching off.
@esse_apfel6448
@esse_apfel6448 3 жыл бұрын
Thats the video I have looked for hours
@MaxProgramming
@MaxProgramming 4 жыл бұрын
Amazing. I still fear from canvas but I can follow this tutorial without canvas. Thanks a lot
@anthonywoodworth3251
@anthonywoodworth3251 2 жыл бұрын
Great functionality thanks man 🤙
@meganallred1915
@meganallred1915 4 жыл бұрын
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!
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
I prefer the term shucky darns.:P
@meganallred1915
@meganallred1915 4 жыл бұрын
@@WebDevSimplified haha.. love it!
@shaggiel3099
@shaggiel3099 4 жыл бұрын
The thing is, I’ve been looking for this for a while, but everything I’ve found has always taken 3 hours to learn how to make the snake object, not including food. Thanks!
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
Glad I could help!
@yadneshkhode3091
@yadneshkhode3091 4 жыл бұрын
Thank you so much. And I am waiting for your course JavaScript intermediate to master and beyond.
@glitchti9948
@glitchti9948 3 жыл бұрын
thanks i have made my first game ever yay, your really awsome
@sureshthakur1305
@sureshthakur1305 4 жыл бұрын
Awesome 👍 sir, I want more JavaScript games from you. Kindly make a full playlist of "Game Development with JavaScript".
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
I plan to make some more game tutorials in the future. Rock paper scissors is coming soon and I want to make tetris as well.
@vikramjeetsingh1766
@vikramjeetsingh1766 3 жыл бұрын
thank you brother for this great tutorial
@liampugh4705
@liampugh4705 3 жыл бұрын
New to development so thank god for half speed playback :D
@tristanlanner8086
@tristanlanner8086 4 жыл бұрын
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.
@hyprisking
@hyprisking 2 жыл бұрын
hey Kyle, I know this is late and there's a small chance you'll see this but it didn't refresh the snake and food after we implemented the expanding part any reason you might know know of? edit: nvm it did RIGHT after I commented...
@ibeeliot
@ibeeliot 4 жыл бұрын
at 9:34 when you invoke main for the first time with requestAnimationFrame(main), where is the currentTime dependency coming from on the main function when you have it as an argument...main(currentTime ) {...console.log(currentTime}
@ThinkSoumya
@ThinkSoumya 3 жыл бұрын
Amazingly Amazing " ''
@mysiph
@mysiph 4 жыл бұрын
you explain things so well thank you so much
@connorbailey308
@connorbailey308 4 жыл бұрын
if you drop the food at a position that is random, and the random position is generated by checking whether the position chosen at random is on the snake, then once the snake is very very large (taking up 95% of the board for example) that loop could potentially run a large number of times. Wouldnt it be more efficient to grab all the open positions and grab a random one from that selection? Or maybe at the start, when the snake is small (maybe < 50% of the board) you can randomly assign a position without checking the board first, then, once the snake is longer ( > 50% of the board) you read the board and select the random position from the available spots?
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
That would be more efficient for sure. I just didn't want to write all the code to so that and I knew that in 95% of cases this code would be fine since most people lose before the snake gets that big
@connorbailey308
@connorbailey308 4 жыл бұрын
@@WebDevSimplified That makes sense!
@bedrockcoder5169
@bedrockcoder5169 4 жыл бұрын
Nice, I love your videos! Subbed
@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)
@LabaranLabs
@LabaranLabs 4 жыл бұрын
Great job keep the hard work
@pleasurface
@pleasurface 4 жыл бұрын
Wow, this tutorial is awesome! Thank you so much
@prashoonbhattacharjee8211
@prashoonbhattacharjee8211 4 жыл бұрын
Amazing tutorial👍!!
@priyankashahasane7758
@priyankashahasane7758 4 жыл бұрын
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.
@mounir101
@mounir101 4 жыл бұрын
The video was great! I liked it. Thanks so much.
@luise6124
@luise6124 4 жыл бұрын
Thank you so much for sharing your knowledge!
@inderjitsaini9303
@inderjitsaini9303 2 жыл бұрын
This a very helpful video. Just a question: Why weren’t classes used inside of files of snake and food? Why did we only use independent functions?
@kengthe5949
@kengthe5949 4 жыл бұрын
you're doing an incredible job! thank you :)
@DiabloVal
@DiabloVal 4 жыл бұрын
2:12 Why the snake's Tail is like that??
@_.sunnyraj._
@_.sunnyraj._ 4 жыл бұрын
Major bug
@bitashahsavan7993
@bitashahsavan7993 4 ай бұрын
That was so cool and take 5 hour for coding and understanding
@deansprivatearchive
@deansprivatearchive 3 жыл бұрын
If I'm not just plain annoying, actual Snake has an extra tick where the snake doesn't move if you're about to lose. How would we code THAT?
@rajeshbudhathoki7888
@rajeshbudhathoki7888 4 жыл бұрын
Wow! 😍😍 Thanks for the tutorial! 🙏🙏
@trylle04
@trylle04 3 жыл бұрын
14:30 - Uncaught SyntaxError: Cannot use import statement outside a module I copied the exact same place, but it's saying something is wrong. Any ideas?
@santoss2428
@santoss2428 4 жыл бұрын
Yes sir ,👍 my Young brother is awesome 😎
@saar120
@saar120 3 жыл бұрын
At 43:12 - why did you set the parameter as "{ignoreHead = false} = {}" and not as "ignoreHead = false".
@sarifulislampatowari.2584
@sarifulislampatowari.2584 4 жыл бұрын
Love you bro. Would you make any video about front end development
@kochgamers
@kochgamers 4 жыл бұрын
you're INCREDIBLE!
@nerdsportal7252
@nerdsportal7252 3 жыл бұрын
amazing video. can you tell me what software you use to record your screen and webcam at the same time
@milanradinovic6770
@milanradinovic6770 4 жыл бұрын
Awesome!!! I love your every video.
@WebDevSimplified
@WebDevSimplified 4 жыл бұрын
Thank you so much!
@Weibenfalk
@Weibenfalk 4 жыл бұрын
Awesome tutorial! =)
@maximilianoamodei7827
@maximilianoamodei7827 4 жыл бұрын
Great video! Two functionalities I could not understand: 1) how does the object functionality with the 3 dots work {...array[i] } ? Do you have any useful resource about it? 2) how does puting {ignorehead = false}={} work?, I cannot get in which situations is useful to use this, any examples?
@soyaiburrahman3806
@soyaiburrahman3806 2 жыл бұрын
me too
I Can’t Believe They Added AI To The Browser
9:55
Web Dev Simplified
Рет қаралды 9 М.
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 101 МЛН
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 230 МЛН
How to Win Snake: The UNKILLABLE Snake AI
17:05
AlphaPhoenix
Рет қаралды 2,2 МЛН
How To Build A Simple Card Game With JavaScript
43:04
Web Dev Simplified
Рет қаралды 156 М.
Build Tic Tac Toe With JavaScript - Tutorial
41:46
Web Dev Simplified
Рет қаралды 361 М.
JavaScript Fighting Game Tutorial with HTML Canvas
3:56:20
Chris Courses
Рет қаралды 8 МЛН
How To Build Feature Flags Like A Senior Dev In 20 Minutes
20:33
Web Dev Simplified
Рет қаралды 96 М.
C Programming Tutorial for Beginners
3:46:13
freeCodeCamp.org
Рет қаралды 14 МЛН
These CSS PRO Tips & Tricks Will Blow Your Mind!
8:48
Coding2GO
Рет қаралды 475 М.
A game of Snake written in JavaScript 🐍
28:50
Bro Code
Рет қаралды 81 М.
How To Use Libraries Like A Senior Dev
9:53
Web Dev Simplified
Рет қаралды 45 М.
Get started with React.js & React Router 6+
3:45:30
Academind
Рет қаралды 170 М.
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН