I am coding a better time feature for my game and it mostly works, except when I try to calculate minutes.
Here is my code. There are 1440 ticks (ticks happen every second), 24 hours, and 60 minutes in every day.
public static void time() {
tick++;
minute=(tick/hour)-60;
if(hour==13){
toggle_time();
}
if(hour>24){
hour=1;
tick=0;
}
if (tick % 60 == 0) {
hour = Math.round(tick / 60);
}
if(hour==0){
hour=1;
}
if(hour==10){
sun_set=true;
sun_rise=false;
}
if(hour==20){
sun_rise=true;
sun_set=false;
}
rot=-(float) (hour/2*30);
System.out.println("Time: H: "+hour+"; M: "+ minute+"; Tick: "+ tick);
}
which outputs something like:
Time: H: 15.0; M: 3.9333344; Tick: 959.0
Time: H: 16.0; M: 4.0; Tick: 960.0
Time: H: 16.0; M: 0.0625; Tick: 961.0
Time: H: 16.0; M: 0.125; Tick: 962.0
Time: H: 16.0; M: 0.1875; Tick: 963.0
Time: H: 16.0; M: 0.25; Tick: 964.0
I’m trying to calculate current minutes in the hour based off of the ticks.
any help would be greatly appreciated! :point: