5 ms·
Snake in Elm with WebGL
- Kiro 9y agoHow is the actual game loop executed? I don't know Elm but I only find update, not how it's run.
- kornish 9y agoThe function `Html.program`, in `main`, takes an update function which handles (among other things) ticking the game loop. http://package.elm-lang.org/packages/elm-lang/html/latest/Html#program http://package.elm-lang.org/packages/elm-lang/html/latest/Ht...
- dyarosla 9y agoBug: 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.
- KurtMueller 9y agoWhy not file a Github issue? :)
- dyarosla 9y agoDone
- fb03 9y agoNot 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.
- baddox 9y agoMaybe it makes it too easy, but I would enjoy the mechanic that quickly pressing UP LEFT when moving right would make the snake head move one square up then turn left and continue left. I suppose that would require some special casing, and you wouldn't want to support longer queued direction changes. Maybe a nice implementation would be that for inputs queued within a single game tick, execute the first input for one square of movement, then the last input for the next tick.
- fareesh 9y agoYeah happened to me too, thought it was my mistake but now I blame the bug :D
- donatj 9y agoI 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.
- KurtMueller 9y agoImho, Elm's syntax is more akin to OCaml than to Haskell. Besides OCaml, it reminds me a lot of F#.
- fpoling 9y agoOr any other strict language in ML family like SML. Still it tells something about language popularity when is Elm is only compared with Haskell.
- mikekchar 9y agoHere'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).
- winstonewert 9y agoWell, something like C-like, for maximum familiarity. What functionality is difficult to render in C-like syntax?
- orblivion 9y agoCurrying
- winstonewert 9y agoI can get the same effect as currying with C syntax by deliberating invoking a special function: functools.partial(old_function, my_new_argument) Is this such a useful thing that you need the functional style syntax to make it even easier to do?
- pgt 9y agoI made Snake in 103 lines of ClojureScript for a talk from 2015: https://github.com/theronic/cljs-snake https://github.com/theronic/cljs-snake It would be fun to implement WebGL as a renderer.
- DrPhish 9y agoI'm going to make this the "Other awesome snake implementations" sub-conversation Here is a snake in 4k (sn4ke) mapped onto a sphere instead of a 2d playsurface, which is one of my favourites. http://www.pouet.net/prod.php?which=61035 http://www.pouet.net/prod.php?which=61035 Here is an awesome music-driven one that modifies the songs based on level and "danger" http://www.pouet.net/prod.php?which=57518 http://www.pouet.net/prod.php?which=57518 But the best snake ever was the one from FastTracker 2 by Triton! http://www.pouet.net/prod.php?which=13350 http://www.pouet.net/prod.php?which=13350
- lolc 9y agoCool demo. And I learn there was an Elm conference close to where I live and I missed it.