Author Topic: ANALOG CLOCK  (Read 1247 times)

ANALOG CLOCK
« on: 18 Jan 2020, 21:06 »
hello everyone is it possible to create an analog clock in the game? that goes on its own without blocking anything, and that during a certain animation, you can give the command to change the background or props? thanks, in the meantime I created a characters clock with a 12-frame loop, only that anyway the animation starts but it ends and then if I send it to other rooms the animation starts again, instead I would like it to be a fake clock but with 12 hours, in fact I created 12 frames for this, I would like to find a solution thanks

ciao a tutti e possibile creare un orologio analogico nel gioco? che vada per conto suo senza bloccare nulla, e che poi durante una certa animazione, puoi dare il comando di cambiare sfondo oppure oggetti di scena? grazie, nel frattempo mi sono creata un orologio characters con loop di 12 frame, solo che comunque mi parte l'animazione ma finisce e poi se lo mando in altre stanze riparte da capo l'animazione, io invece vorrei come se fosse un orologio finto ma con 12 ore, infatti ho creato 12 frame per questo, vorrei trovare una soluzione grazie


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 #1 on: 18 Jan 2020, 21:56 »
Short answer: Yes.

Now hos exactly does this watch move?
1)  Does it run on real time? 1hour of game running = 1 hour in game has passed?
2)  Does it change at a given setting? Like if you do task 1 and 2, the time moves 1 hour, then task 3 & 4 makes the timer move another hour...
3) Another scenario?

So first explain exactly how your clock should work, then we can give you solution (or even code) on how to solve the task at hand.
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #2 on: 18 Jan 2020, 23:00 »
hello thanks for the answer, no it does not work in real time, the time then I decide it according to the mission but I believe 6 hours of real game = one day in the game, the timer always moves one hour in the game, the but idea is that the game starts on October 1, 1898 at 9 in the morning, so if I calculate in the right way after 30 minutes, 10 will start, etc. of sunset, while if it is 5 in the morning the background of dawn comes out, even when I use the carriage to go to a place it must change animation of the landscape from day to night, then for bad weather that is decided throughout history,

yes I would like to create the code with the analog clock skin as seen in the photo if possible, thanks, if you want I will send you the files with the animation if you want to try, the game starts at 9 in the morning
« Last Edit: 18 Jan 2020, 23:02 by katie08cd »

Re: ANALOG CLOCK
« Reply #3 on: 18 Jan 2020, 23:37 »
You can have a function called "repeatedly_execute_always" that will be called 40 times ("ticks") per second, no matter what. It goes into the GlobalScript script (the Script, not the header). Just put the following near the end of that file to define it:
"function repeatedly_execute_always()
{
}"

In the editor, define an int variable in "Global Variables" (look for that section in the upper right pane of the editor).

In repeatedly_execute_always() increment this new variable. In order to prevent overflow, set the variable to 0 as soon as it has reached the ticks of a whole day.

In repeatedly_execute_always(), whenever your variable has reached the appropriate values, change the appearance of your room appropriately. If this entails changing objects, then this will become a big hassle since GlobalScript does not know the object names of your room. In this case, do "CallRoomScript(0)" whenever the room needs to be changed, and in your room script, define a function "on_call" near the end. This function will then be called whenever your global script calls CallRoomScript(), so you can handle things from there.

To be more specific, do something like the following near the end of your room script:
"function on_call(int what)
{
    if (0 == what)
    { ... change the appearance of the room ... }
}"

You can use the same mechanism to change the clock face:
1. In "repeatedly_execute_always", determine whether the clock face needs to be changed now; if so, call "CallRoomScript(1)".
2. In your room script, in function "on_call", add code such as
"   if (1 == what)
    { ... determine the sprite number that your clock should show ...
        YourClock.Graphic = the_right_sprite_number;
    }"

Whenever your character enters a new room, then its appearance must be changed to match the time of day. The easiest way to do this is to define the event "Enters room before fade-in" for the room and see to it that the corresponding function is _below_ the function "on_call()" in the room script. Then, simply do "on_call(0);" in the function for "Enters room before fade-in". This will guarantee that "on_call(0)" will be called whenever the player enters the room, before the room is shown yet.

