// new module header
#define MINUTES_PER_MINUTE 1 // in-game time is 10 times faster
enum TimeOfDay {
eTODMorning = 0, eTODMidday = 1, eTODEvening = 2, eTODNight = 3
};
import void TimePasses(int minutes);
import int _minutes; //= 600;
// new module script
// game starts at 10:00 on day 1
int _minutes = 600;
export _minutes;
int _day = 1;
TimeOfDay _timeOfDay = eTODMorning;
export _timeOfDay;
// background tint stuff
DynamicSprite* bgSprite;
DrawingSurface *bgSurface;
void UpdateTimeLabel() {
// display time on label
int hours = _minutes / 60;
int minutes = _minutes % 60;
lblTime.Text = String.Format("%02d:%02d", hours, minutes);
Display("Displaying time on label.");
}
void UpdateScreen() {
// tint screen, update label, etc.
// display TimeOfDay
if (_timeOfDay == eTODMorning) {
//TimeOfDay = eTODMorning;
lblTimeOfDay.Text = String.Format("Day %d: Morning", _day);
//Tint characters & objects
SetAmbientTint(64, 64, 0, 50, 75);
//Tint room background
bgSprite = DynamicSprite.CreateFromBackground(GetBackgroundFrame());
bgSprite.Tint(64, 64, 0, 50, 75);
bgSurface = Room.GetDrawingSurfaceForBackground();
bgSurface.DrawImage(0, 0, bgSprite.Graphic);
bgSurface.Release();
bgSprite.Delete();
}
else if (_timeOfDay == eTODMidday) {
//TimeOfDay = eTODMidday;
lblTimeOfDay.Text = String.Format("Day %d: Mid-Day", _day);
//Tint characters & objects
SetAmbientTint(0, 0, 0, 0, 100);
//Tint room background
bgSprite = DynamicSprite.CreateFromBackground(GetBackgroundFrame());
bgSprite.Tint(0, 0, 0, 0, 100);
bgSurface = Room.GetDrawingSurfaceForBackground();
bgSurface.DrawImage(0, 0, bgSprite.Graphic);
bgSurface.Release();
bgSprite.Delete();
}
else if (_timeOfDay == eTODEvening) {
//TimeOfDay = eTODEvening;
lblTimeOfDay.Text = String.Format("Day %d: Evening", _day);
//Tint characters & objects
SetAmbientTint(0, 0, 128, 50, 75);
//Tint room background
bgSprite = DynamicSprite.CreateFromBackground(GetBackgroundFrame());
bgSprite.Tint(0, 0, 128, 50, 75);
bgSurface = Room.GetDrawingSurfaceForBackground();
bgSurface.DrawImage(0, 0, bgSprite.Graphic);
bgSurface.Release();
bgSprite.Delete();
}
else {
//TimeOfDay = eTODNight;
lblTimeOfDay.Text = String.Format("Day %d: Night", _day);
//Tint characters & objects
SetAmbientTint(0, 0, 128, 75, 50);
//Tint room background
bgSprite = DynamicSprite.CreateFromBackground(GetBackgroundFrame());
bgSprite.Tint(0, 0, 128, 75, 50);
// Now copy it back to the background
bgSurface = Room.GetDrawingSurfaceForBackground();
bgSurface.DrawImage(0, 0, bgSprite.Graphic);
// Clean up
bgSurface.Release();
bgSprite.Delete();
}
}
void TimePasses(int minutes) {
Display("Time passes.");
_minutes += minutes;
// if end of day was reached
if (_minutes >= 1440) {
_minutes -= 1440;
_day++;
}
//UpdateScreen();
UpdateTimeLabel();
TimeOfDay now = ((_minutes + 240) / 360) % 4;
if (now != _timeOfDay) {
_timeOfDay = now;
UpdateScreen();
}
}
function game_start() {
//UpdateScreen();
UpdateTimeLabel();
lblTimeOfDay.Text = String.Format("Day %d: Morning", _day);
}
int _frames;
function repeatedly_execute() {
//Display("Repeatedly exceute.");
if (lblTime.Text == "") {
UpdateScreen();
}
// increase by one
_frames++;
//Display("Frame increased.");
// if a minute of IRL time has passed
if (_frames >= GetGameSpeed() * 60) {
_frames -= GetGameSpeed() * 60;
TimePasses(MINUTES_PER_MINUTE); // advance game time
}
}
Quote from: Khris on Yesterday at 23:13:27You added a call to UpdateScreen() to TimePasses, why? The room background is only supposed to change when the minutes move into a new time of day range, right?
Anyway, the math isn't that complicated. I'm adding 240 (4 hours) so the morning starts at 4. Then I divide by 360 (6 hours) to get the four different values. Near the end of the day, this will result in 4, so I do mod 4 to roll it over to 0.Code: ags DynamicSprite* backup; // AGS will call this each time a room is about to fade in function on_event(EventType event, int data) { if (event == eEventEntersRoomBeforeFadein) backup = DynamicSprite.CreateFromBackground(GetBackgroundFrame()); } void UpdateScreen() { // make a copy of the backup so the tinting doesn't stack DynamicSprite* bgSprite = DynamicSprite.CreateFromExistingSprite(backup.Graphic); // time of day specific code switch (_timeOfDay) { case eTODMorning: lblTimeOfDay.Text = String.Format("Day %d: Morning", _day); SetAmbientTint(64, 64, 0, 50, 75); bgSprite.Tint(64, 64, 0, 50, 75); break; case ... ... } // end of time of day specific code DrawingSurface* bgSurface = Room.GetDrawingSurfaceForBackground(); bgSurface.DrawImage(0, 0, bgSprite.Graphic); bgSurface.Release(); bgSprite.Delete(); }
DynamicSprite* backup;
// AGS will call this each time a room is about to fade in
function on_event(EventType event, int data) {
if (event == eEventEntersRoomBeforeFadein) backup = DynamicSprite.CreateFromBackground(GetBackgroundFrame());
}
void UpdateScreen() {
// make a copy of the backup so the tinting doesn't stack
DynamicSprite* bgSprite = DynamicSprite.CreateFromExistingSprite(backup.Graphic);
// time of day specific code
switch (_timeOfDay) {
case eTODMorning:
lblTimeOfDay.Text = String.Format("Day %d: Morning", _day);
SetAmbientTint(64, 64, 0, 50, 75);
bgSprite.Tint(64, 64, 0, 50, 75);
break;
case ...
...
}
// end of time of day specific code
DrawingSurface* bgSurface = Room.GetDrawingSurfaceForBackground();
bgSurface.DrawImage(0, 0, bgSprite.Graphic);
bgSurface.Release();
bgSprite.Delete();
}
Quote from: EmmaGundersen on Sun 14/09/2025 20:10:17Hm. Once again I see a fun MAGS theme but only after half the month has already passed :/If it helps, I was almost a week late opening this round, so you're not as far behind as you might think.
If I can find the time I'll try to throw together a short entry.
Quote from: Snarky on Yesterday at 22:46:32Quote from: GildedSpaceHydra on Yesterday at 21:56:30The screen is being tinted when time passes. Unfortunately the screen is tinted WHENEVER time passes, so advancing the clock by one minute causes Time Of Day to change and thus the tint.
I don't think the problem is that the time of day changes whenever you advance the clock. I think what's happening is that the screen is being tinted every time you call UpdateScreen, and you're doing that every time you call TimePasses (line 88).
The time of day calculation is not very transparent, but it's dividing the current _minutes value by 360, so it will only change every 6 hours.
And as CW points out, you're doing the tinting wrong, causing the effect to stack. (Instead of drawing the tint onto the background I would suggest just covering it with a semi-transparent Overlay or GUI.)
(I'm more and more thinking that maybe you should just use my module.)
Quote from: Crimson Wizard on Yesterday at 22:28:13Quote from: GildedSpaceHydra on Yesterday at 21:56:30Additionally, every time the tint changes, it seems to stack (like maybe the previous DynamicSprite isn't being removed before the new tint is added: the more time advances, the darker the screen gets).
That is what I was referring to earlier:QuoteYou must make a copy of original background when you enter the room and save it in a DynamicSprite variable for using in drawing, because next time you call "DynamicSprite.CreateFromBackground" it will return a already modified background.
It should go like this:
1. Store and keep a copy of original background in a separate dynamic sprite.
2. When updating background:
a) make a copy of dynamic sprite which has original bg in it
b) tint the copy
c) paste the tinted copy to room background.
Quote from: GildedSpaceHydra on Yesterday at 21:56:30The screen is being tinted when time passes. Unfortunately the screen is tinted WHENEVER time passes, so advancing the clock by one minute causes Time Of Day to change and thus the tint.
By continuing to use this site you agree to the use of cookies. Please visit this page to see exactly how we use these.
Page created in 0.080 seconds with 15 queries.