p01 / snake

Snake game in no more than 256 bytes of HTML5
75 stars 21 forks source link

Pressing an arrow key in the opposite direction stops the game #3

Open lydell opened 8 years ago

lydell commented 8 years ago

Example steps to reproduce:

  1. Press the left arrow key when the game starts.

Actual result: The game stops. Expected result: The game continues as if no key was pressed at all.

I find myself pressing the wrong keys by mistake a lot, so to me the game isn't really playable. Nevertheless, impressive golfing!

p01 commented 8 years ago

Thanks.

One simple and short ( 2 bytes ) way to work around the problem is to switch from directional to steering controls so that only the ← and → keys are needed.

This is done by replacing d=e.keyCode&3 with d=d-e.keyCode&3

But directional controls don't need any explanation and this other controls scheme takes more practice to master.

What do you think ?

lydell commented 8 years ago

I know that some Snake versions do have steering controls, but I've never played one. I guess I'd suck at using them.

It's your program – you decide. Personally, I'd try to find some clever way to noop the arrow key in the opposite direction, even if it costs a few bytes.