-
Notifications
You must be signed in to change notification settings - Fork 0
/
points.js
39 lines (39 loc) · 1.11 KB
/
points.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
/*
* points.js -- logic about points
*
* Codes from Jack Works([email protected])
* And idea is from Scott Shen([email protected])
*
* Vola Studio 2014.
*
*/
(function () {
Event.on("result lose", function(){
data.points = 0;
Event.publish("points changed",[{now:0, type: "clear"}]);
});
Event.on("result win", function(){
var gotpts = point_calc(doms.source.attr("r"), settings.tgr, settings.tolerance, settings.speed);
data.points += gotpts;
Event.publish("points changed",[{now: data.points, type: "add", value: gotpts}]);
});
Event.on("points changed", function(){
if(data.bestPoints < data.points){
Event.publish("points new high",[data.points]);
}
});
/*
* Use to calc the point when click. wish a better version
* gsr: r of source circle
* gtr: r of target circle
* mis: mistake (settings.torlorance)
* time: settings.speed
*/
function point_calc(gsr, gtr, mis, time){
var points = 1/(Math.abs(gsr - gtr)*time*mis) * 1e5;// * 8;
points = parseFloat(points.toFixed(2));
if(points>5)points = 5;
else if(points<1)points = 1;
return points;
}
})();