Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimalistic approach for a Snake-style game

I received my TI-82 STATS programmable calculator (which is in fact more of a TI-83) about two days ago - and wanted to program a Snake game with the builtin TI-BASIC language.

Although I had to find out: TI-BASIC is extremely slow. My first implementation was so slow, that it wasn't even a challenge for the player! The main bottleneck for me lies in the management of the list (array) containing the coordinates of the snake body.

I have tried two things:

  • When the snake moves, update head position, then loop through the array from the tail position, and set myList[ N ] to myList[ N - 1 ], in order to make the snake appear to be moving.

This however, gets unplayable after the list gets about 4 parts long. (too slow)

  • Then, I tried implementing some sort of queue/deque using TI-BASIC's list manipulation features, like popping off the end and adding something at the front of the array.

This worked a bit better, but also gets too slow over time.

TL;DR / actual question:

  • Do you know a trick so the game doesn't slow down with the snake getting longer? I have seen that this is possible in other games made in TI-BASIC
like image 926
Carx Avatar asked Oct 13 '22 17:10

Carx


2 Answers

Use a circular buffer. To elaborate:

Get an array, sufficiently big to hold the maximum snake. Establish two pointers, one for the head, one for the tail.

At the beginning, the tail would be in cell #1, the head in cell #3. As the snake moves, move the head pointer to the right and write the new coordinate. Then, if there's no food eaten, move the tail pointer to the right as well. If either of the pointers tries to go beyond the rightmost end of the array, wrap them over to the beginning.

like image 141
Stop Putin Stop War Avatar answered Oct 25 '22 05:10

Stop Putin Stop War


A trick that most likely will work is instead of [ N - 1 ] do [ N - 2 ] or a higher number that way it makes up time by mathematically moving faster (you also have to adjust the size of the head to go faster

like image 26
Moshe Goldberg Avatar answered Oct 25 '22 05:10

Moshe Goldberg