In the same vein, to guarantee that the wall clock shows the right time when the player enters the room, do "on_call(1);" in the function for "Enters room before fade-in".

Hope those pointers help. If you need further details, feel free to ask.
« Last Edit: 19 Jan 2020, 00:05 by fernewelten »

Re: ANALOG CLOCK
« Reply #4 on: 19 Jan 2020, 00:41 »
You can have a function called "repeatedly_execute_always" that will be called 40 times ("ticks") per second, no matter what.

A little correction: it will be called X times, where X is the value of SetGameSpeed, could be anything from 10 to 1000 in theory.


I can also recommend using GUI instead of room objects, because it's much easier and you don't depend on room, you can share same GUI between several rooms, and update it in global script.

For calculating real time, DateTime script object is much more preferrable (unless you need millisecond precision). DateTime.Now allows you to get and save real current time. If you get DateTime.Now next time, and subtract the saved value, you will get almost exact number of seconds passed since.
« Last Edit: 19 Jan 2020, 03:37 by Crimson Wizard »

Re: ANALOG CLOCK
« Reply #5 on: 19 Jan 2020, 01:46 »
hi thanks, a question my watch must be a character or a view? however my clock must change time every 20 minutes, the game starts at 9 in the morning, then for example if the sprite of 5 in the morning, I have to change objects like dawn if I am in the city or traveling with the carriage, in the end I just have to calculate 4 scenarios, sunrise, day, sunset, evening, sunrise and sunset are a few minutes, while day and evening last longer, and I have to do all this in 8 hours of real life which result in 24 hours in the game , so every 20 minutes of real time changes an hour in the game and repeats until you finish the chapter, then in the next chapter I start a new time, new assassins, new suspects, etc. etc., maybe I should write a script with 24 voices, sunrise and sunset will be 1 minute each, while day and evening will last, day 280 minutes, evening 200 minutes

01 = 20 minutes
02 = 20
03 = 20
04 = 20
05 = 19 + 1minutes animation sunrise 200 minutes total evening
06 = 20 animation day
07 = 20
08 = 20
09 = 20
10 = 20
11 = 20
12 = 20
13 = 20
14 = 20
15 = 20
16 = 20
17 = 20
18 = 20
19 = 19 + 1minutes animation sunset 280 minutes total day
20 = 20 animation evening
21 = 20
22 = 20
23 = 20
00 = 20

I forgot, obviously in every room of the house or building or in the street, the clock runs normally, while if the character selects a point at the destination, such as going to the police or the crime scene, I should calculate them the theoretical time of 1 hour or 2, since I use a carriage with horses (1898) the game takes place
« Last Edit: 19 Jan 2020, 01:56 by katie08cd »

Re: ANALOG CLOCK
« Reply #6 on: 19 Jan 2020, 11:17 »
thank you for the advice, but unfortunately for me the program is in English, so I have to translate what you say with google translate (and the translation is not always right), then I have to try and try again until I get a result, thanks again everyone

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 #7 on: 19 Jan 2020, 12:47 »
To display the clock use a GUI, no need for characters or views. Just change the sprite of the clock when the timer reaches 20 (or corresponding value of Game Speed). Do the same to change background or set other events in march.

Try and try again, is also a valid way to reach the solution.  (nod)

Decide what is important to keep track of: day? hour? minute? sec?
If you only keep track of seconds, then your variable value will be a big number, which means it's probably easier to keep track of the others, and just reset (like a watch adds a 1 to the next value and resets to zero the current value). This will make it easier for you to keep track, and write if/if else/else clauses that make sense to you.

There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #8 on: 19 Jan 2020, 14:02 »
I have to create a GUI, with the clock button and inside put a script to change the frame, right? and which variable I should use I am not so expert, if in the game I start the GUI (excellent solution by the way because it is safe until I do .visible = false will be displayed) but how can I set that every 20 minutes of real time it moves one frame at a time, and in that frame for example 5 o'clock in the morning, it displays the object 0, because then I have to set my method 4 primary objects for each room, for example
object 0 dawn
object 1 day
object 2 sunset
object 3 evening

