top | item 4028597

Show HN: Snaketron, online multiplayer Snake

96 points| lopatin | 14 years ago |snaketron.com | reply

55 comments

order
[+] a1k0n|14 years ago|reply
Nice. The protocol is completely insecure and the server trusts everything the client does, so "Joshua" is just getting all the food every turn (by sending "eaten-snack" messages) and drawing random stuff.

The client should only be able to send the direction it's turning and on which turn, and that's it. The server should allow for some slack in the turn numbers, but not much.

[+] chubot|14 years ago|reply
Nice job, spent a good 30 minutes playing this :) Brain virus.

I encountered some bugs where there was a guy who couldn't lose. He just kept going straight and when he ran into me he didn't die. Maybe someone cheating by editing the JS?

Also, I noticed some glitches where other players' snakes had a really high velocity. Or was that a power up that I didn't get?

Tangent: Does anyone notice CRAZY GC pauses on Firefox, or something that appears every 5 seconds or so? It makes the game almost unplayable on Firefox. Switched to Chrome to play it.

[+] lopatin|14 years ago|reply
That's odd about the other snake having a higher speed than you. I've noticed that when I was testing a lot but I thought I patched all the bugs that caused it. I'll look into it thanks for pointing it out!
[+] steve8918|14 years ago|reply
Nicely done! I had a lot of fun playing this for about 30 mins!

A couple of questions: I thought that if one snake ran into another, it would end the game but there were a couple of times where they just passed thru each other. Was this a bug?

Also, there were a couple of times when either I or my opponent ran into the other, and it ended in a tie. Shouldn't that be a win for the other player?

[+] lopatin|14 years ago|reply
Thanks! Both of those are bugs caused by latence issues. I tried my best to make the game playable, but they still sometimes occur. Most likely the person you were playing with had a slower connection or had a browser that didn't support web sockets.
[+] pronoiac|14 years ago|reply
On Chrome, the arrow keys occasionally scroll the page. Keeping my other hand on the Home key helped.

I've also had it tell me "You won. :(" which is incorrect. :)

Edit: the Github badge at the top can get in the way. And there could be a check if you've disconnected. And it doesn't remember me if I reload.

[+] MCompeau|14 years ago|reply
It's great how you can use spacebar to start a new game, definitely fuels the addictive/impulsive play. Unfortunately the cycle is broken everytime I have to take my hand off the keyboard and use the mouse at the Game Over prompt.
[+] ryangilbert|14 years ago|reply
I agree... hitting spacebar after game over would be nice. I find that once I hit the okay button and play again then when I hit the first down (or up) arrow afterwards that it slightly moves my screen.

All space bars and arrows while playing the game should fix that.

[+] lopatin|14 years ago|reply
Lol that actually occurred to me. I had some issues with hotkeys but I think I might figure it out and add that, now that a few people have mentioned it already :)
[+] cing|14 years ago|reply
I thought this might be a multiplayer game of a single instance of Snake where the consensus move is executed in realtime from many players. Of course your version makes sense, but I think the latter would also be cool :)
[+] mgkimsal|14 years ago|reply
Sort of like a ouija snake?
[+] prezjordan|14 years ago|reply
This is very nicely done, thanks for making it open-source - I'm learning node to work on a game idea I've had for a long time. Could someone explain the basic idea of server.js and some of the stuff in public? It's a little overwhelming.
[+] lopatin|14 years ago|reply
Yea definitely, I wanted to comment this better but I was just too eager to release it hah.

The run down is this. server.js is a long running script and it only has a few global vars like games and playerQueue. These belong to the application as a whole. They're basically data structures that hold everything that's happening. Which games are being played, which players are waiting, and so on. The main stuff happens with socket.io in the io.sockets.on('connection' ... The paramter 'socket' in this code refers to the connection to a single player so if my server logic says that this player just won the game, I would say socket.emit('won-game') or in my situation I emit a 'gameover' message with some data specifying which username just won.

There's a lot more to it and I plan on getting to commenting the code better but that should point you in the right direction if you want to analyze the code.

[+] fidz|14 years ago|reply
Really great! I think it was on "really big" canvas with multiple snakes, but two snakes in real time are good too. Um, are those anonymouses are messing up the score? Especially in loss/win ratio.

Btw, where do you host this app?

[+] freditup|14 years ago|reply
Cool game but quite buggy. Sometimes a snake went through me, another time the opponent rammed into me and it was a draw. If we can have 3D shooters online without these problems, I would think a snake game would be possible too ;D

Anyway though, I do think it's well done, and open source too, so no real complaints.

[+] lopatin|14 years ago|reply
Thanks :) I think the issue is that some people are playing with browsers that don't support web sockets, so even if you support them, their connection affects the synchronization between you two. I should probably start doing some feature detection for websockets
[+] tylermenezes|14 years ago|reply
My biggest problem with this is I've gotten two opponents which didn't try to grow, just kept going in circles. They were pretty much guaranteed to win, since I eventually hit myself. Even if I hit them, it was just a draw.

