can somone check this code for me?
Displaying 1-16 of 16 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
relaxis

The code for my splash screen. I used while functions within switch control branches...would this work? -


void Autoexec()
{

int introsong=loadSong("intro.mp3");
playsong(introsong);

int splash_image = LoadImage("splash1.gif");
int splash_image2 = LoadImage("splash2.gif");
int titleimg = loadimage("title.gif")
int splash_timestamp = systemtime;
while (systemtime - splash_timestamp < 300)
{
RectFill(0, 0, ImageWidth(screen), ImageHeight(screen), (255,255,255), screen);
SetLucent(100 - (systemtime - splash_timestamp));
Blit(0, 0, splash_image, screen);
SetLucent(0);
ShowPage();
}

switch (systemtime - splash_timestamp)
{
case 500: while (systemtime - splash_timestamp < 800)
{setlucent(100 - (systemtime - splash_timestamp));
Showpage();
}

Case 900: Freeimage(splash_image);
while (systemtime - splash_timestamp < 1200)
{
Blit(0, 0, splash_image2, screen);
SetLucent(0);
ShowPage();
}
Case 1400: while (systemtime - splash_timestamp < 1700)
{setlucent(100 - (systemtime - splash_timestamp));
Showpage();
}

Case 1800: while (systemtime - splash_timestamp < 2200)
{
Blit(0, 0, title, screen);
SetLucent(0);
ShowPage();
}
}



}

Posted on 2006-07-11 09:21:08

Overkill

I can safely say, no it wouldn't :D It would mostly require getting rid of the very unnecessary switch/case blocks, but I'll see if I can't try and fix what you're attempting to do.

Also, on the forums use the pre tag instead of the quote tag for code snippets. It's easier to read monospaced text.

Posted on 2006-07-11 11:06:31

relaxis

Dammit. And I thought I was being clever. You see with the code before the switch makes the splash image fade in. I have no idea how to get around making it fade out again. I tried everything. The main problem is that once the while function is over, if I were to add another while function to make the image fade out and then be freed - VERGE would try i load and fade in the image between 0 and 3 seconds at the same time as making it fade out between 0 and 7 seconds. CRASH

I then tried to use FOR loops but i just don't get it. I really need to be babied in this language...*blubbers and spits all over keyboard*

Posted on 2006-07-11 11:20:33

Overkill

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();
}
}

Posted on 2006-07-11 12:15:43

relaxis

I'm a complete 'tard - which section of code draws the images in and which part is defining the image string?

Also...SplashFadeImageIn - where was this defined? or is it built into VERGE?

Posted on 2006-07-11 15:41:50

mcgrue

"SplashFadeImageIn" was defined right there in the code he wrote for you.

it's declaration is the part that starts "void SplashFadeImageIn"

Have you made a working demo yet? It seems you may need to do some brushing up.

Posted on 2006-07-11 16:55:47

relaxis

ok...for some reason the font map fades in as the first image and then fades out...now...to correct that without messing up the code...

Posted on 2006-07-11 17:39:24

relaxis

dammit I just can't figure it out. I can't stop the font map from loading up as the first splash screen image without the "start game" thing disappearing or creating compile errors.

Posted on 2006-07-12 07:05:55

Code

If you copied it all to your .vc file without changing it, the first splash screen would be the font map. That's what splash_image is defined as.

// Replace with filenames of images you're using!
int splash_image = LoadImage("font1.png");
...

Just replace font1.png with the path to the image you want to use.

Posted on 2006-07-12 08:10:01

relaxis

*dopeslaps himself*

Posted on 2006-07-12 08:23:37

Overkill

What are you using to edit your code? It sounds like you're probably using something without syntax highlighting if you're having that much trouble noticing the comments.

Posted on 2006-07-12 11:43:15

relaxis

Hehe - notepad. It's simpler when you start something off at work and then go back to it at home (i can't install progs from my workstation at work and can only send and receive document files).

There's just something really old school about notepad - I programmed my site in notepad.

Anyway, is there an IDE that you recommend?

Posted on 2006-07-12 12:55:45

Overkill

I'd recommend Textpad! The VergeC syntax highlighting file for it can be found in the file section of verge-rpg with minimal search efforts.

Posted on 2006-07-12 18:10:43

mcgrue

...I need to make a freaking piece of board code that auto-breaks and propertly tabs anything in a pre-block > 80 cols.

Sewiouswy.

Posted on 2006-07-13 12:54:24

Gayo


/^--^\ /^--^\ /^--^\
\____/ \____/ \____/
/ \ / \ / \
| | | | | |
\__ __/ \__ __/ \__ __/
|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^\ \^|^|^|^/ /^|^|^|^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |\ \| | |/ /| | | | | | \ \ | | | | | | | | | | |
####################################################################################/ /######\ \###########/ /#######################
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | \/| | | | \/| | | | | |\/ | | | | | | | | | | | |
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|

Posted on 2006-07-14 21:34:52

Overkill

D'aww. Cute kitties ;_;

Posted on 2006-07-14 21:57:36 (last edited on 2006-07-14 21:58:09)


Displaying 1-16 of 16 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.