in each room I have to put 4 primary objects in such a way that I create a nice day-change effect in the game

great idea the GUI thanks, now I need a way to create the script, if you can give me an example of how to create it,

in my opinion the GUI gOro24, must use 26 continuous loop frames of about 20 minutes, also if the frame moves to the hours, it must follow this pattern

frames / minutes / objects
frame 10 = 9 in the morning
object 0 disable, dawn
object 1 true, day
object 2 disable, sunset
object 3 disable, evening


01 = 20 minutes = object 3 evening
02 = 20 minutes = object 3 evening
03 = 20 minutes = object 3 evening
04 = 20 minutes = object 3 evening
05 = 20 minutes = object 3 evening
06 = 1 minute = object 0 dawn
07 = 19 minutes = object 1 day
08 = 20 minutes = object 1 day
09 = 20 minutes = object 1 day
10 = 20 minutes = object 1 day
11 = 20 minutes = object 1 day
12 = 20 minutes = object 1 day
13 = 20 minutes = object 1 day
14 = 20 minutes = object 1 day
15 = 20 minutes = object 1 day
16 = 20 minutes = object 1 day
17 = 20 minutes = object 1 day
18 = 20 minutes = object 1 day
19 = 20 minutes = object 1 day
20 = 1 minute = object 2 sunset
21 = 19 minutes = object 3 evening
22 = 20 minutes = object 3 evening
23 = 20 minutes = object 3 evening
24 = 20 minutes = object 3 evening
25 = 20 minutes = object 3 evening
26 = 20 minutes = object 3 evening

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 #9 on: 19 Jan 2020, 16:28 »
You don't need an object to for each period of the day.
Also you have 2 different things in here. One is making the watch and keeping track of time. Another is changing the visual of your BGs to show of day/night cycle.

Concentrate on making the watch first, since you'll need the variables of time to decide when to do your BG change.

First make the GUI and use your  Clock at 00:00 sprite image as the BG.  open Global Variables (the one with a blue globe icon in the project tree). Now right click on an empty place and choose "add new variable...", give it a name like intSecunds. Leave it at int and set the default value to 0. Repeat for intMinutes, intHour & intDay (if you need to keep track of which day it is). You can change the variable names as you see fit. Also they don't all need to default at 00, so if yor game starts at 07:34, then just default Hour to 7 and minute to 34. ;)

now, locate in Global Scripts -> repeatedly_execute_always()

and then add the code to keep track of time:
Code: Adventure Game Studio
  1. intSecunds++;
  2.         if (intSecunds*GetGameSpeed()==2400)
  3.         {
  4.                 player.SayBackground("1 sec"); // for debugging, delete or comment out with //
  5.                 intSecunds=0;
  6.                 intMinute++;
  7.                 if (intMinute==60)
  8.                 {
  9.                         intMinute=0;
  10.                         intHour++;
  11.                         gClock.BackgroundGraphic=Clock00+intHour; // Clock00 is sprite number that corresponds your clock at 00:00 (I'm assuming they have been imported sequencially and in the right order)
  12.                         if (intHour==24)
  13.                         {
  14.                                 intHour=0;
  15.                                 intDay++;
  16.                                 gClock.BackgroundGraphic=Clock00; // Clock00 is sprite number that corresponds your clock at 00:00
  17.                         }
  18.                 }
  19.         }
  20.  

I'm not saying this is the only way to do it, and have no idea if I forgot anything in here. But I would go with something like this.


Don't have the time right now to give you code to change the game's BG.





« Last Edit: 19 Jan 2020, 16:42 by Cassiebsg »
There are those who believe that life here began out there...

Snarky

  • Global Moderator
  • Global Moderator
  • Mittens Lord
  • Private Insultant
    • Best Innovation Award Winner 2018, for his numerous additions to the AGS open source ecosystem including the new Awards Ceremony client and modules
    • Snarky worked on one or more games that won an AGS Award!
    •  
    • Snarky worked on one or more games that was nominated for an AGS Award!
