Here is a new version with Snaking, wavy text working.
Rem Project: scrolling text
Rem Created: 09/01/2006 19:51:24
rem Modified by: Bill Robinson, San Francisco.
Rem ***** Main Source File *****
MAXWORDS=1000 :`stores up to 1000 words in array, increase if needed
dim wordarray$(MAXWORDS) :`array used for word storage
dim wordxy(MAXWORDS,5) :`1=x, 2=y location, 3=word length, 4=animation type, 5=anim data
dim wordcolor(MAXWORDS) :`word color
global wordptr
global spacewidth
global sw
global beginwordptr
global endwordptr
global beginx
global lastx
global arrayindex
sync on
hide mouse
sync rate 60
set text font "impact"
set text size 30
color=rgb(0,100,200),0
ink color,0
data "Once upon a time, there was a boy named Ant, who thought "
data "he would like to try his hand at programming, the only "
data "problem was, he wasn't very good at it, and had to keep annoying "
data "other members of the Darkbasic community, to try and help him out "
data "with his code, but he was always extremely grateful !!!! "
data " Thanks guys, and a Happy New Year to everyone "
data " in the Darkbasic community !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
rem ----- parse words into string array -----
arrayindex=0
for i=1 to 7
read s$ :`reads in 1 data line of text
word$=""
for j=1 to len(s$)
c$=mid$(s$,j)
if c$<>" "
word$=word$+c$ :`builds a word with each character
else
if len(word$)>0
gosub _store_word
rem -------- these lines aren't needed, just here to set some special text settings for testing --------
:`animation type (set wordxy(ai,4)= 0=normal, 1=color change, 2=hopping, 3=snake
ai=arrayindex :`just a shorter variable name for use here
if ai=3 or ai=6 :`3rd and 6th words are GREEN
wordcolor(ai)=rgb(0,255,0)
endif
if ai=13 or ai=19 :`13rd and 19th words are YELLOW
wordcolor(ai)=rgb(255,255,0)
endif
if ai=1 or ai=10 :`1st and 10th words Flashing colors
wordxy(ai,4)=1
endif
if ai=8 or ai=15 :`8th and 15th words hop
wordxy(ai,4)=2
endif
if ai=2 or ai=21 :`2nd words snake, not working yet
wordxy(ai,4)=3
endif
q=rnd(5) :`have random words after word 21, use random animations
if rnd(4)>1
if ai>21
wordxy(ai,4)=rnd(3)+1
endif
else
wordcolor(ai)=rgb(rnd(255),rnd(255),rnd(255)) :`or random colors, yeah I know this is too much
endif
rem ---------------------------------------------------------------------------------------------
word$=""
endif
endif
next j
next i
if word$<>"" then gosub _store_word :`store the last word in array
numwords = arrayindex
`I wanted the last 3 words to Snake
wordxy(numwords-2,4)=3
wordxy(numwords-1,4)=3
wordxy(numwords,4)=3
gosub _init_variables
do
curx=beginx
while lastx<sw
_text_animation(wordptr)
` ink wordcolor(wordptr),0
` text lastx,430-wordxy(wordptr,2),wordarray$(wordptr)
lastx=lastx+wordxy(wordptr,3)+spacewidth
inc wordptr
endwhile
wordlen=wordxy(beginwordptr,3)
if beginx < -wordlen
beginx = beginx + wordlen + spacewidth
inc beginwordptr
if beginwordptr > endwordptr then gosub _init_variables
endif
dec beginx,2
wordptr=beginwordptr
lastx=beginx
sync
cls
loop
rem --- stores each word in string array ---
_store_word:
inc arrayindex
wordarray$(arrayindex)=word$ :`store word in array
wordxy(arrayindex,1)=0 :`x you can set value here, or later in program
wordxy(arrayindex,2)=0 :`y
wordxy(arrayindex,3)=text width(word$) :`length
wordxy(arrayindex,4)=0 :`animation type 0=normal, 1=color change, 2=hopping, 3=snake
wordcolor(arrayindex)=color :`setting text color
return
`You can add any type of animation you want, just by adding another case statement
`and writing the code for the animation you want to happen
`ANIMATION TYPES
`0=normal, 1=color change, 2=hopping, 3=snake
`
`If you want a different color AND animation
`then set the color seperately like this: wordcolor(word number here)=rgb(0,255,255) whatever rgb color you want
function _text_animation(ptr)
animtype=wordxy(ptr,4)
select animtype
` --- color chaging word animation
case 1
zcount=wordxy(ptr,5)
rem --- every 20 times thru loop change color
if zcount>20
wordcolor(ptr)=rgb(rnd(255),rnd(255),rnd(255))
wordxy(ptr,5)=0
else
inc wordxy(ptr,5) :`count each time thru loop
endif
ink wordcolor(wordptr),0
text lastx,430-wordxy(wordptr,2),wordarray$(wordptr)
endcase
` --- hopping word animation
case 2
zcount=wordxy(ptr,5)
if zcount>5
wordxy(ptr,5)=0
inc wordxy(ptr,2)
if wordxy(ptr,2)>10 then wordxy(ptr,2)=0
else
inc wordxy(ptr,5) :`count each time thru loop
endif
ink wordcolor(wordptr),0
text lastx,430-wordxy(wordptr,2),wordarray$(wordptr)
endcase
` --- snaking word animation
case 3
zcount=wordxy(ptr,5)
if zcount>5
wordxy(ptr,5)=0
inc wordxy(ptr,2)
if wordxy(ptr,2)>10 then wordxy(ptr,2)=0
else
inc wordxy(ptr,5) :`count each time thru loop
endif
savlastx=lastx
for qx=1 to len(wordarray$(wordptr)) :`Each character will be output seperately
wordcolor(wordptr)=rgb(0,255,255)
ink wordcolor(wordptr),0
c$=mid$((wordarray$(wordptr)),qx)
y=430-sin(lastx)*10 :`*10 is for the height of the snaking wave, increase for a higher wave
text lastx,y,c$
inc lastx,text width(c$)
next qx
lastx=savlastx
endcase
case default
ink wordcolor(wordptr),0
text lastx,430-wordxy(wordptr,2),wordarray$(wordptr)
endcase
endselect
endfunction
rem --- inits variables, used each time string is restarted ---
_init_variables:
spacewidth=text width(" ")
sw=screen width()
beginwordptr=1
endwordptr=numwords
beginx=sw
lastx=beginx
return
end