Day / Night Cycles?

Started by prototyp3, Wed 18/06/2003 03:54:12

Previous topic - Next topic

prototyp3

Has anyone been able to script day and night cycles in their game?  Is it possible?

I'd need timer constantly running that resets every 24 game hours.  I'm guessing I'd need to have each background an animated sequence, and set which frame (one frame representing day, second frame night) is shown based on time.  

Any insight would be welcome.  I'm a newb, but I figured this question would be best suited to the advanced forum.  Thanks.

gonzalezj

one idea is that you should have a day / night cycle so that if the player is playing at night, it would be night out in the game. If the player is playing during the day, it would be day out, etc. For my idea, you would have to create a clock and jsut have simple "if" conditions to specify if it is day or night.

otherwise, you would have to create the in-game clock and set conditions for the times of the clock. great idea, but I have no idea of how I would go about scripting it.

cheers,
Gonzalezj  :)

juncmodule

#2
Code: ags

string d_sec;
string d_min;
string d_hours;
string d_day;

//////////////////////////////////////////////////////////// 
//Timer
////////////////////////////////////////////////////////////
int timer=0,sec=0,min=0,hours=12,day=1;
function time() { timer+=1;
if (timer>=GetGameSpeed()) {
  sec+=5;
  timer=0;
        if (sec>=60) { 
        min+=1;
        sec=0;
        if (min>=60) {
        hours+=1;
        min=0;
   if (hours>=60) {
        day+=1;
        hours=0;} 
   }
        
    } 
}
}
//////////////////////////////////////////////////////////// 
//Timer
////////////////////////////////////////////////////////////


This is a timer Spyros posted that I modified. It should work with some minor modifications for what you are doing.

Good luck,
-junc

deltamatrix

Yes it is possible! I've done it. I once released a demo that had the feature :).

Day/Night rocks. It might be complicated because theres loads of things to consider. Not just the darkness of the screen but whether the NPCs have gone to bed and whether the shops are shut.

And if the night gradually fades in like mine, you may go indoors and then go outdoors again but the night needs to continue to come while your indoors even if you don't see it through an open window.

Also if you use the AGSflashlight plugin to achieve the right visual effect like me, remember than the current value of the tint or the darkness value DOESN'T SAVE so watch it!
BAD WOLF - TORCHWOOD - MR SAXON - THE BEES ARE DISAPPEARING - PANDORICA - RIVER SONG

prototyp3

Thanks for the assistance!

I'm not planning to keep track of the days, just the time of day.  One game minute would be equal to one second of real world time.  So a game day would pass in 24 minutes.  

I don't see the clock ever stopping, so interiors would have the clock continue counting as usual.

One problem remaining is what to do when a player stays put in one exterior 'room' when it cycles from night to day.  For instance, if I want a police man there during the day, but not through the night.  How could that be handled?

Deltamatrix: do you have that demo around still?  I'd definitely like to take a look at it if you do.

Archangel (aka SoupDragon)

#5
You can do

//on room enter (before fadein)
if(CheckToSeeIfItsDaytime())
 character[POLICE].room = 5; //or whatever number
else
 character[POLICE].room = -1; //get rid of the cop when night

prototyp3

Thanks Archangel.  But if the player is in the room at night (when the cop is not there) and remains in that room until day comes, the cop will not show up unless the player leaves the room and re-enters, correct?  Even so, that's a relatively minor issue.

I'm dumb when it comes to scripting, even scripting as straight forward as this.

TerranRich

That was a problem in QfG4. You could remain in a shop for hours and it would remain open unntil  you left and tried to return. Instead, in the repeatedly_execute function of the room, check to see if it is equal to or above the time that the police officer usually comes in or leaves, then if either is true, write some code to make the police officer enter/leave the room, etc.
Status: Trying to come up with some ideas...

SMF spam blocked by CleanTalk