Update index.html
Browse files- index.html +52 -9
index.html
CHANGED
@@ -14,11 +14,11 @@
|
|
14 |
<a-plane src="#groundTexture" rotation="-90 0 0" height="100" width="100"></a-plane>
|
15 |
<a-entity id="player" position="0 1.5 -5" movement></a-entity>
|
16 |
<a-entity id="bird-swarm">
|
17 |
-
<a-sphere color="#F44336" position="0 1.5 -10" radius="0.5"></a-sphere>
|
18 |
-
<a-sphere color="#E91E63" position="0 1.5 -11" radius="0.5"></a-sphere>
|
19 |
-
<a-sphere color="#9C27B0" position="0 1.5 -12" radius="0.5"></a-sphere>
|
20 |
-
<a-sphere color="#2196F3" position="0 1.5 -13" radius="0.5"></a-sphere>
|
21 |
-
<a-sphere color="#4CAF50" position="0 1.5 -14" radius="0.5"></a-sphere>
|
22 |
</a-entity>
|
23 |
</a-scene>
|
24 |
|
@@ -64,7 +64,7 @@
|
|
64 |
});
|
65 |
|
66 |
document.addEventListener('keyup', function (event) {
|
67 |
-
switch (
|
68 |
case 'ArrowUp':
|
69 |
case 'ArrowDown':
|
70 |
stateMachine.stop();
|
@@ -74,19 +74,50 @@
|
|
74 |
|
75 |
var birdSwarm = document.querySelector('#bird-swarm');
|
76 |
var birdState = 'idle';
|
|
|
77 |
|
78 |
var birdStateMachine = new StateMachine({
|
79 |
init: 'follow',
|
80 |
transitions: [
|
81 |
{ name: 'follow', from: 'idle', to: 'follow' },
|
82 |
-
{ name: 'stop', from: 'follow', to: 'idle' }
|
|
|
|
|
83 |
],
|
84 |
methods: {
|
85 |
onEnterFollow: function () {
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
},
|
88 |
onLeaveFollow: function () {
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
}
|
91 |
}
|
92 |
});
|
@@ -117,6 +148,18 @@
|
|
117 |
break;
|
118 |
}
|
119 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
}
|
121 |
});
|
122 |
</script>
|
|
|
14 |
<a-plane src="#groundTexture" rotation="-90 0 0" height="100" width="100"></a-plane>
|
15 |
<a-entity id="player" position="0 1.5 -5" movement></a-entity>
|
16 |
<a-entity id="bird-swarm">
|
17 |
+
<a-sphere class="bird" color="#F44336" position="0 1.5 -10" radius="0.5"></a-sphere>
|
18 |
+
<a-sphere class="bird" color="#E91E63" position="0 1.5 -11" radius="0.5"></a-sphere>
|
19 |
+
<a-sphere class="bird" color="#9C27B0" position="0 1.5 -12" radius="0.5"></a-sphere>
|
20 |
+
<a-sphere class="bird" color="#2196F3" position="0 1.5 -13" radius="0.5"></a-sphere>
|
21 |
+
<a-sphere class="bird" color="#4CAF50" position="0 1.5 -14" radius="0.5"></a-sphere>
|
22 |
</a-entity>
|
23 |
</a-scene>
|
24 |
|
|
|
64 |
});
|
65 |
|
66 |
document.addEventListener('keyup', function (event) {
|
67 |
+
switch (
|
68 |
case 'ArrowUp':
|
69 |
case 'ArrowDown':
|
70 |
stateMachine.stop();
|
|
|
74 |
|
75 |
var birdSwarm = document.querySelector('#bird-swarm');
|
76 |
var birdState = 'idle';
|
77 |
+
var birdInterval;
|
78 |
|
79 |
var birdStateMachine = new StateMachine({
|
80 |
init: 'follow',
|
81 |
transitions: [
|
82 |
{ name: 'follow', from: 'idle', to: 'follow' },
|
83 |
+
{ name: 'stop', from: 'follow', to: 'idle' },
|
84 |
+
{ name: 'click', from: 'follow', to: 'click' },
|
85 |
+
{ name: 'release', from: 'click', to: 'follow' }
|
86 |
],
|
87 |
methods: {
|
88 |
onEnterFollow: function () {
|
89 |
+
birdInterval = setInterval(function () {
|
90 |
+
var birds = document.querySelectorAll('.bird');
|
91 |
+
var birdPosition = birdSwarm.getAttribute('position');
|
92 |
+
var randomX = Math.random() * 0.4 - 0.2;
|
93 |
+
var randomY = Math.random() * 0.4 - 0.2;
|
94 |
+
var randomZ = Math.random() * 0.4 - 0.2;
|
95 |
+
birds.forEach(function (bird) {
|
96 |
+
bird.setAttribute('animation', 'property: position; to: ' + (birdPosition.x + randomX) + ' ' + (birdPosition.y + randomY) + ' ' + (birdPosition.z + randomZ) + '; dur: 1000');
|
97 |
+
});
|
98 |
+
}, 1000);
|
99 |
},
|
100 |
onLeaveFollow: function () {
|
101 |
+
clearInterval(birdInterval);
|
102 |
+
var birds = document.querySelectorAll('.bird');
|
103 |
+
birds.forEach(function (bird) {
|
104 |
+
bird.setAttribute('animation', '');
|
105 |
+
});
|
106 |
+
},
|
107 |
+
onClick: function (event, from, to) {
|
108 |
+
var target = event.target;
|
109 |
+
target.setAttribute('animation__click', 'property: position; to: 0 2.5 -5; dur: 1000');
|
110 |
+
},
|
111 |
+
onRelease: function (event, from, to) {
|
112 |
+
var target = event.target;
|
113 |
+
target.removeAttribute('animation__click');
|
114 |
+
var birdInterval = setInterval(function () {
|
115 |
+
var birdPosition = target.getAttribute('position');
|
116 |
+
var randomX = Math.random() * 0.4 - 0.2;
|
117 |
+
var randomY = Math.random() * 0.4 - 0.2;
|
118 |
+
var randomZ = Math.random() * 0.4 - 0.2;
|
119 |
+
target.setAttribute('animation', 'property: position; to: ' + (birdPosition.x + randomX) + ' ' + (birdPosition.y + randomY) + ' ' + (birdPosition.z + randomZ) + '; dur: 1000');
|
120 |
+
}, 1000);
|
121 |
}
|
122 |
}
|
123 |
});
|
|
|
148 |
break;
|
149 |
}
|
150 |
});
|
151 |
+
|
152 |
+
var birds = document.querySelectorAll('.bird');
|
153 |
+
birds.forEach(function (bird) {
|
154 |
+
bird.addEventListener('mousedown', function (event) {
|
155 |
+
birdStateMachine.click
|
156 |
+
}, false);
|
157 |
+
|
158 |
+
bird.addEventListener('mouseup', function (event) {
|
159 |
+
birdStateMachine.release(event);
|
160 |
+
}, false);
|
161 |
+
});
|
162 |
+
});
|
163 |
}
|
164 |
});
|
165 |
</script>
|