From 1a8fe435e7deabf06029c8e50201136518e3af73 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sat, 12 Aug 2017 01:26:29 -0400 Subject: split out src/ directory into categorized subdirectories. --- src/engine/play_time.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/engine/play_time.c (limited to 'src/engine/play_time.c') diff --git a/src/engine/play_time.c b/src/engine/play_time.c new file mode 100644 index 000000000..9882c9c4b --- /dev/null +++ b/src/engine/play_time.c @@ -0,0 +1,73 @@ +#include "global.h" +#include "play_time.h" + +enum +{ + STOPPED, + RUNNING, + MAXED_OUT +}; + +static u8 sPlayTimeCounterState; + +void PlayTimeCounter_Reset() +{ + sPlayTimeCounterState = STOPPED; + + gSaveBlock2.playTimeHours = 0; + gSaveBlock2.playTimeMinutes = 0; + gSaveBlock2.playTimeSeconds = 0; + gSaveBlock2.playTimeVBlanks = 0; +} + +void PlayTimeCounter_Start() +{ + sPlayTimeCounterState = RUNNING; + + if (gSaveBlock2.playTimeHours > 999) + PlayTimeCounter_SetToMax(); +} + +void PlayTimeCounter_Stop() +{ + sPlayTimeCounterState = STOPPED; +} + +void PlayTimeCounter_Update() +{ + if (sPlayTimeCounterState == RUNNING) + { + gSaveBlock2.playTimeVBlanks++; + + if (gSaveBlock2.playTimeVBlanks > 59) + { + gSaveBlock2.playTimeVBlanks = 0; + gSaveBlock2.playTimeSeconds++; + + if (gSaveBlock2.playTimeSeconds > 59) + { + gSaveBlock2.playTimeSeconds = 0; + gSaveBlock2.playTimeMinutes++; + + if (gSaveBlock2.playTimeMinutes > 59) + { + gSaveBlock2.playTimeMinutes = 0; + gSaveBlock2.playTimeHours++; + + if (gSaveBlock2.playTimeHours > 999) + PlayTimeCounter_SetToMax(); + } + } + } + } +} + +void PlayTimeCounter_SetToMax() +{ + sPlayTimeCounterState = MAXED_OUT; + + gSaveBlock2.playTimeHours = 999; + gSaveBlock2.playTimeMinutes = 59; + gSaveBlock2.playTimeSeconds = 59; + gSaveBlock2.playTimeVBlanks = 59; +} -- cgit v1.2.3