
JavaScript Snake Game Tutorial Using Functional Programming
video description
Date: 2022-03-14
Comments and reviews: 10
Florian
That is a great tutorial! I work as scala developer and I'm currently learning elm for fun, so I'm familiar with FP.
You really have a talent creating readable code imho. I was wondering all the time how you would have implemented the nextSnake function and was expecting some complicated mapping over accumulated moves or whatever. But your -remove the tail and append a new head- approach is super elegant. I haven't thought about the problem enough to come up with this elegant solution.
I'll try to reimplement your solution with elm if I have time.
reply
That is a great tutorial! I work as scala developer and I'm currently learning elm for fun, so I'm familiar with FP.
You really have a talent creating readable code imho. I was wondering all the time how you would have implemented the nextSnake function and was expecting some complicated mapping over accumulated moves or whatever. But your -remove the tail and append a new head- approach is super elegant. I haven't thought about the problem enough to come up with this elegant solution.
I'll try to reimplement your solution with elm if I have time.
reply
freecodecamp
Very nice implementation, but in javascript games, reuse of objects and objects pooling is key for a decent performance, try a space shooter or a bullet hell shooter to see the limits and witness the garbage collector rampage. I'm not very familiar with functional programming, but why returning a new function each frame while you could use two variables to get the deltaT and set the frame rate at the value you want ?
reply
Very nice implementation, but in javascript games, reuse of objects and objects pooling is key for a decent performance, try a space shooter or a bullet hell shooter to see the limits and witness the garbage collector rampage. I'm not very familiar with functional programming, but why returning a new function each frame while you could use two variables to get the deltaT and set the frame rate at the value you want ?
reply
Tao
Hey, Interesting tutorial, but requestAnimationFrame should be running apprx every 16ms, limiting or trying to hard code this to instead run at 100ms for each frame seems a bit counter-intuative. Still learnt quite a lot from this video. But this implementation seems very convoluted.. Maybe you could make a remake of this using the new .animate() Javascript api...
reply
Hey, Interesting tutorial, but requestAnimationFrame should be running apprx every 16ms, limiting or trying to hard code this to instead run at 100ms for each frame seems a bit counter-intuative. Still learnt quite a lot from this video. But this implementation seems very convoluted.. Maybe you could make a remake of this using the new .animate() Javascript api...
reply
Allan
Haha that's a good one man! =)
Oh anyway, can I seek your advice in this open source android app I have posted below? I will be happy to get feedback about this app. Greatly appreciate!...
You can search ' -pub:Path Ahead- ' in Android Play Store (P & A are case sensitive).
thanks a-hundred-times !!
reply
Haha that's a good one man! =)
Oh anyway, can I seek your advice in this open source android app I have posted below? I will be happy to get feedback about this app. Greatly appreciate!...
You can search ' -pub:Path Ahead- ' in Android Play Store (P & A are case sensitive).
thanks a-hundred-times !!
reply
Mal
state.moves should not be an array. The snake is only able to move one direction at a time. If you spam multiple keys, the snake remains moving around even after releasing all keys. Also state.snake should not be an array of the coordinates where the snakes body would be. It should be the length of the snake.
reply
state.moves should not be an array. The snake is only able to move one direction at a time. If you spam multiple keys, the snake remains moving around even after releasing all keys. Also state.snake should not be an array of the coordinates where the snakes body would be. It should be the length of the snake.
reply
spinthma
Hi thank you for the nice example. I did not get the spec() function how does it work without any parameter - the state, how does it knows about, how orks map / apply, and how to understand the spec function in itself. Thanks you
for example o => x => , x is never referenced,
reply
Hi thank you for the nice example. I did not get the spec() function how does it work without any parameter - the state, how does it knows about, how orks map / apply, and how to understand the spec function in itself. Thanks you
for example o => x => , x is never referenced,
reply
awaterplease
Could someone please explain me line 'const step = t1 => t2 => -...'
are t1 and t2 both arguments of step fucntion and if they were, why wasnt it written line 'const step = (t1, t2) => -...'
Thanks.
reply
Could someone please explain me line 'const step = t1 => t2 => -...'
are t1 and t2 both arguments of step fucntion and if they were, why wasnt it written line 'const step = (t1, t2) => -...'
Thanks.
reply
Ganesh
thanks for this video? could you please tell me how to show grid lines in snake's background, so to predict in which row it is.
in short, To show rows and columns cells/squares.
reply
thanks for this video? could you please tell me how to show grid lines in snake's background, so to predict in which row it is.
in short, To show rows and columns cells/squares.
reply
Nikhil
Very well explained tutorial. Why do you use multiple arrows for multiple input arguments for function? like p1 => p2 => and not (p1, p2) => ?
Edit: I understand currying now!
reply
Very well explained tutorial. Why do you use multiple arrows for multiple input arguments for function? like p1 => p2 => and not (p1, p2) => ?
Edit: I understand currying now!
reply
MindGem
Who is your target group for this? I came in thinking Snake was a newbie tutorial but it looks super complicated so me as a beginner is not the target group.
reply
Who is your target group for this? I came in thinking Snake was a newbie tutorial but it looks super complicated so me as a beginner is not the target group.
reply
Add a review, comment
Other channel videos















