ANALOG CLOCK

Started by katie08cd, Sat 18/01/2020 21:06:15

Previous topic - Next topic

Cassiebsg

I forgot to mention I changed the greyout commands. It's changed in settings "When player interface is disabled, GUIs should". I just set it to Normal, as I I don't like the greyed out that is default to Sierra template. And it made the clock look weird.

Oh, I see. this is what happens when I code and don't test all options.  :-[
Give a me sec to figure out.
There are those who believe that life here began out there...

katie08cd

I did the test, if I set the global at 9 it makes me the background cycle, if instead I put at 6, nothing happens

Cassiebsg

#42
I found the problems,
- The first is that my check for hour was looking for a specific time, that would never be.
- The second wass that the first "check" for the clock come only after the clock reached the first hour, so the clock would show 00 and then jump to 10 after the first hour.

So I fixed it, it now. I'll try and explain how you can fix it (it's just copy/paste & replace in the right place).

Open CustomScripts Script and copy/paste the following code (replace all the lines in the script):
Code: ags

// new module script

void AdjustClock()
{
  if (intHour<=11)Bclock24.NormalGraphic=100+intHour; // 100 is sprite number that corresponds your clock at 00:00 
  else Bclock24.NormalGraphic=100+intHour-12; // Need to remove 12h to get the correct sprite number		
}

void CheckRoomBackground()
{
  if ((intHour<6)||(intHour>=19 && intMinute>=1)) SetBackgroundFrame(0); // Night Background
  else if (intHour==6 && intMinute==0) SetBackgroundFrame(1); // Dawn Background
  else if (intHour>=6) SetBackgroundFrame(2); // Day Backgrund
  else if (intHour==19 && intMinute==0) SetBackgroundFrame(3); // Sunset Background
} 


Now open CustomScripts Header and copy/paste the following code:
Code: ags

import void AdjustClock();



Open GlobalScript and locate the following two lines and replace them with: AdjustClock();
Code: ags

if (intHour<=11)Bclock24.NormalGraphic=100+intHour; // 100 is sprite number that corresponds your clock at 00:00 
else Bclock24.NormalGraphic=100+intHour-12; // Need to remove 12h to get the correct sprite number		


Lastly, open Room40 script and add the same line to room_load and it should look like this:
Code: ags

function room_Load()
{
  AdjustClock();
  CheckRoomBackground(); // this script can be found in Scripts->CustomScripts and it will change the room background acording to the clock at game start
}


Note: This last code you should add when you create a new playable room. Also take notice that if other rooms need to start at a specific time, you can just add a line before AdjustClock();, and type intHour=8; this would make that room to start at 8:00.
I'm not sure how you are planing to set the rooms, but if you have a case per room and they all need to start at 9, then just add the intHour=9; code to the room_Load of all your rooms. If not the clock will continue counting from when it stops (I set it to count if it's visible, so remember to turn it off if the player is accessing a GUI like save or settings...)
There are those who believe that life here began out there...

katie08cd

OMG WOOOW, I set at 9 and the day came * _ * fantastic, thank you very much you do me doing school, before I took a cue from your script so I created one for the deduction room, because I practically have a nice long code and global script it bothered me because it still needed space, so I took a cue from your script and I created mine, I'm too happy, I still created a simple thing, in the deduction room I created the inventory, there are words and you have to drag these words on the suspect, the wrong ones turn red and then the display text says "does not match etc" instead for the right one of each category, the label is displayed, the categories that I invented are 5
opportunity
weapon
test
motive
conclusion

when you have these 5 elements you can incriminate the suspect, also if a category of the type (occasion) if it is correct automatically removes you those are not exact

for each category I created 4 wrong elements

does not seem, but I'm very happy that I created a small script (obviously not at the levels of the master XD) but thanks anyway, and if you want to put your script in the downloads, which by the way is a fantastic thing because it makes the game more openworld if we want, put it well maybe other people need it, thanks again for everything


katie08cd

#44
hello I'm trying the clock and it makes me a strange thing, if I start the room at 6 pm, when it arrives at 9 pm, it sets the background during the day like 9 am, then at 10 pm the night starts again, maybe it doesn't calculate the 24 hours , then I tried to add another 12 sprites but he doesn't see them, if now I want to make a 24 sprite watch (which I think is more precise) what should I do ?, I did the test again now, if I start at 21 it comes always during the day, then it passes at night but at 10 pm it is day again, I send you a new file with 24 sprites already set from 100 to 123, another thing if in the script you want to make a list of the 24 sprites to associate, go ahead, that then I fix them, (always if possible of course) we set the clock to 24 hours with 24 sprites at least we are sure that it counts those, thank you very much