Re: ANALOG CLOCK
« Reply #10 on: 19 Jan 2020, 20:34 »
You could also check out my Day/Night module to keep track of the time.

Re: ANALOG CLOCK
« Reply #11 on: 20 Jan 2020, 14:22 »
wow, hello thank you, as soon as I fix my AGS I try immediately, I'm remaking the game again because I changed a main room and now some chars don't go anymore, and then in the game I found various functions so better to start again with code clean, however I did not understand the part of the frame, in the sense that I did not understand how to create frames within a GUI, I can change the background and add a button, but I am missing the fact of how to add other frames, but you have you already tried everything? does it work can you create a small executable? Thanks for your patience :)

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 #12 on: 20 Jan 2020, 14:32 »
Line 11 on my code is how you change the clock sprite.

No idea what you mean by "frame".
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #13 on: 20 Jan 2020, 18:34 »
that I can't make an animated sequence in GUI, right? because my watch, at 26 frames, or maybe it can be done but I have never tried it

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 #14 on: 20 Jan 2020, 19:05 »
How exactly do you want to animate the clock?
From what I understood of what you wrote, the clock changed only at every hour, if it's running on full time like a real clock, then you'll need a lot more sprites (or animate the pointers). Otherwise just do what I told you do to or use Snarky's module.

If you need to use a view for animation, use a button (I can't recall if the background can be assigned a view, but think it's not). Make a button, then assign the view to that button and it will animate.
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #15 on: 20 Jan 2020, 23:15 »
hello thanks for replying, then I apologize because I understood to create a GUI and inside that gui to put the clock frames (which are 26) but I realized that you cannot import frames in the gui, so I ask , to use your code what do I have to create to make animation? a character, an object, what is created to animate, sorry for my ignorance on this issue :)

Re: ANALOG CLOCK
« Reply #16 on: 20 Jan 2020, 23:37 »
hello thanks for replying, then I apologize because I understood to create a GUI and inside that gui to put the clock frames (which are 26) but I realized that you cannot import frames in the gui, so I ask , to use your code what do I have to create to make animation? a character, an object, what is created to animate, sorry for my ignorance on this issue :)

You can add sprite on GUI, there's a property called BackgroundGraphic. You can also make a Button on GUI and add image to this button, using property called NormalGraphic.
Both GUI's background graphic, and button's graphic can be changed anytime in script.

In AGS you can also set whole animation to the object, using Views, but you do that if you want continious animation (the animation that runs all the time on screen), but that's not what you need probably for this clock.
« Last Edit: 20 Jan 2020, 23:39 by Crimson Wizard »

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 #17 on: 20 Jan 2020, 23:45 »
I'm not animating anything. I'm just replacing the clock sprite (image) with the next one.
You say in your first post that you have "created a characters clock with a 12-frame loop". So I'm assuming that you want to show only the hours and change the hour every time the hour has changed. So that the player can see what the current hour he's playing.

But now you're talking about a 26 frames animation...  ???

If you only need to show a single image (no animation!) and change the image every game hour, the set the first sprite to your clock 00 as the GUI image background.

If you want to animate it somehow, you will need to create a button, add the image of the first sprite to your clock 00 as the normal button image (note that you can also use this option for a single image with no animation).

CW beat me to the answer. :)
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #18 on: 21 Jan 2020, 00:14 »
first of all thank you both for the answers, you are very kind, thank you thank you, I did not know that you could change frames for this I am in difficulty, now in the photo I have created a transparent gclock GUI, with the frame button 00 in it (0 : 00) now if I want to create a simple thing like, I enter the room, a time starts that after 20 minutes of play, must change the frame, what command should I use for this? then the same command must be repeated 24 times, (to create a clock effect animation) and continuous cycle, I don't have to do anything complicated but just to understand how it works, that at a certain time it can change frames, thanks