Kind of silly, since they'd obviously get bored quickly, but still a problem.

[+] 6ren|14 years ago|reply
I think a "need to eat" would fix this, e.g. tail gets shorter by one every unit-time (e.g. 10s).
[+] ilaksh|14 years ago|reply
Hey man, that was my strategy a few times.. seems like a legit way to play I think.
[+] coffeeaddicted|14 years ago|reply
You can still win - just keep on eating, at one time a green point will suddenly appear in their path and it will make them lose (and you can get lots of points in the meantime).
[+] superkuh|14 years ago|reply
There are already people cheating. I'm looking at you Anon #2340.
[+] coffeeaddicted|14 years ago|reply
I love it. Tell against whom you fight - that would add to the thrill (especially if it's one of the top-10, maybe even show the number fat in that case).
[+] bfilmheld|14 years ago|reply
Love it! You made a very entertaining game out of this idea!

I'm curious if you did by any chance see my take on multiplayer snake? (From here or the tigsource forums, maybe? It's playable at http://bfilmhelden.de:8080/ less polished tough. Made some different choices. (E.g. clients can only send commands, and also send always the full game state.)

[+] jboggan|14 years ago|reply
It works really well about half of the time for me. A really nice effort, but I do notice the other snake "moonwalking" sometimes and reversing several steps before retracing their route. Sometimes I am able to kill them while being several pixels away. It's an awesome start and a great excuse to learn Node though.
[+] ryangilbert|14 years ago|reply
As more people keep playing I've noticed it's starting to glitch.

Last game my opponents snake ran into me and I could tell that he was then done playing because his snake kept going in a straight line over and over. About a minute later it finally said I won.

Just a heads up.

[+] lopatin|14 years ago|reply
Gotcha. I haven't experienced that yet but it may be resulting from all the traffic I'm getting right now.

Or .. were there still snacks popping up after he ran into you? If not, it's possible that the server restarted when that happened due to some exception so you just ended up playing solo with no server connection.

[+] piptastic|14 years ago|reply
Very fun :) I used to play a lot of nibbles back in the day...

Small bug: over 10.0 W/L and it stopped showing up in the leaderboards: http://i.imgur.com/NChEp.png

Once I lost a 2nd game it appeared again.

[+] unimpressive|14 years ago|reply
Magnificent. I was hypnotized by my 1# spot on the running score until I lost it.

The meta competition is an addiction +1 powerup.

My personal recommendation is some catchy techno tune as music. Heart pumping sort of music that gets you into the zone.

[+] lopatin|14 years ago|reply
Great suggestion, I would snake to techno
[+] lumberjack|14 years ago|reply
JS events using in these JS only apps conflict with Pentadactyl and Vimperator for me. :(

EDIT: It's the extensions' fault, just to be clear. Also, I'm amazed by the addictive nature of this simple game!

[+] minoru|14 years ago|reply
You can enable "ignore all keys" mode with Shift-Escape in Vimperator. It would then just pass all your key strokes directly to the app. I believe there should be similar mode in Pentadactyl as well.
[+] binxbolling|14 years ago|reply
This is maddeningly addictive. However, "draws" are a little weird -- I often saw my opponent run directly into me, yet we get a draw? Shouldn't that be my win?
[+] piptastic|14 years ago|reply
When I played, it looked like if you run into each other in the first 1-3 segments of the head end, it will declare it a draw. However if the player runs into you further down the chain you'll win.
[+] ricardobeat|14 years ago|reply
This is great!

Would be cool to have maybe 3 rounds vs the same opponent and a chat window, so the competition can heat up a little.

Also, I hope passwords aren't being stored in clear text :)

[+] lopatin|14 years ago|reply
Sure aren't :) Crypto node module FTW. And I should definitely add those components to make it more competitive thanks for the suggestion!