Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @description game_timer(timer)
- /// @param timer
- function game_timer(timer) {
- //Handles the in-game timer.
- //Local variables for calculating the time
- var hour, minute, second, centisecond;
- //Local variables for displaying the time
- var d_hour, d_minute, d_second, d_centisecond;
- //Timer limits
- var local_limit = 599999;
- var global_limit = 35999999;
- //Stage time
- if (global.gameTimer == 1) {
- //Calculate current time
- if (global.currentTime < local_limit - 4) {
- if (++timer == 2) {
- timer = 0;
- global.currentTime += 5;
- }
- } else {
- global.currentTime = local_limit;
- }
- //Calculate each timer section
- minute = floor(global.currentTime / 6000);
- second = floor((global.currentTime - (minute * 6000)) / 100);
- centisecond = (global.currentTime - (minute * 6000) - (second * 100));
- //Display correct time
- d_hour = "";
- d_minute = minute < 10 ? "0" + string(minute) : string(minute);
- d_second = second < 10 ? "0" + string(second) : string(second);
- d_centisecond = centisecond < 10 ? "0" + string(centisecond) : string(centisecond);
- }
- //Global time
- else {
- //Calculate current time
- if (global.globalTime < global_limit - 4) {
- if (++timer == 2) {
- timer = 0;
- global.globalTime += 5;
- }
- } else {
- global.globalTime = global_limit;
- }
- //Calculate each timer section
- hour = floor(global.globalTime / 360000);
- minute = floor((global.globalTime - (hour * 360000)) / 6000);
- second = floor((global.globalTime - (hour * 360000) - (minute * 6000)) / 100);
- centisecond = (global.globalTime - (hour * 360000) - (minute * 6000) - (second * 100));
- //Display correct time
- d_hour = hour < 10 ? "0" + string(hour) : string(hour);
- d_minute = minute < 10 ? "0" + string(minute) : string(minute);
- d_second = second < 10 ? "0" + string(second) : string(second);
- d_centisecond = centisecond < 10 ? "0" + string(centisecond) : string(centisecond);
- }
- //Return timer and strings to display
- return [timer, d_hour, d_minute, d_second, d_centisecond];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement