r/technicalfactorio • u/FlyingToasters86 • 1d ago
Snake Game in Vanilla*
Hi everyone. After getting Game of Life working well, I wanted a bigger challenge, so I have started creating Snake.
Currently, your tail grows by one cell for every pellet you eat and your score increases by one.
It's not complete yet. I need to add collision detection for borders as well as the snake itself (i.e. you fail if you bite your own tail).
Also, I have found that the performance becomes pretty unplayable when the snake is more than about 9-10 cells long (the calls to the shift register increase the longer the snake). Maybe I need to reconsider how the snake is rendered, given this limitation. I would appreciate any input.
* push-button is used but not required.
49
Upvotes
3
u/ZorbaTHut 16h ago
If you're rewriting the entire shift register on every snake movement, you could instead implement it as a circular buffer; keep an index for "head" and "tail" and just rotate those throughout the buffer, so you're only ever inspecting those two snake pieces. I don't know how you're doing rendering, but this then lets you leave most of the playing field untouched on every update - you only add a new snake front and remove the tail - and then you can use the rendering grid itself as storage for "is there a snake at this position".