HOME >> Tutorials >> Tutorial 5: Scrolling The Entire Screen Left & Right
Advanced Game Techniques Tutorials
Advanced BASIC
Tutorial 5
Scrolling The Entire Screen Left & Right

   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: Strings Make it Possible

String?
Suprisingly enough, perhaps one of the most advanced functions of the TI-83 is also the least known. For those of you who dont know a string is used to store a, well, a string of charachter data. It is very similar to lists, and with the many advanced string operations you can mainpulate it just as you would a list. A string can be any length, it can be infinitely long, or when you run out of memory. As every one knows, when you use the Disp command and you try to disp a message that is wider than the screen you get those annoying little dots(...) and it cuts it off. However, when you use the Output( command to output a string, it automatically wraps the message in the string to the next line. This will come in very handy down below.

String Operations:
Since string operations arent well known, I will list them here. All these operations can be found in the catalog on your calculator:
[note that all these operations can be found in your manual, if you have any syntax questions, consult your manual, believe it or not, you can learn something from reading a book.]

Storing Into A String [->]:
In order to put a message into a string you put what you want to input in quotes, like so: "STRINGS ARE FUN!"->Str1. You could then do a Disp Str1, and STRINGS ARE FUN! would be put on the homescreen. You can also do Input Str1 and then whatever the user typed in would be stored into the string.

Concatenation [+]:
Suppose you had, "HELLO_"->Str1, and, "BOB"->Str2. If you wanted to add these together to create Str3, "HELLO_BOB", you would just type in: Str1+Str2->Str3.

Length (string):
If you had a string and you wanted to know how many charachters were in "HELLO BOB", then you would type Length(Str3) and it would return a 9. You could store this number into a variable for later use by Length(Str3)->S.

Sub(string,begin,length): "ABCDEFGHIJKLM"->Str1
Sub(Str1,4,3)->Str2
Disp Str2
[displays]
DEF
This is used if you want to take just a part of a string and store it into another string. For example:

This is a way to substract parts from a string. You'll understand more after you read the rest of the tutorial.

Part 3: Moving the String

Scrolling:
The basic idea of scrolling is that you have a 'map' that is bigger than the screen. You can then move the point that the screen is centered on to see different parts of the 'map'. By moving the point the screen is centered on over and over 1, you generate the illusions that the 'map' is scrolling by on the screen. Here is an example program that will scroll a string across the screen:

this is written with the TI-82/83/83+ in mind, if your screen is not 16 charachters wide, you will have to change the code.

1:ClrHome
2:"THIS_STRING_IS_MORE_THAN_16_CHAR_LONG."->Str1
3:"________________"+Str1->Str1 //16spaces long
4:For(a,1,45)
5:Output(1,1,sub(str1,a,16)
6:End
2:sets the 'map' (in this case its just a one dimensional 'map') into string 1
3:Since we want to scroll the entire string ALL the way across the string, we have to add this. If we didn't when the for loop got to 30, it would try to take the next 16 charachters to output, but it isnt 46 charachters long, so we would get an error. This prevents that.
4:This is the loop that keeps track of the point at which the screen is looking at the 'map'.
5:What makes this fast and possible is that it outputs everything in one output statement, it takes the position of the screen on the 'map', gets the next 16 charachters, and outputs them.
6:Ends for loop.

As you can see, there is no need to clear the first line because the output statement overwrites it, with a space, every time. By using this same principle you can scroll the entire screen. Here is some sample code I came up with. I didn't provide documentation so you'll have to figure it out on your own.

ClrHome
"*_+_*++*_+_*++*_+_*++*_+_*++*_+_*++*_+_*++*"->Str1
"________________"->Str2   //16 spaces long
6->A
While 1
0->K
While not(getKey)
End
(Ans=26)-(Ans=24)+A->A
If A>27:A-1->A
If A<1:A+1->A
sub(Str1,A,16)+Str2->Str3
Output(1,1,Str3+Str3+Str3+Str3
End
As you can see, with this you can move the entire screen at about 3-4 f.p.s.! This is incredible speed in a basic program.

Dont forget that it auto-wraps the string to the next line when you use strings, this is what is makes it so fast, you output the entire screen in one statement!

For some reason there seem to be no basic games out there that use this technology effectively. Perhaps no knew about it. But dont worry, SiCoDe is working on some very impressive side scrollers... Check the site in the next few months (2/2000 to 5/2000) to get the side scroller when it is released.

Part 4: Condicionals and Strings
Lets say you were working on a game, a frogger game, you already know how to scroll the cars across the screen. So if you put in the loop where you could control a charachter, and you had one whole list outputed to the screeen. Then you check to see if the charachter hit something by:

If (sub(Str1,(16(y-1))+x,1))!="_"

For those non C++ programmers, != means does not equal to. Disp "_" means you hit something!

The (16(y-1))+x converts the two cordinates of the charachter to a position along the screen, it follows this pattern:
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 row 1
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32 row 2
33,34,35,36,37,38,39,40,41,42,43,45,46,47,48,49 row 3
113,114,...,128 row 8
(each number represents a charachter position along the screen)

This formula would only work if your string was outputed at 1,1. But it would be easy to change the formula to whatever you wanted.

In this way you could have hit detection using strings. And here is a sample program so that you can understand this better. Note that this is not optimised or anything, I threw it together in 3 minutes, so yes, it could be made a heck of alot better.

"_____(---)__(++)_____(**)__(---)___(///////)__(----)_____(+++)"->Str1
You could put any string here that is more than 20 charachters long
"________________"->Str2 16 spaces
5->X:8->Y
1->P:1->H
length(Str1)-16->L
While H
Output(Y,X,"*")
sub(Str1,A,16)->Str3
Str2+Str3+Str2+Str3+Str2+Str3+Str3+Str2->Str4
Output(1,1,Str4)
getKey->K
If K:Then
(K=26)-(K=24)+X->X
(K=34)-(K=25)+Y->Y
End
If (sub(Str4,(16(Y-1))+X,1))!="_" does not equal a space
0->H
A+1->A
If A=L
1->A
End
Output(Y,X,"X")


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: Advanced Graphics.

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.