Day to Night code help...
Displaying 1-20 of 28 total.
12 next
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Rysen

Okay, I'm stumped...and was hopeing one of you coding guru's could help me out.

I'm coding the "Day and Night" code for Rysen Ranch, and I can't think of a good way of doing this. I know it's entirely possible but as I've stated before I'm only a mediocre coder so last time I just used the day and night script Mythril made in v2, which uses palettemorph. Any thoughts about how I go and do this in v3?

I've thought about using a giant rectfill and playing with the lucent settings, or just creating a big black image that would fill the screen and play with its lucent settings using my time-of-day variables, but I'm not sure how well either of those would work, as I'm using vec's circlefade's from the pack-in as my screen transition. I'm just assuming that using SetLucent would affect any other drawing functions/images in use. I also don't want it to affect my textbox....

Any and all would be greatly appreciated!

Posted on 2004-08-19 09:46:43 (last edited on 2004-08-19 09:49:00)

Zip

I'm certain some kinda overblit is going to be the only practical way of doing this, but depending on how you have things set up, you'll probably need to HookRender it. Bug me on #vergehelp and send code I'll try to give you a hand.

Zip

Posted on 2004-08-19 10:02:21

Omni

...Hmm. Here's what I do for a tinter.

Essentially, I'll assume that if you could tint the screen just as with PaletteMorph, you'd be satisfied?

That's pretty easy...

Make a function, TintScreen().

Then, have a SetTint(int r, int g, int b, int a) function that sets the global tint variables.

Then, just have it set the lucency to A alpha/lucency, draw a rectangle over the screen with R red, G green, B Blue, and then set the lucency back to normal.

Your textbox itself probably calls its own SetLucent() command, so it will always be the proper lucency. As long as you set lucency back to 0, then everything else should work fine.

Call this in a loop after the Render() command, or with HookRetrace. This is what I use for the fades and tints in Love Revolution, which is under V2.6 right now, but the same idea applies.

Also, have you thought about using the system hour/minute variables for a real-time game? It would completely break the Harvest Moon scaled-down day gameplay feel, and would add an Animal Crossing flavor, but it's just an idea.

Does this sound okay?

Main Game Loop

{
Updatecontrols()
(insert gameplay whatever else for your main loop)
(draw gameplay graphics with render, etc.)
TintScreen()
ShowPage()
}


Also, sometimes you need the tint to slowly come back to normal, right? Well, at lucency = 100, there will be no tint since it's completely translucent. So, to remove tint, create something like:


void Normalize()
{
if (global tint lucency is less than 100)
global tint lucency ++
}


Then, call that in your game loops too.

Main Game Loop

{
Updatecontrols()
Normalize()
(insert gameplay whatever else for your main loop)
(draw gameplay graphics with render, etc.)
TintScreen()
ShowPage()
}


This way, whenever you create a tint, when the main game loop takes control, it will slowly fade back into view.

Also, when you need a fadeout:


Void FadeOut()
{
SetTint(color_r, color_g, color_b, 100)
while (global tint lucency > 0) //ie, while we aren't completely faded...
global tint lucency --
(render game screen)
ShowPage()
}




Does this make sense? You create fades with FadeOut, you recover from a fade with normalize, and you draw the current fade using a single translucent rectangle over all screen data.

In fact, I made a new UpdateScreen() function for Love Revolution, that automatically draws the tint rectangle and then calls ShowPage(), so I don't have to call them both separately. The above is almost the exact method used for all fades in Love Revolution.

Posted on 2004-08-19 16:57:22 (last edited on 2004-08-19 16:58:01)

vecna

rather than using a rectfill with setlucent, another approach that might provide better visual results is to use ColorFilter(CF_BLUE). You can use setlucent on that if you dont want it to be complete. You can play with it other ways too, you can partially mix CF_GREY to kind of fade out the colors and then use a lucent rectfill to make it darker or something if you wanted a more realistic 'night' look. And by being able to dynamically change the lucent effect of both components you could make the day to night transision be completely fluid and gradual, visually.

Posted on 2004-08-19 17:31:09

Zip

Remember this is on a map Omni, so there IS no gameloop.

Also, I'm with vec on the colourfilters, I've been playing with them recently. I'd use all three rgb on varying lucent values, up the redish for sunrise/set, up the blue for night and so forth. Could even add weather effects, overcast days vs sunny days or something :)

Zip

Posted on 2004-08-19 17:44:26

Omni

On a map, HookRetrace Normalize and TintScreen.

or, since the player can be controlled while entities are processing within a loop, do it within a loop anyway.

Posted on 2004-08-19 18:10:10

Gayo

Someone mentioned something I've thought about casually: if you DO want to tint a rectangular area (and colorfilter isn't an option), is it better to blit a rectangular image or use RectFill?

Posted on 2004-08-19 18:57:31

Rysen

