4 ms·
The controls don't react if you press them too quickly. How about queueing up key presses and then each additional step of the snake would dequeue a key press?
by phasevar 14y ago
The controls don't react if you press them too quickly. How about queueing up key presses and then each additional step of the snake would dequeue a key press?
- shmageggy 14y agoAs 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.