-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
executable file
·248 lines (218 loc) · 8.23 KB
/
index.html
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<title>是男人坚持20秒</title>
<script src="crafty-min.js"></script>
<style type="text/css">
html, body{ margin:0; padding:0; overflow:hidden; height:100%; background-color:#3D4F63; }
#box{ position:absolute; top:50%; left:50%; margin:-160px 0 0 -160px; }
#restart{ position:fixed; left:50%; top:50%; margin:-90px 0 0 -130px; z-index:1; font-size:28px; width:260px; height:180px; font-weight:bold; border-width:0; background-color:rgba(230, 100, 80, 0.7); color:#FFFEFC; display:none; }
.pic{ width:1px; height:1px; }
.MAN{
text-align:center;
vertical-align:-5px;
border-radius:3px;
}
.MAN span{ position:relative; top:10px; }
.Collision{
border-radius:100%;
-webkit-animation:turn 1s linear 0ms infinite normal backwards;
animation:turn 1s linear 0ms 1 infinite backwards;
}
@-webkit-keyframes turn{
0%, 100%{
opacity:1;
}
50%{
opacity:0.5;
}
}
@keyframes turn{
0%, 100%{
opacity:1;
}
50%{
opacity:0.5;
}
}
</style>
</head>
<body>
<div style="position:fixed; top:3px; width:100%; z-index:2; color:#FFF; text-align:center;">
<h1 style="font-size:18px;">是男人坚持20秒</h1>
<div class="tips" style="text-align:center;">请放平手机,晃动她,躲避小球。</div>
</div>
<div id="box">
<div id="game"></div>
</div>
<button type="button" id="restart" onclick="restart();">再来</button>
<pre id="output" class="output" style="position:fixed; right:5px; bottom:5px; background-color:#FFF; display:none;"></pre>
<script>
var shareInfo = {
appid : '',
imgUrl : 'http://man.misuisui.com/man.jpg',
lineLink : 'http://man.misuisui.com/',
descContent: '放平你的手机,调整你的心态,控制你的抖动,展显男人的坚持!',
shareTitle : '好男人坚持20秒不会让心爱的女人受一点点伤!'
};
var output = document.querySelector('.output');
var re = document.getElementById("restart");
Crafty.init(320, 320, document.getElementById("game"));
Crafty.background("#24292F");
var manX = 150;
var manY = 150;
var man = Crafty.e("MAN, 2D, DOM, Color, HTML, Fourway")
.attr({x: 150, y: 150, w: 20, h: 20})
.color("#fff")
.replace("<span>龍</span>")
.fourway(5)
.bind("EnterFrame", function () {
if (this.x > 300) {
this.x = 300;
}
else if (this.y > 300) {
this.y = 300;
}
else if (this.x < 0) {
this.x = 0;
}
else if (this.y < 0) {
this.y = 0;
}
manX = this.x;
manY = this.y;
});
var speed = 200;
var xy = [];
for (var i = 0; i <= 310; i = i + 10) {
xy.push([0, i]);
xy.push([310, i]);
}
var xyl = xy.length - 1;
var coA = ["#FF0000", "#FF7F00", "#FFFF00", "#00FF00", "#007FFF", "#00FFFF", "#FF00FF", "#FFFFFF"];
function kill() {
var _txy = xy[Crafty.math.randomInt(0, xyl)];
var _eX = _txy[0];
var _eY = _txy[1];
var __dX = (manX - _eX) / speed;
var __dY = (manY - _eY) / speed;
var _color = coA[Crafty.math.randomInt(0, 7)];
Crafty.e("2D, DOM, Color, Collision")
.attr({ x: _eX, y: _eY, w: 10, h: 10, dX: __dX, dY: __dY })
.color(_color)
.bind('EnterFrame', function () {
// var _manX = manX;
// var _manY = manY;
// if (this.x > 310 || this.x < 0 || this.y > 310 || this.y < 0) {
// var _txy = xy[Crafty.math.randomInt(0, xyl)];
// this.x = _txy[0];
// this.y = _txy[1];
// this.dX = (_manX - _eX) / speed;
// this.dY = (_manY - _eY) / speed;
// }
if (this.x > 310 || this.x < 0) {
this.dX = -this.dX;
} else if (this.y > 310 || this.y < 0) {
this.dY = -this.dY;
}
this.x += this.dX;
this.y += this.dY;
})
.onHit("MAN", function () {
over();
});
}
var lv = setInterval("kill()", 1000);
var time = 0;
function times() {
time++;
}
var ti = setInterval("times()", 1000);
function over() {
clearInterval(lv);
clearInterval(ti);
setTimeout('Crafty.stop()', 0);
re.innerHTML = "好男人坚持了 " + time + " 秒让心爱的女人受了点伤!再来!";
re.style.display = "block";
shareInfo.shareTitle = "好男人坚持了" + time + "秒让心爱的女人受了点伤!";
}
function restart() {
location.replace(location.href);
}
function handleOrientation(event) {
var x = event.beta; // In degree in the range [-180,180]
var y = event.gamma; // In degree in the range [-90,90]
output.innerHTML = "beta : " + x + "\n";
output.innerHTML += "gamma: " + y + "\n";
// Because we don't want to have the device upside down
// We constrain the x value to the range [-45,45]
if (x > 45) {
x = 45
}
if (x < -45) {
x = -45
}
// To make computation easier we shift the range of
// x and y to [0,90]
x += 45;
y += 45;
// 10 is half the size of the ball
// It center the positionning point to the center of the ball
man.y = 300 * x / 90 - 10;
man.x = 300 * y / 90 - 10;
}
window.addEventListener('deviceorientation', handleOrientation);
function shareFriend() {
WeixinJSBridge.invoke('sendAppMessage', {
"appid" : shareInfo.appid,
"img_url" : shareInfo.imgUrl,
"img_width" : "200",
"img_height": "200",
"link" : shareInfo.lineLink,
"desc" : shareInfo.descContent,
"title" : shareInfo.shareTitle
}, function (res) {
//_report('send_msg', res.err_msg);
})
}
function shareTimeline() {
WeixinJSBridge.invoke('shareTimeline', {
"img_url" : shareInfo.imgUrl,
"img_width" : "200",
"img_height": "200",
"link" : shareInfo.lineLink,
"desc" : shareInfo.descContent,
"title" : shareInfo.shareTitle
}, function (res) {
//_report('timeline', res.err_msg);
});
}
function shareWeibo() {
WeixinJSBridge.invoke('shareWeibo', {
"content": shareInfo.descContent,
"url" : shareInfo.lineLink
}, function (res) {
//_report('weibo', res.err_msg);
});
}
// 当微信内置浏览器完成内部初始化后会触发WeixinJSBridgeReady事件。
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
// 发送给好友
WeixinJSBridge.on('menu:share:appmessage', function (argv) {
shareFriend();
});
// 分享到朋友圈
WeixinJSBridge.on('menu:share:timeline', function (argv) {
shareTimeline();
});
// 分享到微博
WeixinJSBridge.on('menu:share:weibo', function (argv) {
shareWeibo();
});
}, false);
</script>
<img src="man.jpg" class="pic">
</body>
</html>