-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
138 lines (120 loc) · 6.46 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
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="https://aframe.io/releases/0.3.1/aframe.min.js"></script>
<!--<script src="../../dist/aframe-gamepad-controls.js"></script>-->
<script src="//cdn.rawgit.com/donmccurdy/aframe-extras/v2.6.0/dist/aframe-extras.min.js"></script>
<script src="spawnerjs.js"></script>
<script src="clicklistener.js"></script>
<script src="projectilejs.js"></script>
<script src="colliderjs.js"></script>
<script src="gamepadlistener.js"></script>
</head>
<body>
<a-scene id="myScene">
<a-assets>
<img id="enemy-sprite" src="assets/bird.png">
<a-mixin id="laser"
geometry="primitive: cylinder; radius: 0.05; translate: 0 -2 0; buffer: false"
material="color: green; metalness: 0.2; opacity: 0.4; roughness: 0.3"
rotation="90 0 0" projectile collider="target: .enemy"></a-mixin>
</a-assets>
<a-entity class="copier" layout="type: circle; radius: 5" position="1 2 0">
<a-animation attribute="position" dur="30000" easing="linear" repeat="indefinite" from="1 2 0" to="10 2 0"></a-animation>
<a-image class="enemy" look-at="#player" src="#enemy-sprite" transparent="true">
<!-- Attach collision handler animations. -->
<a-animation attribute="opacity" begin="collider-hit" dur="400"
ease="linear" from="1" to="0"></a-animation>
<a-animation attribute="scale" begin="collider-hit" dur="400"
ease="linear" to="0 0 0"></a-animation>
</a-image>
</a-entity>
<a-entity camera
id="player"
position="0 1 0"
look-controls
spawner="mixin: laser; on: gamepadbuttondown"
spawner_1="mixin: laser; on: click"
click-listener
gamepad-listener
gamepad-controls="flyEnabled: true"
universal-controls>
<!--sound="src: url(assets/321103__nsstudios__blip1.wav);
on: gamepadbuttondown:0"-->
</a-entity>
<!--
Example scene, blatantly copied from an official example:
https://github.com/aframevr/aframe/tree/master/examples/template-models
-->
<a-collada-model src="assets/tree1.dae" position="1 0 -1" rotation="0 30 0" scale="1.4 1.4 1.4"></a-collada-model>
<a-collada-model src="assets/tree2.dae" position="2.5 0 1.5" rotation="0 25 0" scale="1.4 1.4 1.4"></a-collada-model>
<a-collada-model src="assets/tree2.dae" position="-2 0 -4" rotation="0 60 0" scale="1.5 1.5 1.5"></a-collada-model>
<a-collada-model src="assets/tree1.dae" position="-8 0 -9" rotation="0 60 0" scale="1.4 1.4 1.4"></a-collada-model>
<a-collada-model src="assets/tree2.dae" position="-12 0 3" rotation="0 60 0" scale="1.5 1.5 1.5"></a-collada-model>
<a-collada-model src="assets/tree1.dae" position="-7 0 -3" rotation="0 60 0" scale="1.3 1.3 1.3"></a-collada-model>
<a-collada-model src="assets/tree2.dae" position="-4 0 1" rotation="0 10 0" scale="1.4 1.4 1.4"></a-collada-model>
<a-collada-model src="assets/tree1.dae" position="-5 0 5" rotation="0 45 0" scale="1.5 1.5 1.5"></a-collada-model>
<a-collada-model src="assets/tree2.dae" position="0 0 9" rotation="0 220 0" scale="1.6 1.6 1.6"></a-collada-model>
<a-collada-model src="assets/tree2.dae" position="-2 0 12" rotation="0 30 0" scale="1.4 1.4 1.4"></a-collada-model>
<a-collada-model src="assets/tree1.dae" position="-7 0 10" rotation="0 30 0" scale="1.4 1.4 1.4"></a-collada-model>
<!--
Sky
-->
<a-sky src="assets/peach-gradient-1.jpg"></a-sky>
<!--
Lighting
-->
<a-light type="ambient" color="#ccc"></a-light>
<a-light color="#ddf" distance="100" intensity="0.4" type="point"></a-light>
</a-scene>
<script>
var sceneEl = document.querySelector('a-scene');
$(function () {
generateBirds();
setTimeout(generateBirds(),30000);
});
var generateBirds = function()
{
for (var i = 0; i < 20; i++) {
var copier = document.querySelector('.copier').cloneNode(true);
var x = getRandomIntInclusive(-10, 10);
var z = getRandomIntInclusive(-10, 10);
copier.childNodes[1].setAttribute('from', x + ' 2 ' + z);
if (x > 6) {
var x1 = getRandomIntInclusive(-10, 0);
copier.childNodes[1].setAttribute('to', x1 + ' 2 0');
}
if (x < 6) {
var x1 = getRandomIntInclusive(0, 10);
copier.childNodes[1].setAttribute('to', x1 + ' 2 0');
}
sceneEl.appendChild(copier);
}
}
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
//sceneEl.addEventListener('gamepadbuttondown', function (e) {
// var boxEl = document.createElement('a-sphere');
// var position = new THREE.Vector3();
// boxEl.setAttribute('position', position);
// boxEl.setAttribute('color', 'red');
// boxEl.setAttribute('radius', '0.2');
// sceneEl.appendChild(boxEl)
//});
//sceneEl.addEventListener('click', function (e) {
// var boxEl = document.createElement('a-sphere');
// //console.log(document.querySelector('a-camera').components.camera.camera.getWorldDirection());
// var position = new THREE.Vector3();
// boxEl.setAttribute('position', sceneEl.camera.getWorldDirection());
// //boxEl.setAttribute('velocity', '2 0 ' + sceneEl.camera.getWorldDirection().x);
// boxEl.setAttribute('color', 'red');
// boxEl.setAttribute('radius', '0.2');
// boxEl.emit('start-link1');
// sceneEl.appendChild(boxEl)
//});
</script>
</body>
</html>