Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------------------------------------------
- time.h
- -------------------------------------------------------------
- #ifndef __TIME_TRAINS__
- #define __TIME_TRAINS__
- /**
- * Maximum length of seconds or minutes
- */
- #define TIME_LENGTH 60
- /**
- * Maximum length of hours in day
- */
- #define TIME_LENGTH_DAY 24
- /**
- * Contains information about current time
- */
- typedef struct
- {
- /**
- * Number of hours
- */
- unsigned char Hours;
- /**
- * Number of minutes
- */
- unsigned char Minutes;
- /**
- * Number of seconds
- */
- unsigned char Seconds;
- } GameTime;
- /**
- * Current time
- */
- static GameTime *time_current;
- /**
- * Reset time back to zero
- * @param Item to reset
- */
- void time_Reset(GameTime *time);
- /**
- * Move time forward by 1 second
- * @param Item to update
- */
- void time_UpdateSeconds(GameTime *time);
- #endif
- -------------------------------------------------------
- time.c
- -------------------------------------------------------
- #include "../include/time.h"
- /**
- * Reset time back to zero
- */
- void time_Reset(GameTime *time)
- {
- time->Hours = 0;
- time->Minutes = 0;
- time->Seconds = 0;
- }
- /**
- * Move time forward by 1 second
- */
- void time_UpdateSeconds(GameTime *time)
- {
- if (++time->Seconds >= TIME_LENGTH)
- {
- time->Seconds = 0;
- if (++time->Minutes >= TIME_LENGTH)
- {
- time->Minutes = 0;
- if (++time->Hours >= TIME_LENGTH_DAY)
- {
- time->Hours = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement