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.
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.
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!
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?
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.
I had some similar problems; a couple of times I was just ahead of the other snake but when I turned across his path it recorded as a draw. I understand that it's really difficult to solve this sort of thing and provide a good experience for the players, but it kind of kills the game for me if it shows me that I'm going to win and then declares that actually I didn't.
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.
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.
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 :)
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 :)
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.
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.
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.
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.
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
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.
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).
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).
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.)
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.
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.
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.
Yeah this happened to me too. After a while the snacks stopped popping up and my opponent just kept looping. Which means you have to refresh and lose your running score :(
Fantastic game though, so addictive... the running score, and win ratio are great. It would be cool if you could see your opponent's win ratio or a rank of some sort too? Perhaps when you're counting down for the game to start?
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.
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?
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.
Thanks! I actually spent the majority of my time fixing latency issues. The movement actually is mostly client side, but I have to sync positions sometimes. With purely client side movement many issues arise like one snake lagging behind the other one due to rendering being slower on one computer, a snake turning a block too late on one browser because it gets the signal later, .. things like that. So I just sync positions when it matters.
Also, make running into the edge kill you, or at least change it so that the edges become lethal after a certain amount of time. That would make the endgame more dramatic, as it would be easier to encircle your opponent.
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.