Page 1 of 2

My take on Snake

Posted: 24 Aug 2017, 17:34
by maestrith
I got bored and decided to write a version of Snake.
Hope someone finds it fun or interesting.
I am sorry but this code requires Windows 7+ and IE 11+ to run properly.


Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Re: My take on Snake

Posted: 24 Aug 2017, 18:06
by Masonjar13
Nice maestrith! Because I'm the sadistic type (ever played Velocibox at 3x speed?), I added a speed modifier option. Feel free to clean it up, but seems to work well enough.

Regular (2 start length): 69 (got bored)
Speed@50 (2 start length): 45
Edit 2: Speed@10 (100): 16

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Edit: changed the modifier to 1-10 (multiplied by 10).

Re: My take on Snake

Posted: 25 Aug 2017, 07:44
by maestrith
I'll possibly get to actually making some more options, but I am working on improving performance :) It starts to slow down around 200 or so body segments.

Re: My take on Snake

Posted: 25 Aug 2017, 08:30
by Delta Pythagorean
*Cracks knuckles* Alright, let's see how many times I have to press space this time...

Re: My take on Snake

Posted: 25 Aug 2017, 09:58
by maestrith
Added:
-Random Colors
-Zen Mode (no way to lose)
-Bumped up the start from 1-100 to 1-500 (it starts to slow a bit at about 400 or so)
-Score, Snake Length, and Mode displayed in the Title

I'll add more options later. I have a doctors appointment to go to.

Re: My take on Snake

Posted: 25 Aug 2017, 18:52
by Masonjar13
Oh jeez.. The random colors makes it nearly impossible to tell where the head is. Can the head be a more distinct color, or have the random colors as a switch? The title update was a great idea!

Edit: testing the limits, about 1011 length starts stuttering for me (at 9 speed, which should be 10ms delay, if you didn't change it). Around 1600-2000 it's about as slow as starting speed, and uses a whopping 50mb of memory and 15% CPU. At 4300, each body segment takes around 500ms to add. 5000, working set peaked at 103MB, CPU peak of about 16.8%. I realize this isn't technically useful information, I just like breaking things. ;)

Re: My take on Snake

Posted: 25 Aug 2017, 22:32
by maestrith
LOL! yea, I have some settings in the works I just had an appointment and then I fell asleep when I got home. I just woke up and I will work on some things.

I know it is a bit of a resource hog but it works a lot better than the original version. At around 80-100 it would start to flicker a lot and just look terrible.

Re: My take on Snake

Posted: 26 Aug 2017, 06:26
by maestrith
Update:
-Settings Page: Press Escape to Start the game and show Settings
-Colors: Edit the colors of the head of the snake and the body
-Zoom: Not what you think
To Do:
-Setup custom keys for directions and Settings

Re: My take on Snake

Posted: 26 Aug 2017, 17:58
by Masonjar13
Hm, feels like there's a problem with the colors.. My assumption was that, by setting the two colors for the body, they would alternate only those colors. It seems to often disrespect the colors and add random ones in anyway. They're also not alternating, but seemingly randomized. I didn't look too terribly hard, but I didn't see anything in the code explicitly that would do that. Or is it meant to be within the range of the two colors? Because that seems accurate then.

Re: My take on Snake

Posted: 26 Aug 2017, 18:02
by maestrith
It is a range between the two colors

Re: My take on Snake

Posted: 26 Aug 2017, 18:13
by Masonjar13
Ah, yeah that makes a lot more sense. Also noticed that the head, being the first created, has the lowest z-index. Only applies to Zen mode: when you go back over your own body, your head appears underneath the other segments, making it non-visible. Not sure how you could alter that, but it would help tremendously to have the head always on top.

Re: My take on Snake

Posted: 26 Aug 2017, 18:17
by maestrith
I'll see if I can fix it.

Re: My take on Snake

Posted: 26 Aug 2017, 18:25
by maestrith
Changed: Suggested by Masonjar13
-Changed the Z order of the head to be on top.

Re: My take on Snake

Posted: 27 Aug 2017, 14:52
by maestrith
Changed:
-Added: Change the hotkeys
-Re-Wrote a good portion of the code
-Changed the Snake Length to an HTML control

Re: My take on Snake

Posted: 27 Aug 2017, 15:17
by Helgef
Hello!
I tried it earlier, very nice, a classic! Thanks for sharing. :clap: :thumbup:

The latest version gives me an error though.

Code: [Select all] [Expand] [Download] (Untitled.txt)GeSHi © Codebox Plus


Cheers.

Edit:
maestrith wrote:oops. Fixed.

:thumbup:
The read head is a nice improvement. I'm not very good though :lol:

Re: My take on Snake

Posted: 27 Aug 2017, 15:26
by maestrith
oops. Fixed.

Re: My take on Snake

Posted: 27 Aug 2017, 15:29
by maestrith
Helgef wrote:Hello!
I tried it earlier, very nice, a classic! Thanks for sharing. :clap: :thumbup:
Cheers.

Thanks :)

Re: My take on Snake

Posted: 28 Aug 2017, 09:07
by maestrith
Added:
-Board Size: Select and it will Reload (Will make this not reload in a future release)
-Snake Size
-Shift+Escape also exits the game

Re: My take on Snake

Posted: 28 Aug 2017, 12:54
by SpeedMaster
Hello,
Very nice ! :thumbup:
but... Only the modified by Masonjar13 old version is working for me :cry:

Error: 0x80020006 - Nom inconnu.
Specifically: CreateElementNS
---> 103: defs := this.Doc.CreateElementNS("http://www.w3.org/2000/svg","defs")

Re: My take on Snake

Posted: 28 Aug 2017, 14:32
by maestrith
SpeedMaster wrote:Hello,
Very nice ! :thumbup:
but... Only the modified by Masonjar13 old version is working for me :cry:

Error: 0x80020006 - Nom inconnu.
Specifically: CreateElementNS
---> 103: defs := this.Doc.CreateElementNS("http://www.w3.org/2000/svg","defs")

I am using SVG which requires IE 11+. Divs start to flicker badly, at least on my system, at around 100 or so and the SVG do not flicker even when my PC starts to slow down at 500 or so. https://support.microsoft.com/en-us/help/17621/internet-explorer-downloads but Windows 7 is the minimum OS that will run it.

I tried the older version using IE 10 and below and the body segments were rectangular not square :( It just won't work properly below 11.