Simple Snake Game in TI Basic
This is a very simple Snake game written in TI Basic. The snake starts in the middle of the display and grows very quickly, i.e. its end stays in the same position. You can add obstacles by setting graphs, since they are drawn before the game starts. If you reach three consecutive pixels, you lose.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | : Pxl-On( 1, 1 ) : ClrDraw : 46 -> X : 32 -> Y : While 1 : getKey -> K : If ( K > 23 and K < 27 ) or K = 34 : K-> D : If D = 24 : X - 1 -> X : If D = 25 : Y - 1 -> Y : If D = 26 : X + 1 -> X : If D = 34 : Y + 1 -> Y : If pxl-Test( Y, X ) : Then : A + 1 -> A : If A > 2 : Stop : Else : 0 -> A : End : Pxl-On( Y, X ) : End |
Time for explanation, then:
- Line 1 puts a pixel on the display in order to bring the graphical window up. If this is not done, line 2 has no effect.
- Line 2 clears the graph window of any prior snakes.
- Lines 3-4 sets the initial coordinates of the snake’s head in the center of the display. The display is 92 pixels wide and 64 pixels high.
- Line 5 starts the game loop.
- Line 6 gets the key input and stores it into K. This is done so that the same key can be used in the next statement.
- Line 7 checks whether K is one of the direction keys. If it is, it is stored into the direction variable.
- Lines 8-11 check what the direction variable is set to, and adjusts the snake’s head accordingly.
- Line 12 is a nested If statement. It can be rewritten as follows in pseudo-code:
If ( pxl-Test( Y, X ) ) { A + 1 -> A If ( A > 2 ) { Stop } } Else { 0 -> A }If the snake’s head is on a pixel, the consecutive pixel count — A — is incremented. Then, if A is greater than 2, i.e. this was the third pixel, the game loop (and thereby the game) ends. If it was not a pixel, the pixel count is reset to 0.
- Line 14 marks the end of the game loop. Here, it starts over at line 5 again.

Hi,
I am from Spain and I found your blog some time ago. I studied IB some years ago and also made some programs for TI-83. I did a Risk game, I’ll have to check if I still have a backup copy…
I studied Computer Science and one of the games I created (this time in Pascal for Windows, not TI Basic) was very similar to the simple snake you’ve posted. It was called Slug (”babosa” in Spanish). You can download it from here if you want: http://jorgealvaro.dyndns.org/jorgealvaro/babosa.zip
Keep posting, it’s an interesting blog!
Comment by Jorge — April 11, 2007 @ 8:08 am
Hello, Jorge. Hope the IB exams weren’t too hard. The Risk game that you made seems cool — the most advanced program that I’ve tried to write for the TI-83 was Hex, but it never really succeeded. I’m very interested in seeing how you implemented such a complex game.
Comment by Tim — April 11, 2007 @ 3:52 pm
Hi,
I’ve found my Risk game, but I wanted to test it and I don’t have any cable for connecting the calculator.
I have the .83p programs. Do you know any good TI-83 emulator? I downloaded emu83 but didn’t get it to work properly, I couldn’t see anything on the emulated TI-83 screen.
Jorge
Comment by Jorge — April 12, 2007 @ 1:07 pm
Actually, Jorge, I never came to programming in assembly since I couldn’t find the necessary tools for Linux, and so I wrote anything in the highly inefficient TI Basic. If you find a working emulator, please notify me.
Good luck in testing the program.
Comment by Tim — April 12, 2007 @ 9:28 pm
Hi again!
Actually they are TI Basic programs, assembly looked very bad when I was studying IB.
I found a good TI-83 emulator and I’ve tested a bit my programs.
You can find the emulator here:
http://www.ticalc.org/archives/files/fileinfo/84/8442.html
And you can download the programs from:
http://jorgealvaro.dyndns.org/jorgealvaro/ti-83_risk_the_game.zip
There’s a small readme file I just wrote. Ask me if you need anything.
Hope you like them!
Comment by Jorge — April 21, 2007 @ 2:12 am
Jorge, I’m going to check it out as soon as I find time!
Comment by Tim — April 22, 2007 @ 11:00 pm
hey, i copied this program exactly onto my TI-83+ and pressed enter…and i’m in a graph area…thats it. nothing happens, no buttons make anything happen at all :(
help! please email me! dafin@gmx.net
Comment by dafin@gmx.net — October 3, 2007 @ 10:38 pm