HOME >> Tutorials >> Tutorial 1: Advanced Game Design
Advanced Game Techniques Tutorials
Advanced BASIC
Tutorial 1
Advanced Game Design

   Advanced BASIC Tutorials

Part 1: Introduction
First of all, your probably wondering what exactly advanced programming is. For our purposes, we can define advanced programming as the ability to use all the available facits of the TI-Basic to create quality and technicaly complex games. In order to do this you must understand how the calculator uses the commands on a very low level. To use TI-Basic to make quality games you have to know what your doing. Since ASM programming is very fast, you have to be able to program very intelligently to make quality games that will compete with them. The purpose of these tutorials is to explain several advanced programming techniques. By starting at game design and ending at 3-D programming. It explains mainly the theorys behind these techniques and not the exact syntax of things.

For these tutorials it is assumed that you already know how basic basically works. If you don't know the syntax and how to use things like 'If' statements or 'Lbl's' then you should go read the many other Basic Tutorials out there on the web.

Part 2: Designing a Game


To start making any game at all, you must layout the basic idea. This becomes very important when you start making very large games. For example, if you wanted to make a racing game then you would start out by creating a diagram as follows:

While this may seem like a wast time, it is important to make complex games. Without this step it is harder to make the game, and your code might become sloppy. and it is very important to have organized code. It will make your game faster and better.

While it may seem logical and easier to use goto statements, these are actually EVIL! To create a game that runs fast you must leave out all Lbls. The reason is that whenever the calculator hits a goto statement, it starts at the very top of the program and searches down through the program until it finds the label. If you have a large program then this process can become very slow. I guarantee that it is possible to write any program w/o Lbls. As long as you don't use labels in the engine then it wouldn't really mater if you used them to start your program. And you have to use Lbls for Menus.

A subroutine is just a program that a certain program calls on to do a particular task. When you become an experienced programmer then subroutines will become your best friend. Programming with subroutines creates very easily readible code. It also helps in the debugging phase. If you had one program and it was 5000 bytes, then it would take you about 2 minutes to scroll to the bottom. This is very inefficent. The main program should only call upon other programs to do stuff. If you do this then the code will be easily updated and debugged. However, when you finish your game, and prepare to release to one of the major TI sites, you may want to compile it. By doing this I mean putting all the program together. Just go to the spot in the code where you called the program, clear that line, and hit 2nd Recall, then Prog, go over to the EXEC menu and select the program that is called. This will paste your code to the spot inside the code that the cursor is at. The reason behind this is that when kids are trading programs at school they won't know what programs to transfer. And if the other guy only gets 1 of 2 programs, then he will not think well of your program. However, dont sacrifice any game speed to do this.

Part 3: Optimizing Code

Storing Vars:
The basis of programming anything is the ability to manipulate data in such a way as to do a desired task. And perhaps one of the most common commands in TI-Basic is the -> command. This command, obviously, stores something into the memory location specified, but through running benchmark tests I have found that the main thing that slows down any game the most, is storing vars. This function takes a very long time when you use it multiple times with in a loop. So to optimize your code you should remove as many stores as possible.

Binary Operators:
I don't really know what you would call these, but since they are binary, and have operators, I will call them Binary Operators. What am I talking about? Here is an example:

On the homescreen enter:

As you can see, these operations return two possible values. Either 1-true or 0-false. This can be to replace certain if statements in a program. Here is an example of code that is not optimized:

This code is from a nibbles type game where the front component must keep moving, so when a new key is pressed, old keys must be reset and one stored with value of movement (either - or +).
Note: s-change in x, t-change in y.
The same code optimised:
If K!=0:then
If K=24
If K=26
If K=25
If K=34
If K!=0:then

As you can see, that is a lot shorter. But more importantly, also much faster. In the later only two storages are used, where in the other there will be three.The later code performs just as many condicional operations as the first, but the later code is much shorter, this is important because space on the calcultor is very limited.

However, this method is not always faster. If you use this instead of an if statement that doesn't have to store a variable every loop, then it will actually go slower. This is because it may unnecesarily storing a zero into a variable instead of just checking a condiconal statement. You have to just experiment with Binary Operators to get good at them.

You can use Binary Operators to replace any If statement that stores a value into a variable:
The same code optimised:
If X=6
If X=6 and Y=4
If X=6 or T=2
//assuming that X and T will not be true at the same time.

Binary condicionals:
Similar to using the binary operator, you can use a regular variable as a binary number. You of course know that 0 is false and 1 is true(actually,any integer is true). Now that you know this you can use it in a game. For instance, you could use it to check a spot in the list.

If L6(1)
If L6(1)=1

Both examples do the exact same thing. Except that the one on the left is a little faster. This could be used to simplify the code and just make it easier to type in.

If you don't understand this stuff:
  1. Reread the tutorial.
  2. Reread it again (throughly, and experiment with the code)
  3. Then I can't write good tutorials, or
  4. You should rethink wanting to program Advanced BASIC

Next Tutorial: Arrays: The Amazing Data Structure.

Written by Brandon Green.

Tutorial is property of Brandon Green, © 2000. Do not use without permision. Algorithms are property of Brandon Green, e-mail for permision to use.

Problems with this page?
Contact the Webmaster.