top | item 14637013

Snake in Elm with WebGL

82 points| tibastral2 | 8 years ago |github.com

27 comments

order

pgt|8 years ago

I made Snake in 103 lines of ClojureScript for a talk from 2015: https://github.com/theronic/cljs-snake

It would be fun to implement WebGL as a renderer.

dyarosla|8 years ago

Bug: Create snake of length two. Move RIGHT. Quickly press UP LEFT in quick succession. Lose.

Similar bug with RIGHT->DOWN->LEFT

And so on for all the other initial directions.

fb03|8 years ago

Not the author, but I've implemented my own snake game and this bug is fairly easy to kill.

(1) - You can only change directions that will change your axis, if you're going left your possible changes are up and down, ....

(2) - You should be only able to consume one direction change per game tick, what is happening here is that rule (1) is working but you can change into the other axis, and then back to the other axis again before the game loop computes another frame. Direction change can be read asynchronously but the actual change should be tied by each tick.

KurtMueller|8 years ago

Why not file a Github issue? :)

fareesh|8 years ago

Yeah happened to me too, thought it was my mistake but now I blame the bug :D

donatj|8 years ago

I attended a two day Elm workshop a while back. There is a lot there to love, I just think it's Haskell inspired syntax is a major impediment to it's mainstream adoption. I however would love to be proven wrong as the webs reliability would be so remarkably improved.

mikekchar|8 years ago

Here's a challenge for you: what syntax would be better? I don't mean that in a derogatory way. I think you are right that the syntax (being very foreign to people) does provide an impediment, but puzzling out how to implement the same functionality with a more familiar syntax would be extremely difficult (though potentially very fun).

chenglou|8 years ago

I work on Reason, which is something you might like: http://facebook.github.io/reason/

Elm has been personally an inspiration too. Nice set of decisions and tradeoffs for what they're trying to achieve, though yeah, mainstream syntax might not be one of them, but that's fine.

KurtMueller|8 years ago

Imho, Elm's syntax is more akin to OCaml than to Haskell. Besides OCaml, it reminds me a lot of F#.

lolc|8 years ago

Cool demo. And I learn there was an Elm conference close to where I live and I missed it.