forked from wwwtyro/Astray
-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer.js
124 lines (110 loc) · 3.09 KB
/
timer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
var timer_duration = 60;
var max_time;
var timer = undefined;
var stepsPlayed = false;
var spawned = false;
var steps = null;
function fiveSecondTimer() {
var start = new Date();
start.setSeconds(start.getSeconds() + 5);
var old_time = 0;
var remaining_time = 5;
while (true) {
var cur_time = new Date();
remaining_time = Math.round(start - cur_time);
if (start - cur_time < 0 ) {
$('#textField').text("");
break;
}
if (remaining_time != old_time) {
//writeToTextField(Math.round(start - cur_time), "red", 1)
$('#textField').text(remaining_time);
$('#textFieldContainer').css('color', "red");
old_time = remaining_time
}
}
}
function isTimeout() {
return timer_duration < 0;
}
function setTimerDuration() {
timer_duration = Math.floor(0.68 * Math.pow(mazeDim1, 1.6));
}
function getTimerDuration(){
return timer_duration;
}
function getTimeElapsed(){
return max_time - timer_duration;
}
function startTimer() {
max_time = timer_duration;
$('#timerText').text(timeToString(timer_duration));
timer_duration--;
timer = setInterval(function() {
$('#timerText').text(timeToString(timer_duration));
timer_duration--;
if(!stepsPlayed && timer_duration < 10){
steps = playSteps();
stepsPlayed = true;
}
}, 1000);
stepsPlayed=false;
}
function restartTimer(remTime) {
timer_duration = remTime;
$('#timerText').text(timeToString(timer_duration));
timer_duration--;
timer = setInterval(function() {
$('#timerText').text(timeToString(timer_duration));
timer_duration--;
if(!stepsPlayed && timer_duration < 10){
steps = playSteps();
stepsPlayed = true;
}
}, 1000);
stepsPlayed=false;
}
function stopTimer() {
var currentTime = timer_duration;
$('#timerText').text(timeToString(currentTime));
clearInterval(timer);
timer = null
return currentTime
}
function timeToString(time) {
var minutes = Math.floor(time/60);
var seconds = time%60 == 0 ? "00" : (time%60 < 10 ? ("0" + time%60) : time%60);
return minutes + ":" + seconds;
}
function startPietimer(seconds, callbackFunction, type) {
var pietimer = type == "zoom_out" ? "#pietimer" : "#pietimer2";
if($(pietimer).pietimer != null) {
$(pietimer).pietimer('pause');
}
$(pietimer).pietimer({
seconds: seconds,
color: 'rgba(255, 255, 255, 0.8)',
height: 100,
width: 100
},
callbackFunction);
$(pietimer).pietimer('start');
}
function clearPietimer() {
$("#pietimer").empty();
$("#pietimer2").empty();
}
function timeToSpawnEnemy()
{
if (!spawned)
{
if (timer_duration < max_time/3.5 || timer_duration < 20) // max_time - timer_duration > 7 appears after 1/4 of time
{
//console.log(max_time + " " + timer_duration)
//debugger;
spawned = true;
return true;
}
}
return false;
}