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[edit | edit source]
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
B variables are the coordinates for the ball.
C keeps the entire loop running.
E will change our ball coordinates. They allow us to use more efficient coding than using 1 and -1.
F 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
While C=0, 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.
getkey→K stores the user keypress into
K. Then, in the next line,
F (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:
Note[edit | edit source]
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:
Which could also be written as the following:
This will make the platform skip over one more space, making the platform faster.