Jibble

Author Topic: ANALOG CLOCK  (Read 1251 times)

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: ANALOG CLOCK
« Reply #40 on: 22 Jan 2020, 19:43 »
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...

Re: ANALOG CLOCK
« Reply #41 on: 22 Jan 2020, 19:50 »
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

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: ANALOG CLOCK
« Reply #42 on: 22 Jan 2020, 20:13 »
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: Adventure Game Studio
  1. // new module script
  2.  
  3. void AdjustClock()
  4. {
  5.   if (intHour<=11)Bclock24.NormalGraphic=100+intHour; // 100 is sprite number that corresponds your clock at 00:00
  6.   else Bclock24.NormalGraphic=100+intHour-12; // Need to remove 12h to get the correct sprite number           
  7. }
  8.  
  9. void CheckRoomBackground()
  10. {
  11.   if ((intHour<6)||(intHour>=19 && intMinute>=1)) SetBackgroundFrame(0); // Night Background
  12.   else if (intHour==6 && intMinute==0) SetBackgroundFrame(1); // Dawn Background
  13.   else if (intHour>=6) SetBackgroundFrame(2); // Day Backgrund
  14.   else if (intHour==19 && intMinute==0) SetBackgroundFrame(3); // Sunset Background
  15. }
  16.  

Now open CustomScripts Header and copy/paste the following code:
Code: Adventure Game Studio
  1. import void AdjustClock();
  2.  


Open GlobalScript and locate the following two lines and replace them with: AdjustClock();
Code: Adventure Game Studio
  1. if (intHour<=11)Bclock24.NormalGraphic=100+intHour; // 100 is sprite number that corresponds your clock at 00:00
  2. else Bclock24.NormalGraphic=100+intHour-12; // Need to remove 12h to get the correct sprite number             
  3.  

Lastly, open Room40 script and add the same line to room_load and it should look like this:
Code: Adventure Game Studio
  1. function room_Load()
  2. {
  3.   AdjustClock();
  4.   CheckRoomBackground(); // this script can be found in Scripts->CustomScripts and it will change the room background acording to the clock at game start
  5. }
  6.  

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...)
« Last Edit: 22 Jan 2020, 20:24 by Cassiebsg »
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #43 on: 23 Jan 2020, 00:10 »
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


Re: ANALOG CLOCK
« Reply #44 on: 23 Jan 2020, 16:23 »
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
« Last Edit: 23 Jan 2020, 16:54 by katie08cd »

Matti

Re: ANALOG CLOCK
« Reply #45 on: 24 Jan 2020, 00:36 »
I haven't followed this thread closely, but I'm not sure about this:

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

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

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: ANALOG CLOCK
« Reply #46 on: 24 Jan 2020, 02:00 »
you're right   :-[ try this...  (roll)

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

Code: Adventure Game Studio
  1. void CheckRoomBackground()
  2. {
  3.   if ((intHour<6)||(intHour>=19 && intMinute>=1)) SetBackgroundFrame(0); // Night Background
  4.   else if (intHour==6 && intMinute==0) SetBackgroundFrame(1); // Dawn Background
  5.   else if (intHour>=6 && intHour<=18) SetBackgroundFrame(2); // Day Backgrund
  6.   else if (intHour==19 && intMinute==0) SetBackgroundFrame(3); // Sunset Background
  7. }
  8.  
« Last Edit: 24 Jan 2020, 02:03 by Cassiebsg »
There are those who believe that life here began out there...

Khris

  • partook in silencing a crtitc despite facts
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on one or more games that was nominated for an AGS Award!
Re: ANALOG CLOCK
« Reply #47 on: 24 Jan 2020, 09:13 »
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: ShowHide

6:18 AM, fading from dawn to day

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.
« Last Edit: 24 Jan 2020, 09:38 by Khris »
Fail at Floaty Rog' now!  still having to deal with what games are going through

