Snake with elm-ui

I am learning elm-ui and decided to make something fun. This is a classic snake game created with elm-ui. Just to give it a boost, this version has the food replenished in batches, not one by one.

  • The game is over if the snake bites itself or it hits
    the wall.
  • Snake grows with each chomp.
  • The longer the snake, the faster it moves.
  • The game is controlled only from keyboard, so please make sure you have focus
    on the game page. Or just focus on it by clicking the start screen.
  • You can tweak the Config to change the game defaults.

Try the game out at

And GitHub:


I love the variation! How fun :smiley:

Have you shared this in #gamedev on Slack? I think that group would love to see it!

Thanks, Brian. I like to start with these toy projects. They are not overly complex, yet they provide a good fun start for those new to the language.
I have just posted this in #gamedev on Slack.

Great work, it was fun to play!

Great work! I would love to see a tutorial on that :slight_smile:

Is it a design choice that pressing in the opposite direction you’re traveling is an instant game over? I prefer the “pressing opposite direction of travel does nothing” control strategy, meself. :wink:

EDIT: There is also a heavy enough input delay that a fast 180 (such as when going up, quickly press left then down) also gives a game over. It’s like all input goes into a buffer, with each input erasing the last input, until that buffer gets sampled at regular intervals.

I’d instead recommend a LIFO buffer where every game step pops one input event off the buffer. Then validity of input (such as ignoring input in reverse direction to current travel) check would happen on pop.

Elm is meant to be easy to refactor and modify on the fly, this might give one an opportunity to discern how true that is.

Very good points. I have made 2 changes:

  • Pressing opposite direction of the snake movement is now ignored.
  • Added direction key buffer. It results in much better gameplay.

Try on Ellie:

Thanks for your input!

1 Like

I agree, this plays way better now. Congratulations holobeat :smiley:

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.