Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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?


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.


Ah, 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.


This. Nokia 3310 style.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: