ticalc.org
Basics Archives Community Services Programming
Hardware Help About Search Your Account
   Home :: Archives :: News :: Feature: Two-Dimensional BASIC Scrolling

Feature: Two-Dimensional BASIC Scrolling
Posted by Nick on 8 March 2000, 01:23 GMT

Brandon Green of SiCoDe Software is the first person to take the mic in this feature concerning two-dimensional scrolling in a BASIC program. Hopefully it can teach you a thing or two about BASIC programming and how strings work.


SiCoDe Software has recently discovered a method to scroll the entire screen at four frames per second. One example of this technology is the TI-83 BASIC game Frogger. The method envolves using a seldom exploited function called a string. [Strings are frequently used in BASIC programs, just not in this specific way. -ed.]
A tutorial of how we did it follows:


ADVANCeD.BASiC Tutorial:
Scrolling the Entire Screen From Left To Right


Part 1: 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, 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)- This is used if you want to take just a part of a string and store it into another string.
For example:
"ABCDEFGHIJKLM"->Str1
Sub(Str1,4,3)->Str2
Disp Str2
[displays]
DEF

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

Part 2: 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_CHARACTERS_LONG."->Str1
3:"________________"+Str1-
>Str1 //16
spaces 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 isn't 46 characters 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 characters, 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 FPS! This is an incredible speed in a basic program.

Don't 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 3: Conditionals and Strings

Let's say you were working on a game - a frogger game - and you already know how to scroll the cars across the screen. So if you put in the loop where you could control a character, and you had one whole list outputed to the screeen. Then you check to see if the character hit something by:

If (sub(Str1,(16(y-1))+x,1))!="_" //for those nonC++ programmers, != means does not equal
disp " you hit something!"

The (16(y-1))+x converts the two coordinates 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 character 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 a lot better.

"_____(---)__(++)_____(**)__(---)___(///////)__(----)_____(+++)"->Str1 //you could put
//any string here that is more than 20 characters 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"

There is also a 2-D scrolling engine which SiCoDe has invented. You can expect more advanced scrolling games from SiCoDe in the future.

 


The comments below are written by ticalc.org visitors. Their views are not necessarily those of ticalc.org, and ticalc.org takes no responsibility for their content.


Re: Feature: Two-Dimensional BASIC Scrolling
PacMak  Account Info

wow, thats incredible! i wish i had thought of it!

-pac

     8 March 2000, 01:52 GMT


Re: Re: Feature: Two-Dimensional BASIC Scrolling
yosweetlady  Account Info

Anyone here know ¹ past th 27th decimal place?
3.141592653289793238462643383...?

     10 March 2000, 01:45 GMT

Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
yosweetlady  Account Info

oops, I made a mistake in that. that's 3.141592653589793238462643383

     10 March 2000, 06:19 GMT

Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
PacMak  Account Info

what dose that have to do with this? and why did you reply to my message?

-pac

     10 March 2000, 21:46 GMT


Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
EvanMath
(Web Page)

3.
1415926535 8979323846 2643383279 5028841971 6939937510 5820974944 5923078164 06286

That's all I have memorized, and it's possible I made a mistake typing, but you can click on the URL.
Click on the "RJN's More Digits of Irrational Numbers Page" link, and pick the number and length of you choice. He also has a good "comedy of science" page, with funny storys such as "Interview with Sol" and "Star Trek: the Last Generation".

     10 March 2000, 21:47 GMT


Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
programerman

okay, here we go...

3.141592653589793 23846264338327950288 419716939937510... That's fifty. I can't remember past that right now.

     11 March 2000, 23:26 GMT

Re: Feature: Two-Dimensional BASIC Scrolling
Adam Vore Account Info
(Web Page)

hey, I was fooling around w/ the person next to me's calc in 2nd period today..
and I thought of this... guess I wasnt fast enough... then I came home, and I see this... I was like "WOW!" we were thinking of the same thing...
I'll program a good side scroller tomorrow in 2nd period... then If I can ever get it uploaded to my computer, I'll post it...
well, see ya'll
Peaze (-<)

     8 March 2000, 01:52 GMT

Re: Re: Feature: Two-Dimensional BASIC Scrolling
Horse_Power Account Info

actually I thought of it a long time ago. More than a year ago but I just now joined SiCoDe and told them about this.

     8 March 2000, 02:56 GMT

Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Adam Vore Account Info
(Web Page)

ya, this was a really great idea... unfortunately I dont own a TI-83, just a stinkin TI-82, the BASIC language on the 82 is much more limited, so its really hard to create good programs... but it can be done... I messed around with writing dec code to a matrix and writing a routine that decoded it to a string, but that was impractical and very SLOW! so I deleted it... the best language for the TI-82 is asm... but for the 83, BASIC and asm are very comparable and I love it... I forgot that tomorrow I am having a test in 2nd period, so I cant program anything :( but when I get some time, I'll make a game... my next production for the 82 is Oregon Trail... I'll see how it turns out, and if its good enough, I'll release it.. soon I will release BASeBALL 2000 in BASIC which is one of my better accomplishments. also, I am working with a ti82 without link capabilities... so bear with me while I type line for line, the code for BASeBALL into my computer and upload it... sorry about the length.. I get a little carried away here sometimes...

     8 March 2000, 08:31 GMT


Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
brentes
(Web Page)

You know, it's not who thinks of it first, but who actually applies and uses it who needs to get the credit for it. Also, it doesn't matter if you thought of it a year ago, because you both eventually thought of it, and it was the same idea. It's who puts out the game first who actually should get the credit. In this case, you win, but your argument wasn't really needed.

     8 March 2000, 13:40 GMT


Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Frederic Merizen  Account Info

You're right, I remember seeing a similar technique on the HP48 (in RPL) years ago, but the point is that he rediscovered the technique, and he brought it to good use (they were just scrolling a text on th HP, whereas he is making games)

     8 March 2000, 18:45 GMT


Re: Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
EvanMath

Actually, I personally prefer to use ASM for the display, and BASIC for the rest of the program. For example, in a puzzle game I wrote called Boulders, I used a list (actually, it worked almost exactly like the way strings are used in the feature, maybe I'll change it to use a string instead...) to store the level, and two variables, X and Y, to give the coordinates of the screen. Then I wrote an ASM routine to fetch the variables X and Y, and used a ROM call to read that element of the list, and display the corresponding graphic in the upper left corner. Then it moved on to the next element, and so on until it displayed the whole screen. This way, I had a two dimensional side-scroller in BASIC with a superfast display.
But that's just my way of doing things.

     9 March 2000, 23:13 GMT


Re: Re: Feature: Two-Dimensional BASIC Scrolling
Robert Maresh  Account Info
(Web Page)

Hey, yea. I also tried this, once. I had this "Mario" game where you scroll using strings; the problem with it though, was that it had no concept, it didn't seem practical to me (at the time) and so I eventually deleted it (sadly). I see now that it was worth it.

Speaking of strings, they really are very valuable. Almost every program I write currently uses them.

Bob Maresh
Kevtiva Programmer

     8 March 2000, 04:28 GMT


Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Gary Huyser  Account Info

I had made a mario game also about two years ago that was side scrolling. It wasn't very good because there isn't much you can do in BASIC but it still wasw mario. but then i deleted it. I also had made a big rpg called Order of the Griffin 2 it was a really good game, story and all, used a scrolling engine but right when i finished i was messing with some asm and it got erased...i was mad but then i got over it.

     8 March 2000, 14:58 GMT

Re: Feature: Two-Dimensional BASIC Scrolling
James abba shalaka Rubingh  Account Info
(Web Page)

Why is the 'i' and 'e' small in the title of the tutorial?

also, nice work fellas...

     8 March 2000, 02:01 GMT

Re: Re: Feature: Two-Dimensional BASIC Scrolling
Max Seckel  Account Info
(Web Page)

the 'i' and the 'e' are small because thats how we write them!

Max Seckel
SiCoDe Member

     8 March 2000, 02:12 GMT

Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Nick Disabato  Account Info
(Web Page)

Yeah, you SHOW THOSE VOWELS!
Put them in their place.

--BlueCalx

PS: j/k :p

     8 March 2000, 02:44 GMT


Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Max Seckel  Account Info
(Web Page)

lol...if you want the real explanation its on our webpage someplace, i just dont remember where, try the (i)nfobase......

     8 March 2000, 02:50 GMT


Re: Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
David Hall  Account Info
(Web Page)

Copied and pasted...

The SiCoDe logo (SiCoDe) started out with this mixture of upper and lower case letters as when SiCoDe was concieved, we thought the "S", "C", and "D" could not be represented in lower case on the TI-83. Later, we were proved wrong when we "discovered" the "VARS -> Statistics -> EQ" menu...

     8 March 2000, 19:32 GMT


Re: Re: Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Joe Pemberton  Account Info

You dont have to use the things in the VARS menu. Heres a little program that lets you type lower case letters. Run once and you can type lower case, run it again and it will turn lower case off.
Note: the "0" is zero, not oh

PROGRAM:A
:AsmPrgm
:21148A3E08AE77C9

type AsmComp(prgmA,prgmLOWER) in the home screen and press enter
to run the program type Asm(prgmLOWER)

     6 May 2000, 06:14 GMT


Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Erich Oelschlegel  Account Info
(Web Page)

Why did you leave out the "o"?!? Are you anti-"o"?
<g>

~ferich

     8 March 2000, 03:19 GMT

Re: Re: Feature: Two-Dimensional BASIC Scrolling
Horse_Power Account Info

I and e are some of the only lower case letters you can type on-calc. Our 'o' is actually a degree sign. We dont like vowles because they break the rules of english quite often.

     8 March 2000, 03:03 GMT


Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
johnmcd3

no, under vars -> stat -> some menu in there you can get a, b, c, d, e, and f i think.

     8 March 2000, 06:36 GMT

Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Max Seckel  Account Info
(Web Page)

yes, you are right. but, when david and matt were thinking of a name for SiCoDe they didnt know about that menu.

     8 March 2000, 12:23 GMT


Re:
DWedit  Account Info
(Web Page)

SiC°De is spelled S-i-C-(Alt-0176)-D-e?

     9 March 2000, 05:19 GMT

Re: Re:
David Hall  Account Info
(Web Page)

Yeah, actually you're right :)
Have to remember that one...
- David Hall
SiCoDe Member

     9 March 2000, 20:03 GMT


Re: Re:
Adam Vore Account Info
(Web Page)

SiC°De can also be spelled S-i-C-(Alt 0+1+4+5+6)-D-e

     12 March 2000, 00:52 GMT


Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Jim Haskell  Account Info
(Web Page)

You can get n, a, b, c, d, e, r, p, z, t, and s from the var:stats menu. combined with i, u, v, w, and the degree sign, you can get a lot of lowercase characters without using ASM =)

     9 March 2000, 23:45 GMT


Re: Re: Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
Reno  Account Info

man, you 83 users are pretty creative (and seemingly have a lot of time on your hands as well :P)

thank goodness my 86 & 89 have lowercase home-screen accessable

     10 March 2000, 00:47 GMT


Re: Re: Feature: Two-Dimensional BASIC Scrolling
special[k]  Account Info
(Web Page)

Two words:
Inferiority Complex

special [k]

     8 March 2000, 04:22 GMT

Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
David Hall  Account Info
(Web Page)

Two words... No Way
We're better than you :)

     8 March 2000, 19:33 GMT


Re: Re: Re: Feature: Two-Dimensional BASIC Scrolling
CiDirkona  Account Info
(Web Page)

Vowels are evil.
Thank you.



-Colin

     8 March 2000, 21:41 GMT

1  2  3  

You can change the number of comments per page in Account Preferences.

  Copyright © 1996-2012, the ticalc.org project. All rights reserved. | Contact Us | Disclaimer