https://drive.google.com/file/d/14Z4nh9mb9oQGnl7RuGgSjnD8QolYjuvY/view

Matti

I haven't followed this thread closely, but I'm not sure about this:

Code: ags
void CheckRoomBackground()
{
  if ((intHour<6)||(intHour>=19 && intMinute>=1)) SetBackgroundFrame(0); // Night Background
  else if (intHour==6 && intMinute==0) SetBackgroundFrame(1); // Dawn Background
  else if (intHour>=6) SetBackgroundFrame(2); // Day Backgrund
  else if (intHour==19 && intMinute==0) SetBackgroundFrame(3); // Sunset Background
} 


I don't really get it, but the last "else if" will never be called.

Cassiebsg

#46
you're right   :-[ try this...  (roll)

else if (intHour>=6 && intHour<=18) SetBackgroundFrame(2); // Day Backgrund

Code: ags

void CheckRoomBackground()
{
  if ((intHour<6)||(intHour>=19 && intMinute>=1)) SetBackgroundFrame(0); // Night Background
  else if (intHour==6 && intMinute==0) SetBackgroundFrame(1); // Dawn Background
  else if (intHour>=6 && intHour<=18) SetBackgroundFrame(2); // Day Backgrund
  else if (intHour==19 && intMinute==0) SetBackgroundFrame(3); // Sunset Background
}
 
There are those who believe that life here began out there...

Khris

#47
Took a look at this, started to make little changes, then some bigger ones :-D

- replaced the clock with a dynamically drawn one
- backgrounds fade into each other now.
- added two functions:  SetClock(int hour, int minute);  and  AdvanceClock(int hour, int minute);
- while debug mode is on, hold down space to advance time really fast

Spoiler

6:18 AM, fading from dawn to day
[close]
Download


Edit: completely OT, but feels necessary to say nonetheless: 800x600 is a really bad choice, given that probably 95% of devices use 16:9 or similar widescreen resolutions now. My monitor is set to Full HD so I can play this either in a relatively small window or with huge black bars on the sides, which is a shame given the beautiful graphics.
I'd consider switching to 1280x720 or 640x360 while you're in the early stages.

Slasher

Nice one Khris  (nod)

You should have included a 'Quit' though...




Matti

Nice work indeed!

I agree that you should use a different resolution (and that the graphics are beautiful  :)).

@ Slasher: There is a quit button in the menu.

Cassiebsg

Cool. :) Take the master to make it better.  :-D
There are those who believe that life here began out there...

katie08cd

#51
hello, thanks for the work, wow and fantastic, ok I understand how to set the clock, thanks,
but unfortunately for this modification I have not given the full version, and I was wondering, is it possible in my map function, yes because the game uses my invention of the map, where you select a place, the carriage comes and takes you to your destination, it is possible to do a time calculation on the map? eg if I leave the office at 9 in the morning and arrive in the place at 11, then I go back to the office, do I always leave from 9? or at 13? thanks, in case of this modification I will send you the whole file, thanks again

I created a new room but it doesn't change the background, do I have to add some commands in fade in, or in the script? thanks, theoretically I asked this works to change the background in each room of the game to have a time effect as you have seen, what command should I use to change the background in each room?

katie08cd

the backgrounds in the other rooms don't go, what command do I have to use? thanks

Code: ags
// new module script

#define CLOCK_CENTER_X 40
#define CLOCK_CENTER_Y 40
#define CLOCK_RADIUS_H 25
#define CLOCK_SPRITE_H 29
#define CLOCK_RADIUS_M 30
#define CLOCK_SPRITE_M 30

enum BGFrame {
  eBGNight = 1, eBGDawn = 2, eBGDay = 3, eBGDusk = 4
};

int seconds, minutes;
int hour, minute;

void DrawImageAA(this DrawingSurface*, int x, int y, int slot) {
  this.DrawImage(x - 1, y, slot, 80);
  this.DrawImage(x, y + 1, slot, 80);
  this.DrawImage(x + 1, y, slot, 80);
  this.DrawImage(x, y - 1, slot, 80);
  this.DrawImage(x, y, slot); 
}

DynamicSprite* clockFace;

void DrawClock()
{
  clockFace = DynamicSprite.CreateFromExistingSprite(28, true);
  DrawingSurface* ds = clockFace.GetDrawingSurface();
  int a;
  
  // hour hand
  DynamicSprite* hourHand = DynamicSprite.CreateFromExistingSprite(CLOCK_SPRITE_H, true);
  a = minutes / 2;
  while (a > 359) a -= 360;
  if (a > 0 && a < 360) hourHand.Rotate(a, hourHand.Width, hourHand.Height);
  hourHand.Resize(CLOCK_RADIUS_H * 2, CLOCK_RADIUS_H * 2);
  ds.DrawImageAA(CLOCK_CENTER_X - hourHand.Width / 2, CLOCK_CENTER_Y - hourHand.Height / 2, hourHand.Graphic);
  
  // minute hand
  DynamicSprite* minuteHand = DynamicSprite.CreateFromExistingSprite(CLOCK_SPRITE_M, true);
  a = minutes * 6;
  while (a > 359) a -= 360;
  if (a > 0 && a < 360) minuteHand.Rotate(a, minuteHand.Width, minuteHand.Height);
  minuteHand.Resize(CLOCK_RADIUS_M * 2, CLOCK_RADIUS_M * 2);
  ds.DrawImageAA(CLOCK_CENTER_X - minuteHand.Width / 2, CLOCK_CENTER_Y - minuteHand.Height / 2, minuteHand.Graphic);
  
  ds.Release();
  gClock.BackgroundGraphic = clockFace.Graphic;
}

DrawingSurface* roomDS;
DynamicSprite* roomBG;

void CheckRoomBackground()
{
  if (player.Room < 40) return; 
  
  int newBottom = eBGDay; // day
  int newTop = 0; // no second layer yet
  int t;
  
  // is it night?
  if (hour < 6 || hour > 18) newBottom = eBGNight;
  // dawn? 
  if (hour ==  6 && minute < 30) newBottom = eBGDawn;
  // dusk?
  if (hour == 19 && minute < 30) newBottom = eBGDusk;

  // fading for 20 minutes each

  // night -> dawn
  if (hour == 5 && minute > 40) {
    newTop = eBGDawn;
    t = (60 - minute) * 5;
  }
  // dawn -> day
  if (hour == 6 && minute > 10 && minute < 30) {
    newTop = eBGDay;
    t = (30 - minute) * 5;
  }
  // day -> dusk
  if (hour == 18 && minute > 40) {
    newTop = eBGDusk;
    t = (60 - minute) * 5;
  }
  // dusk -> night
  if (hour == 19 && minute > 10 && minute < 30) {
    newTop = eBGNight;
    t = (30 - minute) * 5;
  }
  
  roomDS = Room.GetDrawingSurfaceForBackground();
  roomBG = DynamicSprite.CreateFromBackground(newBottom);
  roomDS.DrawImage(0, 0, roomBG.Graphic);
  if (newTop > 0) {
    roomBG = DynamicSprite.CreateFromBackground(newTop);
    roomDS.DrawImage(0, 0, roomBG.Graphic, t);
  }
  roomDS.Release();
  roomBG.Delete();
} 

void Update() {
  if (seconds > 24 * 3600) seconds -= 24 * 3600;
  minutes = seconds / 60;
  hour = minutes / 60;
  minute = minutes - hour * 60;
  CheckRoomBackground();
  DrawClock();  
}

void SetClock(int h, int m) {
  seconds = h * 3600 + m * 60;
  Update();
}

void AdvanceClock(int h, int m) {
  seconds += h *3600 + m * 60;
  Update();
}

int frameCount = 0;
void repeatedly_execute_always() {
  
  if (game.debug_mode && IsKeyPressed(eKeySpace)) {
    AdvanceClock(0, 1);
  }
  else {
    frameCount++;
    if (frameCount >= GetGameSpeed()) {
      frameCount -= GetGameSpeed();
      seconds += 3; // 1 second passes IRL => 3 seconds pass in game
    }
  }
  
  Update();
}

void on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) SetBackgroundFrame(0);
}

Khris

I already sent Katie a PM, but for reference, the line in question is line 58:

Code: ags
  if (player.Room < 40) return; 


I put this there because in the source files, the only playable room was room 40, and it was supposed to disable the background code for menu and intro rooms.

katie08cd

yes you are right, because the first modification was made by Cassiebsg, then since he only had to modify one thing I gave him the file you took, while before I sent him the one with the rooms but I had not calculated your intervention, however just remove that line and put 4 backgrounds (in case of error) always in each room and AdvanceClock (2, 0) also works; , but if in the future I would like a script in hours with a map can I do it? my idea was to make the map as in the photo divided into 4 time slots imagine (which I will then have to fix), from the left 0 hours, center + 1 hour, right + 2 hours, off the map 4 hours, travel to London in NY etc. the time it takes for train and ship, you can create a script where I insert the rooms change time (each room) all the time differences, of course then I create the detailed list but asked if I could do a thing of the kind, in the meantime thank you very much again


SMF spam blocked by CleanTalk