Different backrounds depending on time of day...

Started by , Fri 12/09/2003 03:49:55

Previous topic - Next topic

ValadSlayer

Can I change the current background depending on the time of day with out using Background Frames (I would like to use the background frames to animate the current screen background).

My goal is to achieve the type of realistic day/evening/night feel similar to Quest For Glory 4.


shaadb

I was wondering if there is a way to change the background of a screen while the character is in it. Depending on the time of day, I would like to have day/evening/night backgrounds.

(not using background frames, I would also like to have animating backgrounds)

I have figured out a little complicated way of doing this, by using 2 of the 5 frames in the background, one for evening and one for night. and then using GetTime to get the time of day and changing the background to the required frame. Then for other screens, once the time is in a certain range, the screen will load with the required frame...

is there any easier way to do this?

Scummbuddy

Wow, you both post the exact same thing within a day of each other.  Which leads me to believe you all did no search what-so-ever of the forums.

Anyways, the best way to do this in my opinion, would be to make your animated frames do what they will, and then set up a timer, and a constant check for its value, such as if its at 3000, then do a TintScreen(); enter some value to get a good dusk color, and then at 5000, do a darker tint, and so on.
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

shaadb

oh, sorry about that, but both posts were done by me, and I didn't know how to erase the previous one, because i wanted to explain it a lil better...

I was thinking about using the tint, and while it is a good way to try it, it won't bring out the desired effect, considering shadows and light source placement (sun rises in one place producing shadows in one direction, and then sets in the opposite place, producing shadows in the opposite direction)

tinting would be useful for darkening a room with a static light source. Any more ideas?

Scorpiorus

There is a RawDrawImage() command you could use then:

QuoteRawDrawImage (int x, int y, int slot)

Draws image SLOT from the sprite manager onto the screen at location (X,Y).
Example:

RawDrawImage(100,100,134);

will draw the image that's stored in sprite manager's slot 134 at the coordinates 100,100.

Timer example:

//main global script:

int day=1; // current day
int hour=1; // current hour
int minute=1; // current minute
int loop=1;   // current loop

// the next intervals affect the time duration:
int minute_time = 40; // [in game loops]
int hour_time   = 60; // [in minutes]
int day_time    = 24; // [in hours]

function repeatedly_execute() {

if (loop > minute_time) { // if loop timer has expired
   loop = 1;
   minute++;
   if (minute > hour_time) { // if minute timer has expired
      minute = 1;
      hour++;
      if (hour > day_time) { // if hour timer has expired
        hour = 1;
        day++;
      }
      CallRoomScript(hour); // calls on_call() function in the current room
   }

} else loop++; // else increase loop timer


}


// every room script

function on_call (int hour) {

 // choose image slot depending on the hourtimer:

 if (hour == 1) RawDrawImage(0,0, <some_slot_value>);
 else if (hour == 5) RawDrawImage(0,0, <some_slot_value>);
 else if (hour == 10) RawDrawImage(0,0, <some_slot_value>);
 else if (hour == 20) RawDrawImage(0,0, <some_slot_value>);

}

How does it turn out?

~Cheers

shaadb

ok. i tried the code and everything, i decided to use SetBackgroundFrame instead of RawDrawImage. but i getting errors when i try to save the room.

i'm not sure exactly how to apply it (scriptwise). I need to set the background frame before the player enters the room so that the background for the time of day will be consistent when moving from room to room. but when i use the on_call function in the script for player enters the room before fadein, i getting errors.

any help on how to get the code to work? and also i need to put the code in the repeatedly execute for the room, so that it will keep on checking the time.

shaadb

here's the code i have so far...

//in the global script

int day=1; // current day
int hour=1; // current hour
int minute=1; // current minute
int loop=1; // current loop

// the next intervals affect the time duration:
int minute_time = 40; // [in game loops]
int hour_time = 60; // [in minutes]
int day_time = 24; // [in hours]

function repeatedly_execute() {
 // put anything you want to happen every game cycle here
 if (loop > minute_time) { // if loop timer has expired
loop = 1;
minute++;
if (minute > hour_time) { // if minute timer has expired
minute = 1;
hour++;
if (hour > day_time) { // if hour timer has expired
hour = 1;
day++;
}
CallRoomScript(hour); // calls on_call() function in the current room
}

} else loop++; // else increase loop timer


}


// in the room script

function on_call (int hour) {

// choose image slot depending on the hourtimer:

if (hour == 1){
DisplayMessage(500);
SetBackgroundFrame(1);
}
else if (hour == 2){
DisplayMessage(501);
SetBackgroundFrame(2);
}
}


function room_a(int hours) {
 // script for room: Player enters screen (before fadein)
if (hours < 1)
SetBackgroundFrame(0);
else if (hours >= 1)
SetBackgroundFrame(1);
else if (hours >= 2)
SetBackgroundFrame(2);
}
----------------------------------------------------------------
the hour == 1 and hour ==2 is just for testing purposes. i need to find a way to get it to decide which background frame to use when the player enters a screen.

also, if i don't specify to set the background when the player enters the room then the background frames keep on cycling.

i don't have anything in the script header. i was trying to put a variable there called hours (which is where the room script code for entering calls it). and that value is the same as the "hour" variable.

but i don't know how to do that.

shaadb

ok guys i fixed it.

it works fine now, i had to create a function in the global script to return the value of "hour". and import that function in the header script.

then the local room script for entering the room checks that value of "hour" and sets the background accordingly.

Scorpiorus

Quotei need to find a way to get it to decide which background frame to use when the player enters a screen.
Ah, yes, sorry. I completely forgot about that.

Quotealso, if i don't specify to set the background when the player enters the room then the background frames keep on cycling.
Yep, it's cycling unless you set the frame explicitly. I think you already figured it out though.

Quoteit works fine now, i had to create a function in the global script to return the value of "hour". and import that function in the header script.
Right way, the on_call() function recieves the hour value through the parameter ( via CallRoomScript(hour); ) whereas room_a() (before fadein) doesn't. :P

~Cheers

shaadb

thanks for the help Scorpiorus and Scummbuddy.

It takes a lil while to get used to the AGS type of coding.

SMF spam blocked by CleanTalk