Thanks for all the replies and suggestions. I'm heading out the door now for work, but I'll definately try them out when I get home.

Omni: I *have* thought about using the system time variables, but I don't think the Animal Crossing feel would suit it. If you went to bed at 1pm, you would wake up at 1pm and there's just something about a farmer getting up at 1pm that doesn't feel quite right. :P There are also a couple of other aspects where I didn't feel that it suited it, but I can't remember them now....*shrugs* Thanks for the suggestion though. :) And feel free to give me more. I've all ready added a few things you suggested in the old thread about the game. ^_^

Posted on 2004-08-19 19:22:39

Technetium

You might also be able to get a really nice effect by making a NewImage the size of the screen, filling it with a medium yellow color (say, rgb(182,128,0)), drawing several concentric circles of varying translucent black around where the main character will be positioned on screen, and then hookretracing the whole thing, blitting that image to the screen using SubractiveBlit. Subracting yellow will darken towards blue, and subtracting black leaves the background pixels the same color.

I was thinking of doing something like this for another game.

Posted on 2004-08-19 21:08:03

Interference22

Alternatively, now we have runtime-configurable layer lucencies, you could have a layer with the nighttime effects on (allowing you to do funky stuff like light halos and the warm glow of fires from within buildings conveniently) and simply alter its lucency value every couple of timer cycles (or whenever it's appropriate).

I plan to be giving this system a shot when I get back to programming Perceptions, my mouse-based pseudo-Sci-fi RPG with funky weather effects and 640x480 graphics and whatnot.

Posted on 2004-08-19 23:19:38

Rysen

Got it.

I decided to go with Interference's suggestion, and it works exactly the way I want it to.

Thanks again for all the help. ^_^

Posted on 2004-08-20 01:06:14

Interference22

No problem. I moaned for that feature for ages and now we have it I'm not only over them moon but way past Jupiter and Neptune. Figuratively speaking.

Posted on 2004-08-20 01:24:24

Kreplyn

Hey cool can we keep this as a sticky plz? So later ppl who want to know the code for Day to Night can come look at this? Where is rpgking when you really need him?... sigh.

Posted on 2004-08-20 03:04:44

Omni

Interference...that's genius!

Posted on 2004-08-20 05:24:06

gannon

the day/night code is done differently in dragon warrior (the scenery darkens but the people stay the same)
this is easily done by changing the vsp

Posted on 2004-08-20 05:33:44

Interference22

Can I just take this opportunity to thoroughly pimp configurable layer lucency? Yay.

It's useful for a whole lot of stuff since we have an upper layer limit far higher than anyone with ever reach. So you can have house roofs that fade away as you enter them, a Brigadoon-style village that fades out of existence at daybreak, a The Time Machine-style aging of scenery as you watch a cottage rapidly degrade from newly built to cracks fading into the paintwork and holes breaking out all over the thatch or even something as simple has fading walkbehinds so the player can be seen behind them.

Configurable layer lucency rocks!

Posted on 2004-08-20 23:08:16

Gayo

I personally like the subtractive blit idea, if only because it's such a weird way to do it.

Posted on 2004-08-21 06:54:09

rpgking

I played around with some Day/Night code a bit last night and was fairly successful in getting a Dragon Warrior/Breath of Fire-style system to work. This is where the character sprites don't change in darkness, but the map does. Like gannon said, all this requires is altering the VSP only when a day/night transition occurs.

I'm feeling generous so here's the sourcecode:


void Day_Night(int darkness)
{
int alpha_tiles;
int filter_tiles;

alpha_tiles = NewImage(ImageWidth(curmap.tileset), ImageHeight(curmap.tileset));
filter_tiles = DuplicateImage( curmap.tileset );

// apply blue color filter with varying strength to filter_tiles
SetLucent(darkness);
ColorFilter(CF_BLUE, filter_tiles);

// create the alpha image (easy way to preserve transparent areas of tileset)
Silhouette( 0, 0, RGB(255,255,255), curmap.tileset, alpha_tiles);

// finally, alpha blit our final day/night image set to the tileset
AlphaBlit(0,0,filter_tiles, alpha_tiles, curmap.tileset);

FreeImage(alpha_tiles);
FreeImage(filter_tiles);
}


Calling Day_Night(10) would produce a "late night" effect. By looking at the code, you can easily see that a lower value for darkness would make for a darker map. Optionally, you can tint the map a little by translucent blitting a rectfilled image with a color of your choice after the filter is applied. Here are some shots of this in action:






Hope that helped somehow.

Posted on 2004-08-21 17:54:46 (last edited on 2004-08-22 05:48:15)

vecna

Thats pretty damn spiffy. If you want it to change dynamically, you should just make a duplicate of curmap.tileset in a global variable.

Posted on 2004-08-21 18:01:29

Omni

That's really cool and good looking.

Posted on 2004-08-21 19:29:55


Displaying 1-20 of 28 total.
12 next
 
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.