You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
855 B
45 lines
855 B
#include "pixelGameEngine.h"
|
|
|
|
struct time_data{
|
|
int seconds=0;
|
|
int minutes=0;
|
|
int hours=0;
|
|
int days=0;
|
|
int seasons=0;
|
|
};
|
|
|
|
class GameClock{
|
|
long time=0;
|
|
float accumulated_time=0;
|
|
public:
|
|
void Update(float delta){
|
|
accumulated_time+=delta;
|
|
while(accumulated_time>1){
|
|
time++;
|
|
accumulated_time--;
|
|
}
|
|
};
|
|
void AfterUpdate(float delta){};
|
|
time_data GetTime(){
|
|
return {
|
|
(int)(time%60),
|
|
(int)(time/60)%60,
|
|
(int)(time/3600)%24,
|
|
(int)(time/86400)%30,
|
|
(int)(time/2592000),
|
|
};
|
|
}
|
|
};
|
|
|
|
int main(){
|
|
GameClock master_clock;
|
|
while(true){
|
|
master_clock.Update(1/60.f); //Simulate 60 FPS.
|
|
time_data current_time = master_clock.GetTime();
|
|
std::cout<<
|
|
current_time.seasons<<" Seasons "<<
|
|
current_time.days<<" Days "<<
|
|
current_time.hours<<"h,"<<current_time.minutes<<"m,"<<current_time.seconds<<"s"
|
|
<<std::endl;
|
|
}
|
|
} |