Slasher

  • slasher
    • I can help with AGS tutoring
    • Lifetime Achievement Award Winner
    • I can help with scripting
    • I can help with story design
    • Slasher worked on one or more games that won an AGS Award!
    •  
    • Slasher worked on one or more games that was nominated for an AGS Award!
Re: ANALOG CLOCK
« Reply #48 on: 24 Jan 2020, 09:44 »
Nice one Khris  (nod)

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




Matti

Re: ANALOG CLOCK
« Reply #49 on: 24 Jan 2020, 10:58 »
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

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: ANALOG CLOCK
« Reply #50 on: 24 Jan 2020, 12:10 »
Cool. :) Take the master to make it better.  :-D
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #51 on: 24 Jan 2020, 12:18 »
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?
« Last Edit: 24 Jan 2020, 15:38 by katie08cd »

Re: ANALOG CLOCK
« Reply #52 on: 25 Jan 2020, 12:56 »
the backgrounds in the other rooms don't go, what command do I have to use? thanks

Code: Adventure Game Studio
  1. // new module script
  2.  
  3. #define CLOCK_CENTER_X 40
  4. #define CLOCK_CENTER_Y 40
  5. #define CLOCK_RADIUS_H 25
  6. #define CLOCK_SPRITE_H 29
  7. #define CLOCK_RADIUS_M 30
  8. #define CLOCK_SPRITE_M 30
  9.  
  10. enum BGFrame {
  11.   eBGNight = 1, eBGDawn = 2, eBGDay = 3, eBGDusk = 4
  12. };
  13.  
  14. int seconds, minutes;
  15. int hour, minute;
  16.  
  17. void DrawImageAA(this DrawingSurface*, int x, int y, int slot) {
  18.   this.DrawImage(x - 1, y, slot, 80);
  19.   this.DrawImage(x, y + 1, slot, 80);
  20.   this.DrawImage(x + 1, y, slot, 80);
  21.   this.DrawImage(x, y - 1, slot, 80);
  22.   this.DrawImage(x, y, slot);
  23. }
  24.  
  25. DynamicSprite* clockFace;
  26.  
  27. void DrawClock()
  28. {
  29.   clockFace = DynamicSprite.CreateFromExistingSprite(28, true);
  30.   DrawingSurface* ds = clockFace.GetDrawingSurface();
  31.   int a;
  32.  
  33.   // hour hand
  34.   DynamicSprite* hourHand = DynamicSprite.CreateFromExistingSprite(CLOCK_SPRITE_H, true);
  35.   a = minutes / 2;
  36.   while (a > 359) a -= 360;
  37.   if (a > 0 && a < 360) hourHand.Rotate(a, hourHand.Width, hourHand.Height);
  38.   hourHand.Resize(CLOCK_RADIUS_H * 2, CLOCK_RADIUS_H * 2);
  39.   ds.DrawImageAA(CLOCK_CENTER_X - hourHand.Width / 2, CLOCK_CENTER_Y - hourHand.Height / 2, hourHand.Graphic);
  40.  
  41.   // minute hand
  42.   DynamicSprite* minuteHand = DynamicSprite.CreateFromExistingSprite(CLOCK_SPRITE_M, true);
  43.   a = minutes * 6;
  44.   while (a > 359) a -= 360;
  45.   if (a > 0 && a < 360) minuteHand.Rotate(a, minuteHand.Width, minuteHand.Height);
  46.   minuteHand.Resize(CLOCK_RADIUS_M * 2, CLOCK_RADIUS_M * 2);
  47.   ds.DrawImageAA(CLOCK_CENTER_X - minuteHand.Width / 2, CLOCK_CENTER_Y - minuteHand.Height / 2, minuteHand.Graphic);
  48.  
  49.   ds.Release();
  50.   gClock.BackgroundGraphic = clockFace.Graphic;
  51. }
  52.  
  53. DrawingSurface* roomDS;
  54. DynamicSprite* roomBG;
  55.  
  56. void CheckRoomBackground()
  57. {
  58.   if (player.Room < 40) return;
  59.  
  60.   int newBottom = eBGDay; // day
  61.   int newTop = 0; // no second layer yet
  62.   int t;
  63.  
  64.   // is it night?
  65.   if (hour < 6 || hour > 18) newBottom = eBGNight;
  66.   // dawn?
  67.   if (hour ==  6 && minute < 30) newBottom = eBGDawn;
  68.   // dusk?
  69.   if (hour == 19 && minute < 30) newBottom = eBGDusk;
  70.  
  71.   // fading for 20 minutes each
  72.  
  73.   // night -> dawn
  74.   if (hour == 5 && minute > 40) {
  75.     newTop = eBGDawn;
  76.     t = (60 - minute) * 5;
  77.   }
  78.   // dawn -> day
  79.   if (hour == 6 && minute > 10 && minute < 30) {
  80.     newTop = eBGDay;
  81.     t = (30 - minute) * 5;
  82.   }
  83.   // day -> dusk
  84.   if (hour == 18 && minute > 40) {
  85.     newTop = eBGDusk;
  86.     t = (60 - minute) * 5;
  87.   }
  88.   // dusk -> night
  89.   if (hour == 19 && minute > 10 && minute < 30) {
  90.     newTop = eBGNight;
  91.     t = (30 - minute) * 5;
  92.   }
  93.  
  94.   roomDS = Room.GetDrawingSurfaceForBackground();
  95.   roomBG = DynamicSprite.CreateFromBackground(newBottom);
  96.   roomDS.DrawImage(0, 0, roomBG.Graphic);
  97.   if (newTop > 0) {
  98.     roomBG = DynamicSprite.CreateFromBackground(newTop);
  99.     roomDS.DrawImage(0, 0, roomBG.Graphic, t);
  100.   }
  101.   roomDS.Release();
  102.   roomBG.Delete();
  103. }
  104.  
  105. void Update() {
  106.   if (seconds > 24 * 3600) seconds -= 24 * 3600;
  107.   minutes = seconds / 60;
  108.   hour = minutes / 60;
  109.   minute = minutes - hour * 60;
  110.   CheckRoomBackground();
  111.   DrawClock();  
  112. }
  113.  
  114. void SetClock(int h, int m) {
  115.   seconds = h * 3600 + m * 60;
  116.   Update();
  117. }
  118.  
  119. void AdvanceClock(int h, int m) {
  120.   seconds += h *3600 + m * 60;
  121.   Update();
  122. }
  123.  
  124. int frameCount = 0;
  125. void repeatedly_execute_always() {
  126.  
  127.   if (game.debug_mode && IsKeyPressed(eKeySpace)) {
  128.     AdvanceClock(0, 1);
  129.   }
  130.   else {
  131.     frameCount++;
  132.     if (frameCount >= GetGameSpeed()) {
  133.       frameCount -= GetGameSpeed();
  134.       seconds += 3; // 1 second passes IRL => 3 seconds pass in game
  135.     }
  136.   }
  137.  
  138.   Update();
  139. }
  140.  
  141. void on_event(EventType event, int data) {
  142.   if (event == eEventEnterRoomBeforeFadein) SetBackgroundFrame(0);
  143. }

Khris

  • partook in silencing a crtitc despite facts
    • Lifetime Achievement Award Winner
    • I can help with play testing
    • I can help with scripting
    • I can help with translating
    • Khris worked on one or more games that was nominated for an AGS Award!
Re: ANALOG CLOCK
« Reply #53 on: 26 Jan 2020, 10:04 »
I already sent Katie a PM, but for reference, the line in question is line 58:

Code: Adventure Game Studio
  1.   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.
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: ANALOG CLOCK
« Reply #54 on: 26 Jan 2020, 17:07 »
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