First Reason Project: Smooth Snake Game and Takeaways from it


#1

Hey! I made a snake game using Reason that you can play here. Also the source code is here if you want to take a look. Writing it in Reason was super interesting, and the community was very helpful and answered a lot of my questions on discord.

This is probably one of my most favorite lines of code I’ve written just because it’s so expressive

let update = (snake: t) => snake |> moveSnake |> pivotBody |> pivotHead;

Advice that I got in discord that I wish I had known earlier:

  • Use bs-webapi.
  • Use Belt. It’s super useful.
  • Use rollup to bundle your code because it’s really good at tree shaking.
  • Reading the code that bucklescript generates is super useful, and really helps understand what’s going on. (this was especially useful for when I wrote my own bindings to roughjs)

The only real cons were just that it was very hard for me to debug lists using the in browser debugger since they were a bunch of nested arrays, and the UNKNOWN SYNTAX ERRORS did eat up some of my time.


#2

Thanks for this, I’ll definitely be taking a look into bs-webapi and Belt soon.


#3

@aria I see from the gif that the sneak blocks are exiting a little too early from one side to another; they disappear a little before they reappear on the other side. Small nit, probably complicated to implement =)


#4

@chenglou yeah because of the way that the interpolation works, I have to teleport the segment of the snake to the other side. If I didn’t do that, the segment would appear to move backwards in position instead of phasing through the wall. I could fix it, but I’d have to write some special cases into the code, which wasn’t really worth it to me. I figured people would be focusing more on the head of the snake anyways instead of checking to see if the rest of the body makes it through the wall smoothly.