TGC Codebase Backup



Credits Scrolling by DARKGuy

15th Apr 2004 10:51
Summary

This is a credits scroller for DBC with text fading at the botton and top of the screen and smooth movement :) It also includes instructions on how to implement it in your own code



Description

This is a credits scroller for DBC with text fading at the botton and top of the screen and smooth movement :)

It also includes instructions on how to implement it in your own code :).

If you're gonna use it in your games I ask that you please put my name in your credits :)



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `Credits scroller
`by DARKGuy
`With this you can do scrolling credits like DarkForge did but in a more simple and
`fast way.
`
`I don't mean to offend DarkForge, I'm just showing him a better way to do it, also,
`the ispiration for doing this snippet was his code :).
`
`Also, the lines:
`for index = 0 to 99
`  read tmp$
`  CreditsData$(index) = tmp$
`next index
`
`Were taken from the QuickSort function from Mighty Atom Software. Without that code,
`I wouldn't have learned to use DATA to read credits data. Credits go to him too :)
`
` I hope you can learned a lot with my code snippet :).
`
`Just be sure to put my name in your credits :) (98% of the code is mine).
`
`This is my first contribution to the codebase and isn't any bad, right?
`
`See you in the forums! ;)
`
`-DARKGuy
`=======================================================================================
`INSTRUCTIONS FOR USING IT IN YOUR OWN CODE
`=======================================================================================
`
` STEP 1: You MUST have the 2 arrays here in your code.
` dim CreditsData$(99)
` dim TY(99)
`
` STEP 2: You MUST HAVE the Setup_Credits subroutine and call it from somewhere
`         before your main loop.
`
` STEP 3: You MUST have the variable CreditsSpeed and set it BEFORE YOU RUN THE CREDITS.
`
` STEP 4: You MUST HAVE the Handle_Credits subroutine and call it in a loop where the
`         credits are being shown.
`
` SPET 5: Be sure to DO NOT USE the "a", "col" and "CreditsSpeed" variables in any other
`         place except for functions
`
`=======================================================================================
`We set up the auto camera, the random seed and the sync rate. If you have a fast PC,
`I advise that you put the sync rate in 30 so the text won't be scrolling too fast :).
randomize timer()
autocam off
sync on : sync rate 0
`up to 100 lines (or more if you want! :) )
dim CreditsData$(99)
`TY = Text Y
dim TY(99)
gosub Setup_Credits
gosub Setup_Background
do
   `for the lighting effects
   color backdrop 0
   `we'll just print the FPS
   set cursor 0,0
   print screen fps()," FPS"
   `we'll move the background objects :)
   turn object right 1,2
   pitch object down 1,1
   turn object right 2,1
   pitch object down 2,2
   turn object right 3,2
   pitch object down 3,2
   gosub Handle_Credits
sync
loop
Handle_Credits:
`In this subroutine we'll fade the text near the top and the bottom of the screen to
`make a smooth aparition of the texts, and decrement their Y using CreditsSpeed.
`for every line of text...
   for a=0 to 99
   `...If isn't an empty line or just a return carriage...
      if CreditsData$(a)<>"" and CreditsData$(a)<>" "
      `...If isn't out of the top of the screen...
        if TY(a)>-300
         `we'll increment the Y position of the text using TY for separate Y locatios
         TY(a)=TY(a)-CreditsSpeed
         `white text at start
         ink rgb(255,255,255),0
         `if it's near the top (yeah..it's strange, but 0 isn't the real 0 in screen...)
         if TY(a)>0
            `If it's in the screen and isn't off the bottom of the screen...
            if TY(a)<screen height() and TY(a)>screen height()-(text height("A")+(text height("A")/10))
               `This is a strange formule, made by trial an error. it makes the color from 0 to 255
               `depending on the Y location...
               col=0-(abs(TY(a))*2.55)*2.55
               `we just set the text color
               ink rgb(col,col,col),0
            endif
         `if isn't near the top and it's near the bottom of the screen...
         else
            `another strange formule. This does the same as the last one, but it does it
            `inverse, so from 255 to 0 depending on the Y location...
            col=255-(abs(TY(a))*2.55)*2.55
            `set the text color...
            ink rgb(col,col,col),0
         endif
         `center text   X middle of the screen, the Y of the text, and the text...
         center text screen width()/2,TY(a),CreditsData$(a)
        endif
      endif
   next a
return
___Credits:
`Here are the credits
data " "
data " "
data "DARKGuy"
data "Presents"
data " "
data "A DarkBASIC production"
data " "
data "Starring"
data "DARKGuy"
data " "
data "DARKBASIC CREDITS SCROLLING"
data " "
data "With this you can do scrolling"
data "credits like DarkForge did but"
data "in a more simple and fast way."
data " "
data "Just take a look at your FPS ;)"
data " "
data "I don't mean to offend DarkForge,"
data "I'm just showing him a better way"
data "to do it, also, the ispiration for"
data "doing this snippet was his code :)."
data " "
data "Also, the lines:"
data " "
data "for index = 0 to 99                "
data "   read tmp$                       "
data "         CreditsData$(index) = tmp$      "
data "next index                             "
data " "
data "Were taken from the QuickSort function"
data "from Mighty Atom Software. Without"
data "that code, I wouldn't have learned to"
data "use DATA to read credits data."
data " "
data "Credits go to him too :)"
data " "
data "I hope you've learned a lot with my"
data "code snippet :)."
data " "
data "This is my first contribution to the"
data "codebase and isn't any bad, right?"
data " "
data "Just be sure to put my name in your"
data "credits :) (98% of the code is mine)"
data " "
data "See you in the forums! ;)"
data " "
data "THE END"
`it's for restoring data so it doesn't need a RETURN
Setup_Credits:
`we'll set up the font and load the credits into the array
`no matter what resolution you have, it will appear the same size :)
set text size screen width()/15
set text font "Arial Black"
for t=0 to 99
   `here we'll separate the lines vertically, so they don't appear all grouped up in
   `a single line.
   TY(t)=screen height()+((text height("A")*2.5)*t)
next t
`read data from here
restore ___Credits
`we load the data into the array
for index = 0 to 99
   read tmp$
   CreditsData$(index) = tmp$
next index
`in pixels
CreditsSpeed=1
return
Setup_Background:
`I'm sure you can understand all this...
make object cone 1,0.5
position camera object position x(1),object position y(1),object position z(1)-2
make object cube 2,0.5
make object sphere 3,0.5
position object 1,0,-0.5,0
position object 2,-0.8,0.5,0
position object 3,0.8,0.5,0
make light 1
make light 2
make light 3
position light 1,-2,-2,-2
position light 2,2,-2,-2
position light 3,0,2,-2
set light range 1,100
set light range 2,100
set light range 3,100
color light 0,rgb(0,0,0)
color light 1,rgb(255,0,0)
color light 2,rgb(0,255,0)
color light 3,rgb(0,0,255)
color ambient light rgb(0,0,0)
return