-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
74 lines (66 loc) · 1.33 KB
/
main.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
var size = 1;
var stage = new Kinetic.Stage({
container: 'container',
width: 900,
height: 900
});
var layer = new Kinetic.Layer();
var dragonArray = new Array();
dragonArray.push('right');
var border = new Kinetic.Rect({
x: 0,
y: 0,
width: stage.getWidth(),
height: stage.getHeight(),
stroke: 'black',
strokeWidth: 1
});
var line = new Kinetic.Line({
points: [[0,0]],
x: 450,
y: 450,
stroke: 'black',
strokeWidth: 1
});
function makeNextStep() {
for(var i = dragonArray.length-1; i >= 0; i--) {
switch(dragonArray[i]) {
case 'right':
dragonArray.push('up');
break;
case 'up':
dragonArray.push('left');
break;
case 'left':
dragonArray.push('down');
break;
case 'down':
dragonArray.push('right');
break;
}
};
var points = new Array();
points.push([0,0]);
for(var i = 0; i < dragonArray.length; i++) {
switch(dragonArray[i]) {
case 'right':
points.push([points[i][0]+size,points[i][1]]);
break;
case 'up':
points.push([points[i][0],points[i][1]-size]);
break;
case 'left':
points.push([points[i][0]-size,points[i][1]]);
break;
case 'down':
points.push([points[i][0],points[i][1]+size]);
break;
}
}
line.setPoints(points);
layer.draw();
};
KeyboardJS.on('space',makeNextStep,function(){});
layer.add(line);
layer.add(border)
stage.add(layer);