per prima cosa vi ringrazio entrambi per le risposte, siete molto gentili, grazie grazie, non sapevo che si poteva cambiare frame per questo mi trovo in difficoltà, ora in foto ho creato una GUI gclock trasparente, con dentro il pulsante del frame 00 (0:00) adesso se voglio creare una cosa semplice del tipo, entro nella stanza, parte un orario che dopo 20 minuti di gioco, deve cambiare il frame, che comando devo usare per questo? poi lo stesso comando va ripetuto 24 volte, (per creare una animazione di effetto orologio) e ciclo continuo, non devo fare nulla di complicato ma tanto per capire come funziona, che ad un determinato tempo possa cambiare frame, grazie

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 #19 on: 21 Jan 2020, 11:25 »
Code: Adventure Game Studio
  1. function repeatedly_execute_always() // locate this in GlobalScript
  2. {
  3.   intSecunds++;
  4.   if (intSecunds*GetGameSpeed()==2400)
  5.   {
  6.     intSecunds=0;
  7.     intMinute++;
  8.     if (intMinute==20) // Because you wish to change the hour at every 20 minutes and not real time (every 60 minutes).
  9.     {
  10.         intMinute=0;
  11.         intHour++;
  12.         Bclock.NormalGraphic=88+intHour; // 88 is sprite number that corresponds your clock at 00:00 (note that this only works if 89 is hour 01:00, and 90 is 02:00, etc)
  13.         if (intHour==12 && intHour==24)
  14.         {
  15.           Bclock.NormalGraphic=88; // this resets the clock image to 00:00
  16.           if (intHour==24)
  17.           {
  18.           intHour=0;
  19.           intDay++;
  20.           }
  21.        }
  22.     }
  23.   }
  24. }
  25.  

Setting the day/night cycle is slightly more complicated. Does your clock show 06:01 ? If not and you just want the BG to show Dawn animation at this time, it's easier. Otherwise I recommend you might want to change the sprite numbers to make it easier when coding.
Let's say that you import all your clocks sprites in order....
Sprite number = clock hour
88 = 00:00
89 = 01:00
90 = 02:00
91 = 03:00
92 = 04:00
93 = 05:00
94= 06:00
95 = 06:01 (Dawn) // would it keep showing 6:01? <--- This situation would mess up the clock, showing the correct hour in my code. My suggestion would be to move it to another number. So that 95 = 07:00 and so on...

If what you want is to show an animation at 6:01 in your room changing from night to dawn to day, then all is needed is to add an if check in the minutes section of the code and keep track of the hour and minute, when  it matches you just tell it to animate and do the changes needed to the room.

If you want the clock to animate then just use
bclock.Animate(view); //where view is the view number or name (all caps). Place this line right after gClock.Visible=True.

I can try and explain in Portuguese, if you think you'll get a better match in the translation, considering Portuguese and Italian match in grammar and derive both from Latin.
Posso tentar explicar em Português, se tu achares que a tradução é melhor, tendo em consideração que Português e Italiano têm a gramática em comum e derivam ambas do Latim.
« Last Edit: 21 Jan 2020, 23:36 by Cassiebsg »
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #20 on: 21 Jan 2020, 15:26 »
hello, thanks for the answer, then let's start over, a simple thing for you, use the animated command that from how as you can see in the picture does not work because I'm wrong something,
gclock = gui
bclock = button gui gclock
clock24 is view animated
what am i wrong with this command ?, what should i write exactly, then first i was trying your script but by mistake i then send you the photo, of your script i created 4 int in global variabiles and copied your script, on function repeatedly_execute_always ()
only that later he gave me an error at this point

GlobalScript.asc(128): Error (line 128): Nested functions not supported (you may have forgotten a closing brace)

// Called when a dialog script line "run-script" is processed
function dialog_request (int param)
{
}

thanks anyway :)





« Last Edit: 21 Jan 2020, 15:38 by katie08cd »

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 #21 on: 21 Jan 2020, 17:13 »
From the manual: Button.Animate(int view, int loop, int delay, RepeatStyle)

So you probably want something like: Bclock.Animate(CLOCK24, 0, 10, eRepeat); (where 10 is the speed the animation will run, and eRepeat to make it animate constantly)

About the last one, it tells you exactly what is wrong. You forgot a } (closing brace).
Now, you don't show your code and cut it, but I can see that there's a dotted line behind 123 that has no closing } bellow it. Try adding a line between line 123 and 124 and add a } under the dotted vertical line.
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #22 on: 21 Jan 2020, 18:09 »
yeep, small steps, the clock works, how do i calculate the delays? is there by chance a delay converter for seconds or minutes? , now that it finally works I can interact, now if from this animation I would like to make a similar sequence,

gClock.Visible = true;
    Bclock.Animate (CLOCK24, 0, 10, eRepeat);
10 speed = I want to change it in 20 minutes

after I try again your script, thank you very much

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 #23 on: 21 Jan 2020, 19:11 »
uhm... number too big that my mind explodes.  Math is not my forte...


My script "manually" animates your clock every 20 minutes.
So it does exactly what you want to do with the animation (Meaning you don't need to animate the button it at all! as I'm manually changing it at the appropriate time).
Note that if you are animating the clock, changing the clocks normalGraphic will likely not work. Since there's a warning about it in the manual. My advice is: forget animating the clock. That's not really what you want, when we talk about animating is something that will run a quick/short animation sequence once or keep repeating it.
Delete or comment out the Bclock.animate command, and go with the code.


