-
Notifications
You must be signed in to change notification settings - Fork 2
/
gameInterface.js
172 lines (142 loc) · 4.5 KB
/
gameInterface.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
*
* ADSLife expose
*
*/
$.fn.expose=function(){
var overlayExist=$("#exposeMask").length>0;
if($.fn.expose.to)
clearTimeout($.fn.expose.to);
var el=this;
//console.debug("exposing: "+el.attr("id"));
var scene=$("#scene");
$("#exposeMask").remove();
var overlay=$("<div/>").attr("id","exposeMask").hide().addClass("expose").css({left:-scene.position().left});
scene.append(overlay);
$.fn.expose.highlight(el);
if(overlayExist)
overlay.show();
else
overlay.fadeIn();
};
$.fn.expose.remove=function(){
//console.debug("clearExpose");
$("[zIndex]").each(function(){
var zindex=$(this).attr("zIndex");
var display=$(this).attr("display");
$(this).css("z-index",zindex);
$(this).css("display",display);
});
$.fn.expose.to = setTimeout(function(){$("#exposeMask").fadeOut(500,function(){$(this).remove();});},500);
//$("#exposeMask").remove();
};
$.fn.expose.highlight=function(el){
el.attr("zIndex",el.css("z-index"));
el.attr("display",el.css("display"));
el.css({"z-index":10000, "position":"relative"});
el.show();
};
/**
* Parallax by robicch
* @param config
*/
jQuery.fn.parallax= function(config) {
//console.debug("parallax");
var params ={"x":true,"y":false};
if (config){
$.extend(params,config);
}
this.each(function(){
var stage = $(this);
//get scene offset
//var sceneOffset=stage.parents("#scene:first").position().left;
var bgDistance=parseFloat(stage.attr("distance"));
var dimension=parseFloat(stage.attr("dimension"));
var left = stage.position().left;//+sceneOffset;
var top = stage.position().top;
var width = stage.width();
var height = stage.height();
//console.debug(stage.position())
// setup parallel plans
stage.find("[distance]").each(function(){
var plan=$(this);
//store the starting/original position
plan.data("x",plan.position().left);
plan.data("y",plan.position().top);
plan.data("scale",parseFloat(plan.attr("distance"))/bgDistance);
//console.debug("parallax --> "+plan.attr("id")+" left: "+plan.data("x")+" top: "+plan.data("y"));
});
//setup transversal plans
stage.find("[distanceStart]").each(function(){
var plan=$(this);
//store the starting/original position
plan.data("x1",plan.position().left);
plan.data("x2",plan.position().left+plan.width());
plan.data("y",plan.position().top);
plan.data("w",plan.width());
plan.data("scale1",parseFloat(plan.attr("distanceStart"))/bgDistance);
plan.data("scale2",parseFloat(plan.attr("distanceEnd"))/bgDistance);
});
// handle movement
stage.mousemove(function(ev) {
var x = (ev.clientX - left)-width/2;
var y = (ev.clientY - top)-height/2;
//$("#debug").html("ex: "+ev.clientX+" ey:"+ev.clientY+"<br>x: "+x+" y:"+y+"<br>l: "+left+" t:"+top);
//move parallel plans
stage.find("[distance]").each(function(){
var plan=$(this);
if (params.x)
plan.css("left",plan.data("x")-x/plan.data("scale")/dimension);
if(params.y)
plan.css("top",plan.data("y")-y/plan.data("scale")/dimension);
});
//move transversal plans
stage.find("[distanceStart]").each(function(){
var plan=$(this);
var x1=plan.data("x1")-x/plan.data("scale1")/dimension;
var x2=plan.data("x2")-x/plan.data("scale2")/dimension;
var nw=x2-x1;
var resize=nw/plan.data("w")*100;
plan.css("left",x1);
plan.css("width",nw);
plan.html("left: "+x1+" width: "+nw+ "scale: "+resize);
});
});
});
return this;
};
jQuery.fn.clearParallax= function() {
//console.debug("clearParallax");
this.each(function(){
var stage = $(this);
// handle movement
stage.unbind("mousemove");
//ripristin positions
stage.find("[distance]").each(function(){
var plan=$(this);
if(plan.data("x")!=undefined){
plan.css("left",plan.data("x"));
plan.css("top",plan.data("y"));
}
});
//move transversal plans
stage.find("[distanceStart]").each(function(){
var plan=$(this);
if(plan.data("x1")!=undefined){
plan.css("left",plan.data("x1"));
plan.css("width",plan.data("w"));
}
});
});
return this;
};
function getTime(date) {
if (!date)
date = new Date();
return {
hours:date.getHours(),
minutes:date.getMinutes(),
seconds:date.getSeconds()
}
}
//console.debug(getTime().hours,":",getTime().minutes,":",getTime().seconds);