3 ms·
As an expert in this area (I implemented snake, once, in ascii for kicks) the problem with that approach is there's no way to undo your presses. So if you erron
by shmageggy 14y ago
As an expert in this area (I implemented snake, once, in ascii for kicks) the problem with that approach is there's no way to undo your presses. So if you erroneously press left when you meant to press right, you're screwed. The best control strategy I found, and the one that seemed to correlate with classic implementations, is to simply take the most recently pressed key at each tick, and only allow the keys that correspond to left and right relative to your snake's direction.
- meaty 14y agoThis. Nokia 3310 style.
- a1k0n 14y agoAh, but then you can't do a quick U-turn. I think ideally you'd queue up to two moves, the second always being a 180 if any, but if you change your mind it clears the queue. E.g. you're going right, you can queue up-left or down-left but if you hit up-left-up you just go up, up-left-right you just go right, etc.