jmgraph 3.2.16 → 3.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +251 -428
- package/build/gulpfile.js +142 -142
- package/build/package-lock.json +10666 -0
- package/build/package.json +71 -71
- package/dev.js +9 -9
- package/dist/jmgraph.core.min.js +1 -1
- package/dist/jmgraph.core.min.js.map +1 -1
- package/dist/jmgraph.js +3500 -2668
- package/dist/jmgraph.min.js +1 -1
- package/example/ball.html +216 -216
- package/example/base.html +111 -111
- package/example/canvas.html +53 -53
- package/example/cell.html +283 -283
- package/example/controls/arc.html +128 -128
- package/example/controls/arrowline.html +77 -77
- package/example/controls/bezier.html +298 -298
- package/example/controls/img.html +96 -96
- package/example/controls/label.html +86 -86
- package/example/controls/line.html +172 -172
- package/example/controls/prismatic.html +62 -62
- package/example/controls/rect.html +63 -63
- package/example/controls/resize.html +111 -111
- package/example/controls/test.html +359 -359
- package/example/es.html +69 -69
- package/example/es5module.html +62 -63
- package/example/heartarc.html +115 -115
- package/example/index.html +46 -46
- package/example/js/require.js +4 -4
- package/example/love/img/bling/bling.tps +265 -265
- package/example/love/img/bling.json +87 -87
- package/example/love/img/bling.tps +295 -295
- package/example/love/img/love.json +95 -95
- package/example/love/img/love.tps +315 -315
- package/example/love/img/qq/qq.tps +399 -399
- package/example/love/img/qq.json +242 -242
- package/example/love/index.html +40 -40
- package/example/love/js/game.js +558 -558
- package/example/music.html +210 -210
- package/example/node/test.js +137 -137
- package/example/pdf.html +186 -186
- package/example/progress.html +172 -172
- package/example/pso.html +147 -147
- package/example/sort.html +804 -815
- package/example/tweenjs.html +83 -83
- package/example/webgl.html +278 -278
- package/example/xfj/index.html +331 -331
- package/example/xfj/shake.js +48 -48
- package/example/xfj/testori.html +75 -75
- package/index.js +99 -99
- package/package.json +58 -56
- package/src/core/jmControl.js +1376 -1531
- package/src/core/jmEvents.js +240 -281
- package/src/core/jmGradient.js +231 -231
- package/src/core/jmGraph.js +569 -569
- package/src/core/jmList.js +92 -157
- package/src/core/jmObject.js +83 -103
- package/src/core/jmPath.js +35 -35
- package/src/core/jmProperty.js +71 -110
- package/src/core/jmShadow.js +65 -65
- package/src/core/jmUtils.js +906 -919
- package/src/lib/earcut.js +680 -680
- package/src/lib/earcut.md +73 -73
- package/src/lib/webgl/base.js +522 -452
- package/src/lib/webgl/core/buffer.js +48 -48
- package/src/lib/webgl/core/mapSize.js +40 -40
- package/src/lib/webgl/core/mapType.js +43 -43
- package/src/lib/webgl/core/program.js +138 -138
- package/src/lib/webgl/core/shader.js +13 -13
- package/src/lib/webgl/core/texture.js +60 -60
- package/src/lib/webgl/gradient.js +168 -168
- package/src/lib/webgl/index.js +137 -11
- package/src/lib/webgl/path.js +568 -561
- package/src/shapes/jmArrowLine.js +36 -36
- package/src/shapes/jmImage.js +244 -244
- package/src/shapes/jmLabel.js +271 -271
- package/src/shapes/jmResize.js +332 -330
package/example/xfj/index.html
CHANGED
|
@@ -1,332 +1,332 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>小飞机</title>
|
|
5
|
-
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
|
|
6
|
-
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
|
|
7
|
-
<meta content="yes" name="apple-mobile-web-app-capable">
|
|
8
|
-
<meta content="black" name="apple-mobile-web-app-status-bar-style">
|
|
9
|
-
<script type="text/javascript" src="shake.js?2"></script>
|
|
10
|
-
<script type="text/javascript" src="../../index.js"></script>
|
|
11
|
-
<!--<script type="text/javascript" src="../../dist/jmGraph.min.js"></script> -->
|
|
12
|
-
<style>
|
|
13
|
-
html,body {
|
|
14
|
-
margin:0;
|
|
15
|
-
padding:0;
|
|
16
|
-
width:100%;
|
|
17
|
-
height:100%;
|
|
18
|
-
overflow: hidden;
|
|
19
|
-
-webkit-user-select: none; /* Chrome all / Safari all */
|
|
20
|
-
-moz-user-select: none; /* Firefox all */
|
|
21
|
-
-ms-user-select: none; /* IE 10+ */
|
|
22
|
-
/* No support for these yet, use at own risk */
|
|
23
|
-
-o-user-select: none;
|
|
24
|
-
user-select: none;
|
|
25
|
-
}
|
|
26
|
-
#mycanvas {
|
|
27
|
-
background-color:#000;
|
|
28
|
-
position: absolute;
|
|
29
|
-
width: 100%;
|
|
30
|
-
height: 100%;
|
|
31
|
-
}
|
|
32
|
-
</style>
|
|
33
|
-
</head>
|
|
34
|
-
<body >
|
|
35
|
-
<div style='display:none;'><img src="img/fj_ico.png" /></div>
|
|
36
|
-
<div id="mycanvas">
|
|
37
|
-
</div>
|
|
38
|
-
|
|
39
|
-
</body>
|
|
40
|
-
<script type="text/javascript">
|
|
41
|
-
var graph;
|
|
42
|
-
var sources = [
|
|
43
|
-
'img/bg.jpg',
|
|
44
|
-
'img/fj1.png',
|
|
45
|
-
'img/zd1.png',
|
|
46
|
-
'img/dr1.png'
|
|
47
|
-
];
|
|
48
|
-
window.onerror = function(msg,url,line,col,err) {
|
|
49
|
-
//alert(msg);
|
|
50
|
-
}
|
|
51
|
-
//初始化jmgraph
|
|
52
|
-
jmGraph('mycanvas').then((g)=>{
|
|
53
|
-
//jmUtils.bindEvent(window,'resize',resize);
|
|
54
|
-
graph = g;
|
|
55
|
-
init(g);
|
|
56
|
-
|
|
57
|
-
//实时更新画布
|
|
58
|
-
function update() {
|
|
59
|
-
if(g.needUpdate) {
|
|
60
|
-
var t1 = Date.now();
|
|
61
|
-
g.redraw();
|
|
62
|
-
|
|
63
|
-
var t2 = Date.now();
|
|
64
|
-
console.log('update:'+(t2-t1));
|
|
65
|
-
}
|
|
66
|
-
requestAnimationFrame(update);
|
|
67
|
-
}
|
|
68
|
-
update();
|
|
69
|
-
});
|
|
70
|
-
//初始化
|
|
71
|
-
function init(g) {
|
|
72
|
-
//背景
|
|
73
|
-
var bg1 = g.createShape('image',{
|
|
74
|
-
width: '100%',
|
|
75
|
-
height: '100%',
|
|
76
|
-
position: {x:0,y:-g.height},
|
|
77
|
-
image: sources[0]
|
|
78
|
-
});
|
|
79
|
-
g.children.add(bg1);
|
|
80
|
-
var bg2 = g.createShape('image',{
|
|
81
|
-
width: '100%',
|
|
82
|
-
height: '100%',
|
|
83
|
-
position: {x:0,y:0},
|
|
84
|
-
image: sources[0]
|
|
85
|
-
});
|
|
86
|
-
g.children.add(bg2);
|
|
87
|
-
/*var bg3 = g.createShape('image',{
|
|
88
|
-
width: '100%',
|
|
89
|
-
height: '100%',
|
|
90
|
-
position: {x:0,y:'100%'},
|
|
91
|
-
image: sources[0]
|
|
92
|
-
});
|
|
93
|
-
g.children.add(bg3);*/
|
|
94
|
-
|
|
95
|
-
var log = g.createShape('label', {
|
|
96
|
-
position: {x:0,y:0},
|
|
97
|
-
width: 200,
|
|
98
|
-
height: 50,
|
|
99
|
-
style: {
|
|
100
|
-
stroke: '#fff',
|
|
101
|
-
fill: '#fff',
|
|
102
|
-
zIndex: 100000,
|
|
103
|
-
border:{left:1,top:1,right:1,bottom:1}
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
g.children.add(log);
|
|
107
|
-
|
|
108
|
-
var mainRole = new fj(g);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
var touchLastPosition = {x:0,y:0};
|
|
112
|
-
g.bind('touchmove', function(arg){
|
|
113
|
-
var offsetx = arg.position.x;// - touchLastPosition.x;
|
|
114
|
-
var offsety = arg.position.y;// - touchLastPosition.y;
|
|
115
|
-
mainRole.move(offsetx-30, offsety-30);
|
|
116
|
-
});
|
|
117
|
-
g.bind('touchstart', function(arg){
|
|
118
|
-
touchLastPosition.x = arg.position.x;
|
|
119
|
-
touchLastPosition.y = arg.position.y;
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
var drCreateTime = Date.now();
|
|
123
|
-
setInterval(function(){
|
|
124
|
-
|
|
125
|
-
if(Date.now()-drCreateTime > 100) {
|
|
126
|
-
new dr1(g, {
|
|
127
|
-
x: Math.random() * (g.width-20),
|
|
128
|
-
y: -60
|
|
129
|
-
});
|
|
130
|
-
drCreateTime = Date.now();
|
|
131
|
-
}
|
|
132
|
-
var gbSpeed = 1;
|
|
133
|
-
//背景滚动
|
|
134
|
-
bg1.position.y += gbSpeed;
|
|
135
|
-
bg2.position.y += gbSpeed;
|
|
136
|
-
if(bg1.position.y >= g.height) {
|
|
137
|
-
bg1.position.y = -g.height;
|
|
138
|
-
}
|
|
139
|
-
if(bg2.position.y >= g.height) {
|
|
140
|
-
bg2.position.y = -g.height;
|
|
141
|
-
}
|
|
142
|
-
var t1 = Date.now();
|
|
143
|
-
g.children.each(function(i,dr){
|
|
144
|
-
if(dr && dr.isDR && dr.role.state == 1) {
|
|
145
|
-
if(dr.position.y > g.height) {
|
|
146
|
-
dr.die && dr.die();
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
var bound = dr.getBounds();
|
|
150
|
-
g.children.each(function(j,zd){
|
|
151
|
-
if(zd && zd.isZD) {
|
|
152
|
-
var zdbounds = zd.getBounds();
|
|
153
|
-
if(zdbounds.top <= bound.bottom && zdbounds.bottom > bound.bottom && zdbounds.right > bound.left && zdbounds.left < bound.right) {
|
|
154
|
-
dr.die && dr.die();
|
|
155
|
-
if(!zd.isBob) g.children.remove(zd);//如果不是超级炸弹,则子弹也消失
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
},true);
|
|
160
|
-
|
|
161
|
-
//如果敌人还活着,则向前走一步
|
|
162
|
-
if(dr.role.state == 1) {
|
|
163
|
-
dr.role.move();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if(mainRole.state !==0 && dr.role.state == 1) {
|
|
167
|
-
var meBound = mainRole.shape.getBounds();
|
|
168
|
-
if(bound.bottom >= meBound.top+5 && bound.top < meBound.bottom && bound.right > meBound.left+8 && bound.left < meBound.right-8) {
|
|
169
|
-
|
|
170
|
-
mainRole.die();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
},true);
|
|
175
|
-
var t2 = Date.now();
|
|
176
|
-
console.log('dr:' + (t2-t1));
|
|
177
|
-
|
|
178
|
-
}, 30);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
var dev = new devicemotion();
|
|
182
|
-
var lastDevOpt = null;
|
|
183
|
-
var lastDevTime = Date.now();
|
|
184
|
-
dev.bindShake({
|
|
185
|
-
handler: function(opt){
|
|
186
|
-
if(opt) {
|
|
187
|
-
if(Date.now()-lastDevTime < 50) return;
|
|
188
|
-
var gamma = opt.gamma || (opt.x*10);
|
|
189
|
-
var beta = opt.beta || (-opt.y*10);
|
|
190
|
-
var alpha = opt.alpha || (opt.z*10);
|
|
191
|
-
|
|
192
|
-
var x =Math.floor((gamma+20)/40*g.width/10) * 10;
|
|
193
|
-
var y = mainRole.shape.position.y;
|
|
194
|
-
|
|
195
|
-
log.value = 'x:' + x + ',y:' + y;
|
|
196
|
-
if(!isNaN(x) && !isNaN(y)) mainRole.move(x,y);
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
//alert(JSON.stringify(opt));
|
|
201
|
-
}
|
|
202
|
-
lastDevOpt = opt;
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function fj(g) {
|
|
209
|
-
this.shape = g.createShape('image',{
|
|
210
|
-
width: 60,
|
|
211
|
-
height: 60,
|
|
212
|
-
position: {x: g.width/2-20, y: g.height-100},
|
|
213
|
-
image: sources[1],
|
|
214
|
-
style: {
|
|
215
|
-
rotation: {
|
|
216
|
-
point: {x: '50%', y: '50%'},
|
|
217
|
-
angle: Math.PI
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
g.children.add(this.shape);
|
|
222
|
-
|
|
223
|
-
this.state = '1';//活着,2=死了
|
|
224
|
-
|
|
225
|
-
var self = this;
|
|
226
|
-
var lastZDTime = Date.now();
|
|
227
|
-
var bobTime = Date.now();//大炸弹出现时间
|
|
228
|
-
//不断地发射子弹
|
|
229
|
-
this.inter = setInterval(function(){
|
|
230
|
-
|
|
231
|
-
if(self.state == '1' && Date.now() - lastZDTime > 160) {
|
|
232
|
-
var w = 20;
|
|
233
|
-
var h = 20;
|
|
234
|
-
if(Date.now() - bobTime > 20000) {
|
|
235
|
-
w = 600;
|
|
236
|
-
bobTime = Date.now();
|
|
237
|
-
}
|
|
238
|
-
var zd = g.createShape('image',{
|
|
239
|
-
width: w,
|
|
240
|
-
height: h,
|
|
241
|
-
position: {x: self.shape.position.x + 30 - w/2, y: self.shape.position.y - h},
|
|
242
|
-
image: sources[2]
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
if(w > 20) {
|
|
246
|
-
zd.isBob = true;
|
|
247
|
-
}
|
|
248
|
-
zd.isZD = true;
|
|
249
|
-
g.children.add(zd);
|
|
250
|
-
lastZDTime = Date.now();
|
|
251
|
-
}
|
|
252
|
-
var t1 = Date.now();
|
|
253
|
-
g.children.each(function(i,z){
|
|
254
|
-
if(z&&z.isZD) {
|
|
255
|
-
z.position.y -= 1;
|
|
256
|
-
if(z.position.y <= 0) {
|
|
257
|
-
g.children.remove(z);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
}, true);
|
|
262
|
-
var t2 = Date.now();
|
|
263
|
-
console.log('fire:' + (t2-t1));
|
|
264
|
-
}, 5);
|
|
265
|
-
|
|
266
|
-
this.die = function() {
|
|
267
|
-
clearInterval(this.inter);
|
|
268
|
-
this.shape.visible = false;
|
|
269
|
-
alert('你死了');
|
|
270
|
-
this.state = 0;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
//移动
|
|
274
|
-
this.move = function(x, y) {
|
|
275
|
-
var pos = this.shape.position;
|
|
276
|
-
|
|
277
|
-
if(x <= -30) x = -30;
|
|
278
|
-
else if(x >= g.width-30) x = g.width-30;
|
|
279
|
-
|
|
280
|
-
if(y <= 0) y = 0;
|
|
281
|
-
else if(y >= g.height - 60) y = g.height - 60;
|
|
282
|
-
|
|
283
|
-
pos.x = x;
|
|
284
|
-
pos.y = y;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function dr1(g, pos){
|
|
289
|
-
|
|
290
|
-
this.speed = Math.random()+ 0.5;
|
|
291
|
-
var size = 30 * this.speed;
|
|
292
|
-
|
|
293
|
-
this.shape = g.createShape('image',{
|
|
294
|
-
width: size,
|
|
295
|
-
height: size,
|
|
296
|
-
position: pos,
|
|
297
|
-
image: sources[3]
|
|
298
|
-
});
|
|
299
|
-
this.shape.style.zIndex = size;
|
|
300
|
-
|
|
301
|
-
g.children.add(this.shape);
|
|
302
|
-
this.shape.role = this;
|
|
303
|
-
this.shape.isDR = true;
|
|
304
|
-
this.state = 1;
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
this.shape.die = function(){
|
|
308
|
-
|
|
309
|
-
var self = this;
|
|
310
|
-
//var ms = src.match(/dr1_die(\d+)\.png/);
|
|
311
|
-
/*var index = 1;
|
|
312
|
-
if(ms && ms.length>1){
|
|
313
|
-
index = Number(ms[1])+1;
|
|
314
|
-
} */
|
|
315
|
-
this.image = 'img/dr_die.gif';
|
|
316
|
-
|
|
317
|
-
this.role.state = 0;
|
|
318
|
-
clearInterval(this.role.inter);
|
|
319
|
-
|
|
320
|
-
setTimeout(function(){
|
|
321
|
-
g.children.remove(self);
|
|
322
|
-
}, 1000);
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
var that = this;
|
|
327
|
-
this.move = function(){
|
|
328
|
-
this.shape.position.y+=this.speed;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
</script>
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>小飞机</title>
|
|
5
|
+
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
|
|
6
|
+
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
|
|
7
|
+
<meta content="yes" name="apple-mobile-web-app-capable">
|
|
8
|
+
<meta content="black" name="apple-mobile-web-app-status-bar-style">
|
|
9
|
+
<script type="text/javascript" src="shake.js?2"></script>
|
|
10
|
+
<script type="text/javascript" src="../../index.js"></script>
|
|
11
|
+
<!--<script type="text/javascript" src="../../dist/jmGraph.min.js"></script> -->
|
|
12
|
+
<style>
|
|
13
|
+
html,body {
|
|
14
|
+
margin:0;
|
|
15
|
+
padding:0;
|
|
16
|
+
width:100%;
|
|
17
|
+
height:100%;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
-webkit-user-select: none; /* Chrome all / Safari all */
|
|
20
|
+
-moz-user-select: none; /* Firefox all */
|
|
21
|
+
-ms-user-select: none; /* IE 10+ */
|
|
22
|
+
/* No support for these yet, use at own risk */
|
|
23
|
+
-o-user-select: none;
|
|
24
|
+
user-select: none;
|
|
25
|
+
}
|
|
26
|
+
#mycanvas {
|
|
27
|
+
background-color:#000;
|
|
28
|
+
position: absolute;
|
|
29
|
+
width: 100%;
|
|
30
|
+
height: 100%;
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
33
|
+
</head>
|
|
34
|
+
<body >
|
|
35
|
+
<div style='display:none;'><img src="img/fj_ico.png" /></div>
|
|
36
|
+
<div id="mycanvas">
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
</body>
|
|
40
|
+
<script type="text/javascript">
|
|
41
|
+
var graph;
|
|
42
|
+
var sources = [
|
|
43
|
+
'img/bg.jpg',
|
|
44
|
+
'img/fj1.png',
|
|
45
|
+
'img/zd1.png',
|
|
46
|
+
'img/dr1.png'
|
|
47
|
+
];
|
|
48
|
+
window.onerror = function(msg,url,line,col,err) {
|
|
49
|
+
//alert(msg);
|
|
50
|
+
}
|
|
51
|
+
//初始化jmgraph
|
|
52
|
+
jmGraph('mycanvas').then((g)=>{
|
|
53
|
+
//jmUtils.bindEvent(window,'resize',resize);
|
|
54
|
+
graph = g;
|
|
55
|
+
init(g);
|
|
56
|
+
|
|
57
|
+
//实时更新画布
|
|
58
|
+
function update() {
|
|
59
|
+
if(g.needUpdate) {
|
|
60
|
+
var t1 = Date.now();
|
|
61
|
+
g.redraw();
|
|
62
|
+
|
|
63
|
+
var t2 = Date.now();
|
|
64
|
+
console.log('update:'+(t2-t1));
|
|
65
|
+
}
|
|
66
|
+
requestAnimationFrame(update);
|
|
67
|
+
}
|
|
68
|
+
update();
|
|
69
|
+
});
|
|
70
|
+
//初始化
|
|
71
|
+
function init(g) {
|
|
72
|
+
//背景
|
|
73
|
+
var bg1 = g.createShape('image',{
|
|
74
|
+
width: '100%',
|
|
75
|
+
height: '100%',
|
|
76
|
+
position: {x:0,y:-g.height},
|
|
77
|
+
image: sources[0]
|
|
78
|
+
});
|
|
79
|
+
g.children.add(bg1);
|
|
80
|
+
var bg2 = g.createShape('image',{
|
|
81
|
+
width: '100%',
|
|
82
|
+
height: '100%',
|
|
83
|
+
position: {x:0,y:0},
|
|
84
|
+
image: sources[0]
|
|
85
|
+
});
|
|
86
|
+
g.children.add(bg2);
|
|
87
|
+
/*var bg3 = g.createShape('image',{
|
|
88
|
+
width: '100%',
|
|
89
|
+
height: '100%',
|
|
90
|
+
position: {x:0,y:'100%'},
|
|
91
|
+
image: sources[0]
|
|
92
|
+
});
|
|
93
|
+
g.children.add(bg3);*/
|
|
94
|
+
|
|
95
|
+
var log = g.createShape('label', {
|
|
96
|
+
position: {x:0,y:0},
|
|
97
|
+
width: 200,
|
|
98
|
+
height: 50,
|
|
99
|
+
style: {
|
|
100
|
+
stroke: '#fff',
|
|
101
|
+
fill: '#fff',
|
|
102
|
+
zIndex: 100000,
|
|
103
|
+
border:{left:1,top:1,right:1,bottom:1}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
g.children.add(log);
|
|
107
|
+
|
|
108
|
+
var mainRole = new fj(g);
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
var touchLastPosition = {x:0,y:0};
|
|
112
|
+
g.bind('touchmove', function(arg){
|
|
113
|
+
var offsetx = arg.position.x;// - touchLastPosition.x;
|
|
114
|
+
var offsety = arg.position.y;// - touchLastPosition.y;
|
|
115
|
+
mainRole.move(offsetx-30, offsety-30);
|
|
116
|
+
});
|
|
117
|
+
g.bind('touchstart', function(arg){
|
|
118
|
+
touchLastPosition.x = arg.position.x;
|
|
119
|
+
touchLastPosition.y = arg.position.y;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
var drCreateTime = Date.now();
|
|
123
|
+
setInterval(function(){
|
|
124
|
+
|
|
125
|
+
if(Date.now()-drCreateTime > 100) {
|
|
126
|
+
new dr1(g, {
|
|
127
|
+
x: Math.random() * (g.width-20),
|
|
128
|
+
y: -60
|
|
129
|
+
});
|
|
130
|
+
drCreateTime = Date.now();
|
|
131
|
+
}
|
|
132
|
+
var gbSpeed = 1;
|
|
133
|
+
//背景滚动
|
|
134
|
+
bg1.position.y += gbSpeed;
|
|
135
|
+
bg2.position.y += gbSpeed;
|
|
136
|
+
if(bg1.position.y >= g.height) {
|
|
137
|
+
bg1.position.y = -g.height;
|
|
138
|
+
}
|
|
139
|
+
if(bg2.position.y >= g.height) {
|
|
140
|
+
bg2.position.y = -g.height;
|
|
141
|
+
}
|
|
142
|
+
var t1 = Date.now();
|
|
143
|
+
g.children.each(function(i,dr){
|
|
144
|
+
if(dr && dr.isDR && dr.role.state == 1) {
|
|
145
|
+
if(dr.position.y > g.height) {
|
|
146
|
+
dr.die && dr.die();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
var bound = dr.getBounds();
|
|
150
|
+
g.children.each(function(j,zd){
|
|
151
|
+
if(zd && zd.isZD) {
|
|
152
|
+
var zdbounds = zd.getBounds();
|
|
153
|
+
if(zdbounds.top <= bound.bottom && zdbounds.bottom > bound.bottom && zdbounds.right > bound.left && zdbounds.left < bound.right) {
|
|
154
|
+
dr.die && dr.die();
|
|
155
|
+
if(!zd.isBob) g.children.remove(zd);//如果不是超级炸弹,则子弹也消失
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},true);
|
|
160
|
+
|
|
161
|
+
//如果敌人还活着,则向前走一步
|
|
162
|
+
if(dr.role.state == 1) {
|
|
163
|
+
dr.role.move();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if(mainRole.state !==0 && dr.role.state == 1) {
|
|
167
|
+
var meBound = mainRole.shape.getBounds();
|
|
168
|
+
if(bound.bottom >= meBound.top+5 && bound.top < meBound.bottom && bound.right > meBound.left+8 && bound.left < meBound.right-8) {
|
|
169
|
+
|
|
170
|
+
mainRole.die();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
},true);
|
|
175
|
+
var t2 = Date.now();
|
|
176
|
+
console.log('dr:' + (t2-t1));
|
|
177
|
+
|
|
178
|
+
}, 30);
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
var dev = new devicemotion();
|
|
182
|
+
var lastDevOpt = null;
|
|
183
|
+
var lastDevTime = Date.now();
|
|
184
|
+
dev.bindShake({
|
|
185
|
+
handler: function(opt){
|
|
186
|
+
if(opt) {
|
|
187
|
+
if(Date.now()-lastDevTime < 50) return;
|
|
188
|
+
var gamma = opt.gamma || (opt.x*10);
|
|
189
|
+
var beta = opt.beta || (-opt.y*10);
|
|
190
|
+
var alpha = opt.alpha || (opt.z*10);
|
|
191
|
+
|
|
192
|
+
var x =Math.floor((gamma+20)/40*g.width/10) * 10;
|
|
193
|
+
var y = mainRole.shape.position.y;
|
|
194
|
+
|
|
195
|
+
log.value = 'x:' + x + ',y:' + y;
|
|
196
|
+
if(!isNaN(x) && !isNaN(y)) mainRole.move(x,y);
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
//alert(JSON.stringify(opt));
|
|
201
|
+
}
|
|
202
|
+
lastDevOpt = opt;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function fj(g) {
|
|
209
|
+
this.shape = g.createShape('image',{
|
|
210
|
+
width: 60,
|
|
211
|
+
height: 60,
|
|
212
|
+
position: {x: g.width/2-20, y: g.height-100},
|
|
213
|
+
image: sources[1],
|
|
214
|
+
style: {
|
|
215
|
+
rotation: {
|
|
216
|
+
point: {x: '50%', y: '50%'},
|
|
217
|
+
angle: Math.PI
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
g.children.add(this.shape);
|
|
222
|
+
|
|
223
|
+
this.state = '1';//活着,2=死了
|
|
224
|
+
|
|
225
|
+
var self = this;
|
|
226
|
+
var lastZDTime = Date.now();
|
|
227
|
+
var bobTime = Date.now();//大炸弹出现时间
|
|
228
|
+
//不断地发射子弹
|
|
229
|
+
this.inter = setInterval(function(){
|
|
230
|
+
|
|
231
|
+
if(self.state == '1' && Date.now() - lastZDTime > 160) {
|
|
232
|
+
var w = 20;
|
|
233
|
+
var h = 20;
|
|
234
|
+
if(Date.now() - bobTime > 20000) {
|
|
235
|
+
w = 600;
|
|
236
|
+
bobTime = Date.now();
|
|
237
|
+
}
|
|
238
|
+
var zd = g.createShape('image',{
|
|
239
|
+
width: w,
|
|
240
|
+
height: h,
|
|
241
|
+
position: {x: self.shape.position.x + 30 - w/2, y: self.shape.position.y - h},
|
|
242
|
+
image: sources[2]
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
if(w > 20) {
|
|
246
|
+
zd.isBob = true;
|
|
247
|
+
}
|
|
248
|
+
zd.isZD = true;
|
|
249
|
+
g.children.add(zd);
|
|
250
|
+
lastZDTime = Date.now();
|
|
251
|
+
}
|
|
252
|
+
var t1 = Date.now();
|
|
253
|
+
g.children.each(function(i,z){
|
|
254
|
+
if(z&&z.isZD) {
|
|
255
|
+
z.position.y -= 1;
|
|
256
|
+
if(z.position.y <= 0) {
|
|
257
|
+
g.children.remove(z);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
}, true);
|
|
262
|
+
var t2 = Date.now();
|
|
263
|
+
console.log('fire:' + (t2-t1));
|
|
264
|
+
}, 5);
|
|
265
|
+
|
|
266
|
+
this.die = function() {
|
|
267
|
+
clearInterval(this.inter);
|
|
268
|
+
this.shape.visible = false;
|
|
269
|
+
alert('你死了');
|
|
270
|
+
this.state = 0;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
//移动
|
|
274
|
+
this.move = function(x, y) {
|
|
275
|
+
var pos = this.shape.position;
|
|
276
|
+
|
|
277
|
+
if(x <= -30) x = -30;
|
|
278
|
+
else if(x >= g.width-30) x = g.width-30;
|
|
279
|
+
|
|
280
|
+
if(y <= 0) y = 0;
|
|
281
|
+
else if(y >= g.height - 60) y = g.height - 60;
|
|
282
|
+
|
|
283
|
+
pos.x = x;
|
|
284
|
+
pos.y = y;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function dr1(g, pos){
|
|
289
|
+
|
|
290
|
+
this.speed = Math.random()+ 0.5;
|
|
291
|
+
var size = 30 * this.speed;
|
|
292
|
+
|
|
293
|
+
this.shape = g.createShape('image',{
|
|
294
|
+
width: size,
|
|
295
|
+
height: size,
|
|
296
|
+
position: pos,
|
|
297
|
+
image: sources[3]
|
|
298
|
+
});
|
|
299
|
+
this.shape.style.zIndex = size;
|
|
300
|
+
|
|
301
|
+
g.children.add(this.shape);
|
|
302
|
+
this.shape.role = this;
|
|
303
|
+
this.shape.isDR = true;
|
|
304
|
+
this.state = 1;
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
this.shape.die = function(){
|
|
308
|
+
|
|
309
|
+
var self = this;
|
|
310
|
+
//var ms = src.match(/dr1_die(\d+)\.png/);
|
|
311
|
+
/*var index = 1;
|
|
312
|
+
if(ms && ms.length>1){
|
|
313
|
+
index = Number(ms[1])+1;
|
|
314
|
+
} */
|
|
315
|
+
this.image = 'img/dr_die.gif';
|
|
316
|
+
|
|
317
|
+
this.role.state = 0;
|
|
318
|
+
clearInterval(this.role.inter);
|
|
319
|
+
|
|
320
|
+
setTimeout(function(){
|
|
321
|
+
g.children.remove(self);
|
|
322
|
+
}, 1000);
|
|
323
|
+
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
var that = this;
|
|
327
|
+
this.move = function(){
|
|
328
|
+
this.shape.position.y+=this.speed;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
</script>
|
|
332
332
|
</html>
|