Just for fun, my first Javascript game - SNAKE

Have Fun! -

Controls seem slightly delayed but more due to the fact the snake needs to move in the grid of blocks instead of changing the second you push the button… might be better if I calculate the turn based on when the snake is between block grids rather then just entered the block grid, I might update that when I have more time just to check.


Looks great and is a fun little game!

I took a peak at the code and appreciated all the comments . I’m learning Javascript myself and found all the comments helpful to follow along with how the program was working.

Keep up the nice work.

1 Like

Thanks, and good luck to you on your journey as well!

Looks and plays well. Nice!

The delay is a bit weird. Reminds me of Snake on old Nokia phones.

So the snake is an array of individual squares with their own location data in the grid, and setInterval just updates a new location and renders it?

1 Like

Thanks. And yep, thats basically it. At each interval, it adds a new head to the array based on direction/speed, and deletes the tail most block, checks for tail/wall/food hits, and then redraw. The challenge is keeping the snake on the grid instead of just turning the instant a direction key is pressed. Thats what causes the delay because when arrow is pressed but the snake isn’t lined up yet, a few more frames has to pass before the direction change occurs. Also learned to queue direction changes because if someone hit keys fast enough it could bypass checks if multiple direction changes happen between frame refreshes. It was fun. Next is a block breakout game.

I know very little about Javascript but this is a cool project, congrats! :smiley:

1 Like