TI-Basic Z80 Programming/Programming Games

It is possible to program simple games using TI-Basic. The explanations for the examples given here are meant to be a simple explanation, not a technical guideline.

PONG Demonstration
The following program is a simple game of Pong programmed in TI-Basic. We begin by defining the code for the game:

Here, we begin explaining the code:

These first lines initialize variables to certain values. The  and   variables are the coordinates for the ball. keeps the entire loop running. and  will change our ball coordinates. They allow us to use more efficient coding than using 1 and -1. is our horizontal coordinate for the paddle, so that it can move back and forth.

The not( command returns 1 (true) if the conditional is equal to 0. This is equivalent to using, but reduces a byte.

Refreshes the screen each time something moves (or at least each time the loop repeats).

This prints the symbols to the screen.

This tells the ball to "bounce" off the ceiling by reversing its direction.

This step right here does a bunch of stuff in a little space. The first line checks if the ball is at the bottom of the screen. If the ball is, then it checks if the ball is on the paddle. If the paddle is there, then the ball bounces off.

This tells the ball to bounce off the right and left walls.

This is what triggers the loss. This checks if the ball has hit the bottom of the screen. If it has, then the program terminates the loop.

This step makes the ball move around the screen, by changing the coordinates.

This is what makes the game tick. It is the user input step. stores the user keypress into. Then, in the next line,  (the horizontal coordinate for the paddle) gets one added to it if the user presses  (26) and is less than 13 (right side of the screen = 16 - 3 (for the size of the paddle))

An equality equation always becomes 1 if it is true, and 0 if false, therefore if it is true, then it will move one in that direction, and if the user presses (24) the same principle applies.

This line defines the end of the loop that the main part of the program is running in.

These lines run when you loose. It will display a message, clear the screen, and prevent "Done" from being displayed.

Here is the more optimized version: {{Bcode:Example| PROGRAM:PONG
 * 7→A:8→B
 * DelVar C1→D
 * -1→E:6→F
 * Repeat C
 * If A=1
 * -D→D
 * E-2Emax({A=7,B>=F,B<=F+3→
 * E-2E(B=1 or B=16)→E
 * A=8→C
 * Output(A,B," //")1 space
 * A+D→A
 * B+E→B
 * Output(A,B,"."
 * getKey
 * F+(Ans=26)-(Ans=24
 * If 15<=Ans
 * 1
 * If 0>=Ans
 * 13
 * Output(8,F,"   //")
 * Ans→F
 * Output(8,F,"--")
 * End
 * ClrHome
 * Output(1,1,"U LOSE")

}}

Note
A scoring system and other features can be added, but will be explained in later articles. This program works very well, except that the cursor doesn't move fast enough. In order to make the platform move faster, change:

to:

Which could also be written as the following:

This will make the platform skip over one more space, making the platform faster.