There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #24 on: 21 Jan 2020, 20:01 »
ok I solved your script, it just doesn't move, I even changed the number of frames, seconds, minutes, but nothing doesn't change, what escapes me to make it work? is not that maybe you have to set the script on the view for it to work?
Bclock24.NormalGraphic intHour + = 77;
77 and to test if it moves because with 88 it stays still
Bclock.Animate (CLOCK24, 0, 30, eRepeat);
with this command animation works but with other AGS, I always make a test copy to try the functions, but unfortunately I see that by mistake if I insert the view, anyway thank you so much with the normalgraphic command (which I didn't know how to use) I can also create the pages for dialogue and much more, thanks again

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 #25 on: 21 Jan 2020, 21:13 »
Please copy paste the entire function.  :-\
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #26 on: 21 Jan 2020, 21:19 »
ok I tried with delays, and I did some tests
40 = 1 sec
2400 = 1 min
12000 = 5 min
36000 = 15 min
48000 = 20 min
unfortunately though if I put 33000 delay, the clock goes crazy it runs very fast, so I assume there is a limit also in the delay
32000 = 13 min> the maximum limit of 13 minutes

Re: ANALOG CLOCK
« Reply #27 on: 21 Jan 2020, 21:22 »

function repeatedly_execute_always()
{
  //intSecunds++;
  if (intSecunds*GetGameSpeed()==2400)
  {
    intSecunds=0;
    intMinute++;
    if (intMinute==1) // Because you wish to change the hour at every 20 minutes and not real time (every 60 minutes).
    {
        intMinute=0;
        intHour++;
        Bclock24.NormalGraphic=88+intHour;
        if (intHour==12 && intHour==24)
        {
          Bclock24.NormalGraphic=00; // this resets the clock image to 00:00
          if (intHour==0)
          {
          intHour=0;
          intDay++;
          }
        }
    }
  }
 
 }

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 #28 on: 21 Jan 2020, 22:19 »
 //intSecunds++; <-- this is commented out. That's why the clock isn't running. Remove the // from it

Also, please wrap your code here in the forum with the [ code] [ /code] tags, or copy/paste and then select/highlight your code and choose the # button.
« Last Edit: 21 Jan 2020, 22:22 by Cassiebsg »
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #29 on: 21 Jan 2020, 22:46 »
ok it works but I notice two problems
if (intMinute == 1) // Because you wish to change the hour at every 20 minutes and not real time (every 60 minutes).

1. is there a second, not a minute, that is normal, or do I have to calculate the seconds by minutes?

2. no it resets to the frame continues indefinitely showing me other images of the game, as if there was no stop despite putting the start frame. and the final frame, it seems that it does not find it

Code: Adventure Game Studio
  1.  intMinute=0;
  2.         intHour++;
  3.         Bclock24.NormalGraphic=77+intHour;
  4.         if (intHour==12 && intHour==24)
  5.         {
  6.           Bclock24.NormalGraphic=80; // this resets the clock image to 00:00
  7.           if (intHour==0)
  8.           {
  9.           intHour=0;
  10.           intDay++;

I also did the test to put only 4 frames
from 77 to 80, but it does not stop it continues showing me all the images of the game

other strange thing, if I put any frame like 77 and in the button is set 77, he starts from 80, so I have to put 75 if I want to see frame 77, strange as what

as always thank you
« Last Edit: 21 Jan 2020, 23:36 by katie08cd »

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 #30 on: 21 Jan 2020, 23:37 »
Please show me the numbers of your clock images. Sprite number.

No.

1. intSecund is keeping track of the seconds that have passed. Once the seconds reach 60 they are reset to 0 and to intMinute is added 1. This keeps repeating, until intMinutes reaches 20 (because you want 1 hour in game to equal 20 minutes in real life time), then IntMinutes gets reset to 0, to intHour it's added 1 and the clock changes to the next sprite.

2. There's in no stop sprite, just the sprite that corresponds to clock at 00:00!

And also, that is not the code I posted before. You have changed it at one point or another, and thus it does not work.  :-\ Please copy/paste my code (https://www.adventuregamestudio.co.uk/forums/index.php?topic=57712.msg636615180#msg636615180) and do not make changes. I have edited my code to add the missing closing bracket.
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #31 on: 22 Jan 2020, 00:26 »
https://drive.google.com/file/d/1jjhytBxb6M14_FVlywSWh7Bsm7HL4Jf3/view

hello, I tried again but nothing, it does not stop continue with all the images, I prepared a copy so at least you can understand, maybe you need a reset or stop variable, I don't know, any frame that I put (even not clock) starts always with 4 frames first, so if in the first frame it says 77, I have to put 74 to start it, and then it does not stop it continues always, thanks again

push inizia, caso 1 to play
sorry for the graphic :)

I also did the test to set the 1 sprite to 12, but it does not stop always continues

        intMinute=0;
        intHour++;
        Bclock24.NormalGraphic=1+intHour; // 88 is sprite number that corresponds your clock at 00:00 (note that this only works if 89 is hour 01:00, and 90 is 02:00, etc)
        if (intHour==12 && intHour==24)
        {
          Bclock24.NormalGraphic=12; // this resets the clock image to 00:00
          if (intHour==24)
          {
          intHour=0;
          intDay++;

« Last Edit: 22 Jan 2020, 00:41 by katie08cd »

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 #32 on: 22 Jan 2020, 07:26 »
I fixed it, there's a if/else missing to change the sprite number when intHour is bigger than 11, need to subtract 12 to get the correct sprite to show again.
I'll post the fixes (there's more than one) later, as I needed to leave  now.
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #33 on: 22 Jan 2020, 13:36 »
wowww :) thank you, I'm glad you did it, congratulations

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 #34 on: 22 Jan 2020, 14:10 »
Okay, I'm back.

I started by checking the sprite numbers, and the sprite for clock 00:00 was the last one of the series, not the first.
So I started by re-numbering the sprites. They now run from 100 to 111, and 100 is 00:00, 101 is 01:00, etc, up to clock 11:00.
I had to delete the frames on the clock view, but you don't need them anyway.

Here's the remaining changes I did:
Code: Adventure Game Studio
  1. function repeatedly_execute_always()
  2. {
  3.   if (gClock.Visible==true)
  4.   {
  5.   intSecunds++;
  6.   if (intSecunds==60*GetGameSpeed())
  7.   {
  8.     intMinute++;
  9.     intSecunds=0;if (intMinute==20) // Because you wish to change the hour at every 20 minutes and not real time (every 60 minutes).
  10.     {
  11.       intHour++;
  12.       intMinute=0;
  13.       if (intHour<=11)Bclock24.NormalGraphic=100+intHour; // 100 is sprite number that corresponds your clock at 00:00
  14.       else Bclock24.NormalGraphic=100+intHour-12; // Need to remove 12h to get the correct sprite number
  15.       if (intHour==12 || intHour==24)
  16.       {
  17.         Bclock24.NormalGraphic=100; // this resets the clock image to 00:00
  18.         if (intHour==24)
  19.         {
  20.           intHour=0;
  21.           intDay++;
  22.         }
  23.       }
  24.     }
  25.     CheckRoomBackground(); // this script can be found in Scripts->CustomScripts and it will change the room background acording to the clock at game start                    
  26.     }
  27.    //player.SayBackground(String.Format("%d:%d:%d", intHour, intMinute, intSecunds/GetGameSpeed())); // for debug purpose, player will tell the time
  28.   }
  29. }
  30.  

I created a new Script in called CustomScripts (use it to add new scripts you wish to call from anywhere in script, and don't want it messed with GlobalScript functions).

Here you find the new function:
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 && intMinute>=1) SetBackgroundFrame(2); // Day Backgrund
  6.         else if (intHour==19 && intMinute==0) SetBackgroundFrame(3); // Sunset Background
  7. }
  8.  

And in the Header: import void CheckRoomBackground();

Use this function to set you your room before fade in (as seen in room 40):

Code: Adventure Game Studio
  1. function room_Load() // remember to plug this function to room events, just copy/pasting it won't work.
  2. {
  3.         CheckRoomBackground(); // this script can be found in Scripts->CustomScripts and it will change the room background according to the clock at game start
  4. }
  5.  

Also, if you open Room40 and look at the Backgrounds, you'll notice I've added 3 new BGs.
Background 0 (default) is the one you had, which is Evening/Night,
Background 1 is Dawn,
Background 2 is Day,
Background 3 is Sunset.

Note: I don't know what happens if AGS tries to set a Background in a room that only has 1 background. I'm guessing the two options are "Nothing happens or game crashes..."  (roll)

Here's your source back: https://www.mediafire.com/file/vo67divmugtk8sc/orologio.zip/file
« Last Edit: 22 Jan 2020, 14:19 by Cassiebsg »
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #35 on: 22 Jan 2020, 17:23 »
OMG WOW, when I go to the map to go to the police, you see the background, fantastic * _ *, I made you create a wonderful script, thanks it was what I wanted, but now the game starts at 9 am, so I just have to change it sprites from 00 to 9, and then the change background script that corresponds to the time, thanks again

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 #36 on: 22 Jan 2020, 17:36 »
NONONONO

Just open Global Variables, edit intHour and set the default to 9!
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #37 on: 22 Jan 2020, 18:17 »
ok if I put 9 in global variabiles, the backgrounds go to me like the XD disco strobe effect, they cycle, if I set sprite 109 in the script and the gclock button disappears, because obviously the sprite sequence has changed, so what should I change to to start the game at 9? if I change the sprites the sequence is correct because it is set to 12 sprites, and those remain, the sprite 00 becomes 9 etc., and continues the cycle, the problem and the backgrounds change, now in this script the 6 is set as a time, or number of sprites? because in this way I could change it just tell him where the sprite 6 is located etc, thanks anyway I really like the script

Code: Adventure Game Studio
  1. if ((intHour <6) || (intHour> = 19 && intMinute> = 1)) SetBackgroundFrame (0); // Night Background
  2. else if (intHour == 6 && intMinute == 0) SetBackgroundFrame (1); // Dawn Background
  3. else if (intHour> = 6 && intMinute> = 1) SetBackgroundFrame (2); // Day Backgrund
  4. else if (intHour == 19 && intMinute == 0) SetBackgroundFrame (3); // Sunset Background
« Last Edit: 22 Jan 2020, 18:30 by katie08cd »

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 #38 on: 22 Jan 2020, 18:59 »
That is not sprite number, it's hour.  :~(
There are those who believe that life here began out there...

Re: ANALOG CLOCK
« Reply #39 on: 22 Jan 2020, 19:14 »
yes I noticed, but how come if I set it to 9 in global variabiles, the backgrounds cycle me? and then I was weighing if instead of the script with the background change, they put something like if sprite 109 changes bacground 1, can we do it? do you think so we can solve the problem, because it is fantastic but my office in the game opens at 9 am XD, as always thank you very much, another thing I noticed that I no longer see the dark around the icons (before it was gray if I went to hotspots etc, what command did you use or setting to make sure that you don't see the grayness between the icons, thanks




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