-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.js
67 lines (66 loc) · 1.7 KB
/
logic.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
/*
* logic.js -- main logic
*
* Codes from Jack Works([email protected])
* And idea is from Scott Shen([email protected])
*
* Vola Studio 2014.
*
*
*/
dom.game.source.click(function () {
var $t = $(this).stop(true);
var result = checkr($t.attr('r'), settings.tgr, settings.tolerance, true);
if(result == "in range"){
win();
}
else{
lose();
}
})
function lose(){
Event.publish("result lose")("result",["lose"]);
}
function win(){
Event.publish("result win")("result",["win"]);
ani();
}
function ani(){
settings.tgr = random(70,150)
dom.game.target.attr("r", settings.tgr);
dom.game.source.css("fontSize",0).attr("r",10)
.animate({"fontSize":150 + settings.tolerance}, {
step: function(now) {
var $t = $(this);
$t.attr("r",now);
if(checkr(now, settings.tgr, settings.tolerance, false) == "stop animation"){
$t.stop(true);
lose();
}
},
duration:Math.random()*1000 + settings.speed
}, 'linear', function () {
lose();
})
}
function random(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
function checkr(s,t,m,c){
/*
*
* Actions:
* "too big" "continue animation"
* "too big" "stop animation"
* "too small" "continue animation"
* "in range" "continue animation"
* t-m t+m t+2m
* too small in range stop animation too big
*/
if(t+m<s&&c) return "too big";
if(t+m+m<s){if(c)return "too big";else return ("stop animation")}
if(!c&&(t+m<s||t-m>s||(t-m<s&&s<t+m)))return "continue animation"
if(t-m>s&&c)return "too small"
if(t-m<s&&s<t+m)return "in range"
return "error"
}