It's important that you know this, but while loops aren't functions. They're loops. The difference being that a function can be declared elsewhere, and called from other code, and possibly return a value. Loop blocks on the other hand, can't be declared elsewhere and have a condition that must either be met or made false before it will exit. ...Yeah.
Anyway, nitpicking aside, here's a solution to your problem, with less cluttered and repetitve code, not to mention no switch/case nonsense :D.
// Our main font.
int main_font;
void Autoexec()
{
// Replace with filename of font image you're using!
main_font = LoadFont("font1.png");
// Variable width means easier to read and space consuming text is allowed.
EnableVariableWidth(main_font);
// Go to our title screen introduction.
TitleScreenIntro();
}
void TitleScreenIntro()
{
// Replace with filenames of images you're using!
int splash_image = LoadImage("font1.png");
int splash_image2 = LoadImage("kittyoncar.png");
int title_image = loadimage("logo.png");
// Introductory song.
PlayMusic("intro.mp3");
// Make the background color white.
SplashSetBackgroundColor(RGB(255, 255, 255));
// Splash image.
SplashFadeImageIn(ImageWidth(screen) / 2, ImageHeight(screen) / 2, 200, splash_image);
SplashWait(200);
SplashFadeImageOut(ImageWidth(screen) / 2, ImageHeight(screen) / 2, 200, splash_image);
// Another splash image.
SplashFadeImageIn(ImageWidth(screen) / 2, ImageHeight(screen) / 2, 200, splash_image2);
SplashWait(200);
SplashFadeImageOut(ImageWidth(screen) / 2, ImageHeight(screen) / 2, 200, splash_image2);
// The title screen.
SplashFadeImageIn(ImageWidth(screen) / 2, ImageHeight(title_image) / 2, 200, title_image);
// Wait until they press button 1.
while (!b1)
{
// White background.
RectFill(0, 0, ImageWidth(screen), ImageHeight(screen), SPLASH_COLOR, screen);
// Title screen.
TBlit(0, 0, title_image, screen);
// Text that flashes on and off.
if (systemtime / 35 % 2 == 0)
{
PrintCenter(ImageWidth(screen) / 2, ImageHeight(screen) / 2, screen, main_font, "Press Enter");
}
// Now that everything's drawn, update the screen.
ShowPage();
}
SplashFadeImageOut(ImageWidth(screen) / 2, ImageHeight(title_image) / 2, 200, title_image);
// Free the images now that we're done with them.
FreeImage(splash_image);
FreeImage(splash_image2);
FreeImage(title_image);
// Stop the currently playing music.
StopMusic();
}
int SPLASH_COLOR;
// SplashSetBackgroundColor(int color)
// Sets the color that splash images are drawn against.
// Pass: color for background.
void SplashSetBackgroundColor(int color)
{
SPLASH_COLOR = color;
}
// SplashWait(int duration)
// Waits for the duration of time, and simply updates inputs and the timing.
// Pass: duration in centiseconds
void SplashWait(int duration)
{
int splash_timestamp = systemtime;
// As long as the duration hasn't passed
while (systemtime - splash_timestamp < duration)
{
// Update the timer and controls and such, even if
// no graphical changes can be made inside this loop
ShowPage();
}
}
// SplashFadeImageIn(int x, int y, int duration, int image)
// Fades an image in over the duration of time given.
// Pass: Center point of image (x, y), duration in centiseconds, image to fade in.
void SplashFadeImageIn(int x, int y, int duration, int image)
{
int splash_timestamp = systemtime;
// As long as the duration hasn't passed
while (systemtime - splash_timestamp < duration)
{
// White background.
RectFill(0, 0, ImageWidth(screen), ImageHeight(screen), SPLASH_COLOR, screen);
// Gradually fading in. Have fun figuring this out.
SetLucent(((systemtime - splash_timestamp)
* -100
/ duration)
+ 100);
// Draw our splash.
TBlit(-ImageWidth(image) / 2 + x, -ImageHeight(image) / 2 + y, image, screen);
// Restore lucency.
SetLucent(0);
// Now that everything's drawn, update the screen.
ShowPage();
}
}
// SplashFadeImageOut(int x, int y, int duration, int image)
// Fades an image out over the duration of time given.
// Pass: Center point of image (x, y), duration in centiseconds, image to fade out.
void SplashFadeImageOut(int x, int y, int duration, int image)
{
int splash_timestamp = systemtime;
// As long as the duration hasn't passed
while (systemtime - splash_timestamp < duration)
{
// White background.
RectFill(0, 0, ImageWidth(screen), ImageHeight(screen), SPLASH_COLOR, screen);
// Gradually fading out.
SetLucent((systemtime - splash_timestamp) * 100 / duration);
// Draw our splash.
TBlit(-ImageWidth(image) / 2 + x, -ImageHeight(image) / 2 + y, image, screen);
// Restore lucency.
SetLucent(0);
// Now that everything's drawn, update the screen.
ShowPage();
}
}