-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
596 lines (496 loc) · 19.6 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
<!DOCTYPE html>
<script src='vendor/require.js/require.js'></script>
<script src='vendor/three.js/build/three.js'></script>
<script src='vendor/three.js/examples/js/renderers/CSS3DRenderer.js'></script>
<script src='vendor/three.js/examples/js/loaders/ColladaLoader.js'></script>
<title>Game MENU</title>
<link rel="icon" href="https://fav.farm/🔥" />
<body style='margin: 0px; background-color: #bbbbbb; overflow: hidden;'>
<style>
@font-face { /* for mute button which is part of awesome font */
font-family: 'FontAwesome';
src: url('vendor/Font-Awesome/font/fontawesome-webfont.eot?v=3.2.1');
src: url('vendor/Font-Awesome/font/fontawesome-webfont.eot?#iefix&v=3.2.1') format('embedded-opentype'), url('vendor/Font-Awesome/font/fontawesome-webfont.woff?v=3.2.1') format('woff'), url('vendor/Font-Awesome/font/fontawesome-webfont.ttf?v=3.2.1') format('truetype'), url('vendor/Font-Awesome/font/fontawesome-webfont.svg#fontawesomeregular?v=3.2.1') format('svg');
font-weight: normal;
font-style: normal;
}
</style>
<style>
.osdFont {
font-family : arial, verdana, sans-serif;
font-size : 200%;
font-weight : bolder;
transition : opacity 0.5s ease;
-webkit-transition : opacity 0.5s ease;
color : #000;
text-shadow : 0 0 0.2em #fbc, 0 0 0.2em #fbc, 0 0 0.2em #fbc;
}
.osdFont {
opacity: 0
}
.osdFont.visible {
opacity: 1
}
.clickableOsd {
padding: 4px;
margin: 4px;
}
.clickableOsd:hover {
background-color: rgba(255,0,0,0.5);
border-radius : 6px;
pointer : 'hand';
}
.osdIcon {
font-family: FontAwesome;
font-size: 500%
}
</style>
<style>
#tvSetOsd {
position: absolute;
top: 20px;
left: 20px;
}
#exitOsd:before {
content: "\f0e2"
}
#menuOsd:before {
content: "\f039"
}
</style>
<style>
.tv-button {
background-color: inherit;
color: #fff;
border: none;
padding: 10px 20px;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
.tv-button:hover {
background-color: #000000;
}
.tv-button:active {
background-color: #000000;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.8);
}
</style>
<div id='tvSetOsd'>
<div id="menuOsd" class='osdFont clickableOsd osdIcon' title='Goto Menu'></div>
<div id="exitOsd" class='osdFont clickableOsd osdIcon' title='Go Back Walking'></div>
</div>
<div class="container">
<a href="https://akdavis83.github.io/Space-Maze/" target="_blank"><button class="tv-button" style="margin: 40px;">Space Maze</button></a>
<a href="https://akdavis83.github.io/Scrabble/" target="_blank"><button class="tv-button">Scrabble</button></a>
<a href="https://akdavis83.github.io/Snake-Game/" target="_blank"><button class="tv-button">Snake Game</button></a>
<a href="https://akdavis83.github.io/chess-ai/" target="_blank"><button class="tv-button">Chess</button></a>
<a href="https://akdavis83.github.io/Copy-Cat/" target="_blank"><button class="tv-button">Copy Cat</button></a>
<a href="https://akdavis83.github.io/Ultimate-Asteroids/" target="_blank"><button class="tv-button">Asteroids</button></a>
<a href="https://akdavis83.github.io/Mini-Game/" target="_blank"><button class="tv-button">Mini Game</button></a>
</div>
<script>
require([ 'bower_components/threex.minecraft/package.require.js'
, 'bower_components/threex.montainsarena/package.require.js'
, 'bower_components/threex.daynight/package.require.js'
, 'bower_components/threex.htmlmixer/package.require.js'
, 'bower_components/threex.windowresize/package.require.js'
, 'bower_components/threex.tvset/package.require.js'
, 'bower_components/threex.domevents/threex.domevents.js'
, 'bower_components/threex.domevents/threex.linkify.js'
], function(){
var renderer = new THREE.WebGLRenderer({
antialias : true
});
renderer.setSize( window.innerWidth, window.innerHeight );
// renderer.setSize( 256,256 );
document.body.appendChild( renderer.domElement );
var onRenderFcts= []
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.01, 30000 );
// var camera = new THREE.PerspectiveCamera(45, 256/256, 0.01, 1000 );
camera.position.z = 2;
//////////////////////////////////////////////////////////////////////////////////
// handle window resize //
//////////////////////////////////////////////////////////////////////////////////
THREEx.WindowResize(renderer, camera)
window.addEventListener('resize', function(event){
mixerContext.rendererCSS.setSize( window.innerWidth, window.innerHeight )
}, false)
//////////////////////////////////////////////////////////////////////////////////
// set 3 point lighting //
//////////////////////////////////////////////////////////////////////////////////
;(function(){
// add a ambient light
var light = new THREE.AmbientLight( 0x020202 )
scene.add( light )
// add a light in front
var light = new THREE.DirectionalLight('white', 1)
light.position.set(0.5, 0.5, 2)
scene.add( light )
// add a light behind
var light = new THREE.DirectionalLight('white', 0.75)
light.position.set(-0.5, -0.5, -2)
scene.add( light )
})()
//////////////////////////////////////////////////////////////////////////////////
// comment //
//////////////////////////////////////////////////////////////////////////////////
var sunAngle = Math.PI+Math.PI/2;
onRenderFcts.push(function(delta, now){
var dayDuration = 200
sunAngle -= delta/dayDuration * Math.PI*2
})
//////////////////////////////////////////////////////////////////////////////////
// starfield //
//////////////////////////////////////////////////////////////////////////////////
var starField = new THREEx.DayNight.StarField()
scene.add(starField.object3d)
onRenderFcts.push(function(delta, now){
starField.update(sunAngle)
})
//////////////////////////////////////////////////////////////////////////////////
// sunSphere //
//////////////////////////////////////////////////////////////////////////////////
var sunSphere = new THREEx.DayNight.SunSphere()
scene.add( sunSphere.object3d )
onRenderFcts.push(function(delta, now){
sunSphere.update(sunAngle)
})
//////////////////////////////////////////////////////////////////////////////////
// directionalLight //
//////////////////////////////////////////////////////////////////////////////////
var sunLight = new THREEx.DayNight.SunLight()
scene.add( sunLight.object3d )
onRenderFcts.push(function(delta, now){
sunLight.update(sunAngle)
})
//////////////////////////////////////////////////////////////////////////////////
// skydom //
//////////////////////////////////////////////////////////////////////////////////
var skydom = new THREEx.DayNight.Skydom()
scene.add( skydom.object3d )
onRenderFcts.push(function(delta, now){
skydom.update(sunAngle)
})
//////////////////////////////////////////////////////////////////////////////////
// add the montains //
//////////////////////////////////////////////////////////////////////////////////
THREEx.MontainsArena.defaultMaterial = THREE.MeshPhongMaterial
var mesh = new THREEx.MontainsArena()
mesh.scale.multiplyScalar(1000)
scene.add(mesh)
//////////////////////////////////////////////////////////////////////////////////
// ground //
//////////////////////////////////////////////////////////////////////////////////
var textureUrl = 'images/grasslight-small.jpg';
var texture = THREE.ImageUtils.loadTexture(textureUrl);
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.x= 100
texture.repeat.y= 100
texture.anisotropy = 160;
var geometry = new THREE.CircleGeometry(3000, 3200)
var material = new THREE.MeshPhongMaterial({
map : texture,
})
var mesh = new THREE.Mesh(geometry, material)
mesh.lookAt(new THREE.Vector3(0,1,0))
scene.add(mesh)
//////////////////////////////////////////////////////////////////////////////////
// comment //
//////////////////////////////////////////////////////////////////////////////////
THREEx.MinecraftChar.defaultMaterial = THREE.MeshPhongMaterial
var player = new THREEx.MinecraftPlayer()
player.character.root.rotation.y = Math.PI
player.character.root.position.x = 0
player.character.root.position.z = 5
scene.add(player.character.root)
onRenderFcts.push(function(delta, now){
player.update(delta, now)
})
// attach camera to player
// player.character.root.add(camera)
// camera.position.z = -2
// camera.position.y = 1.2
// camera.lookAt(new THREE.Vector3(0,0.5,3))
var cameraControlsDisabled = false
// keep the camera behind the player
// - complex but html.mixer needs the camera to be at the world level
onRenderFcts.push(function(delta){
if( cameraControlsDisabled ) return
var object3d = player.character.root
// set camera position
var vector = new THREE.Vector3(0, 1.2,-2);
var matrix = new THREE.Matrix4().makeRotationY(object3d.rotation.y);
vector.applyMatrix4( matrix );
var position = object3d.position.clone().add(vector);
camera.position.copy(position)
// set camera lookAt
var vector = new THREE.Vector3(0, 1.2, 3);
var matrix = new THREE.Matrix4().makeRotationY(object3d.rotation.y);
vector.applyMatrix4( matrix );
var target = object3d.position.clone().add(vector);
camera.lookAt(target)
})
//////////////////////////////////////////////////////////////////////////////////
// Camera Controls //
//////////////////////////////////////////////////////////////////////////////////
// var mouse = {x : 0, y : 0}
// document.addEventListener('mousemove', function(event){
// mouse.x = (event.clientX / window.innerWidth ) - 0.5
// mouse.y = (event.clientY / window.innerHeight) - 0.5
// }, false)
// onRenderFcts.push(function(delta, now){
// camera.position.x += (mouse.x*5 - camera.position.x) * (delta*3)
// camera.position.y += (mouse.y*5 - camera.position.y) * (delta*3)
// camera.lookAt( scene.position )
// })
//////////////////////////////////////////////////////////////////////////////////
// controls.input based on keyboard //
//////////////////////////////////////////////////////////////////////////////////
document.body.addEventListener('keydown', function(event){
var input = player.controls.input
if( event.keyCode === 'W'.charCodeAt(0) ) input.up = true
if( event.keyCode === 'S'.charCodeAt(0) ) input.down = true
if( event.keyCode === 'A'.charCodeAt(0) ) input.left = true
if( event.keyCode === 'D'.charCodeAt(0) ) input.right = true
if( event.keyCode === 'Q'.charCodeAt(0) ) input.strafeLeft= true
if( event.keyCode === 'E'.charCodeAt(0) ) input.strafeRight= true
// to support arrows because tsate asked me :)
if( event.keyCode === 38 ) input.up = true
if( event.keyCode === 40 ) input.down = true
if( event.keyCode === 37 && !event.shiftKey ) input.left = true
if( event.keyCode === 39 && !event.shiftKey ) input.right = true
if( event.keyCode === 37 && event.shiftKey ) input.strafeLeft= true
if( event.keyCode === 39 && event.shiftKey ) input.strafeRight= true
})
document.body.addEventListener('keyup', function(event){
var input = player.controls.input
// console.log(event.keyCode)
if( event.keyCode === 'W'.charCodeAt(0) ) input.up = false
if( event.keyCode === 'S'.charCodeAt(0) ) input.down = false
if( event.keyCode === 'A'.charCodeAt(0) ) input.left = false
if( event.keyCode === 'D'.charCodeAt(0) ) input.right = false
if( event.keyCode === 'Q'.charCodeAt(0) ) input.strafeLeft= false
if( event.keyCode === 'E'.charCodeAt(0) ) input.strafeRight= false
// to support arrows because tsate asked me :)
if( event.keyCode === 38 ) input.up = false
if( event.keyCode === 40 ) input.down = false
if( event.keyCode === 37 || event.shiftKey ) input.left = false
if( event.keyCode === 39 || event.shiftKey ) input.right = false
if( event.keyCode === 37 || !event.shiftKey ) input.strafeLeft= false
if( event.keyCode === 39 || !event.shiftKey ) input.strafeRight= false
})
//////////////////////////////////////////////////////////////////////////////////
// create THREEx.HtmlMixer //
//////////////////////////////////////////////////////////////////////////////////
var mixerContext= new THREEx.HtmlMixer.Context(renderer, scene, camera)
onRenderFcts.push(function(delta, now){
mixerContext.update(delta, now)
})
//////////////////////////////////////////////////////////////////////////////////
// init a domEvents //
//////////////////////////////////////////////////////////////////////////////////
var domEvents = new THREEx.DomEvents(camera, renderer.domElement)
//////////////////////////////////////////////////////////////////////////////////
// Game Room //
//////////////////////////////////////////////////////////////////////////////////
if( true ){
;(function(){
//////////////////////////////////////////////////////////////////////////////////
// create a Plane for THREEx.HtmlMixer //
//////////////////////////////////////////////////////////////////////////////////
// create the iframe element
var domElement = document.createElement('iframe')
domElement.src = 'bower_components/threex.tvset/examples/menu.html';
domElement.style.border = 'none'
// create the plane
var mixerPlane = new THREEx.HtmlMixer.Plane(mixerContext, domElement, {
planeW : 1/2.2,
planeH : 1/2.85,
})
// mixerPlane.object3d.scale.multiplyScalar(2)
// scene.add(mixerPlane.object3d)
onRenderFcts.push(function(delta, now){
mixerPlane.update(delta, now)
})
//////////////////////////////////////////////////////////////////////////////////
// comment //
//////////////////////////////////////////////////////////////////////////////////
var tvSet = new THREEx.TvSet()
tvSet.object3d.position.x = 0
tvSet.object3d.position.y = 0
tvSet.object3d.position.z = 0
tvSet.object3d.scale.multiplyScalar(10)
scene.add(tvSet.object3d)
tvSet.setScreenPlane(mixerPlane.object3d)
/**
* what is the state automata
* - state = sitting or walking
* - if state === walking and distance to object < threshold
* goto state = sitting
* - if state === sitting and press esc then goto state walking
*/
var state = 'walking'
onRenderFcts.push(function(){
var distanceTo = player.character.root.position.distanceTo(tvSet.object3d.position)
// console.log('distanceTo', distanceTo)
if( state === 'walking' && distanceTo < 4 ){
console.log('goto sitting')
state = 'sitting'
cameraControlsDisabled = true
camera.position.copy(tvSet.object3d.position)
camera.position.add(new THREE.Vector3(0,0.31,0.6).multiply(tvSet.object3d.scale))
camera.lookAt(new THREE.Vector3(0,camera.position.y,1))
document.querySelector('#menuOsd').classList.toggle('visible')
document.querySelector('#exitOsd').classList.toggle('visible')
}
})
document.querySelector('#menuOsd').addEventListener('click', function(){
domElement.src = 'bower_components/threex.tvset/examples/menu.html';
});
document.body.addEventListener('keydown', function(event){
if( event.keyCode === 27 ) tryToExit()
})
document.querySelector('#exitOsd').addEventListener('click', function(){
tryToExit()
})
function tryToExit(){
if( state === 'sitting' ){
state = 'walking'
cameraControlsDisabled = false
var delta = player.character.root.position.clone().sub(tvSet.object3d.position)
delta.setLength(4)
player.character.root.position.add(delta)
document.querySelector('#menuOsd').classList.toggle('visible')
document.querySelector('#exitOsd').classList.toggle('visible')
}
}
//////////////////////////////////////////////////////////////////////////////////
// big red button //
//////////////////////////////////////////////////////////////////////////////////
var geometry = new THREE.CylinderGeometry(0.1,0.1, 0.5, 16)
var material = new THREE.MeshPhongMaterial({
color : 'red'
});
var mesh = new THREE.Mesh(geometry, material)
mesh.position.set(0, -0.15, 0.3)
tvSet.object3d.add(mesh)
domEvents.bind(mesh, 'click', function(event){
domElement.src = 'bower_components/threex.tvset/examples/menu.html';
});
// bind 'mouseover'
domEvents.bind(mesh, 'mouseover', function(event){
document.body.style.cursor = 'pointer';
material.color.set('yellow')
}, false)
// bind 'mouseout'
domEvents.bind(mesh, 'mouseout', function(event){
document.body.style.cursor = 'default';
material.color.set('red')
}, false)})()
}
//////////////////////////////////////////////////////////////////////////////////
// BetterJS //
//////////////////////////////////////////////////////////////////////////////////
if( false ){
var mixerPlane = addPage({
url : 'http://betterjs.org',
position : new THREE.Vector3(0,1.4,6),
})
mixerPlane.scale.multiplyScalar(2)
addPage({
url : 'tweetiframe.html',
position : new THREE.Vector3(-5,1,6),
mixerPlaneOpts : { elementW : 500, planeW: 1, planeH: 705/500 }
})
}
//////////////////////////////////////////////////////////////////////////////////
// blog.jetienne.com //
//////////////////////////////////////////////////////////////////////////////////
if( false ){
addPage({
url : 'http://blog.jetienne.com/blog/2011/04/07/jquery-qrcode/',
position : new THREE.Vector3(-3,1,-3),
})
addPage({
url : 'http://blog.jetienne.com/blog/2013/04/23/debug-dot-js-global-detection/',
position : new THREE.Vector3(-1,1,-4),
})
addPage({
url : 'http://blog.jetienne.com/blog/2011/07/17/gowiththeflow.js-async-flow-control-with-a-zen-touch/',
position : new THREE.Vector3(+1,1,-4),
})
addPage({
url : 'http://blog.jetienne.com/blog/2011/03/22/microeventjs/',
position : new THREE.Vector3(+3,1,-3),
})
}
//////////////////////////////////////////////////////////////////////////////////
// learningthreejs //
//////////////////////////////////////////////////////////////////////////////////
if( false ){
addPage({
url : 'http://jeromeetienne.github.io/threex/',
position : new THREE.Vector3(3,1,2),
})
addPage({
url : 'http://www.threejsgames.com/',
position : new THREE.Vector3(-3,1,2),
})
addPage({
url : 'twitteriframe.html',
position : new THREE.Vector3(0,1,6),
mixerPlaneOpts : { elementW : 512 }
})
addPage({
url : 'http://learningthreejs.com/blog/2013/08/02/how-to-do-a-procedural-city-in-100lines/',
position : new THREE.Vector3(3,1,-6),
})
}
function addPage(options){
var url = options.url || console.assert(false)
var position = options.position || console.assert(false)
var mixerPlaneOpts = options.mixerPlaneOpts|| {
elementW : 1024
}
var mixerPlane = THREEx.HtmlMixer.createPlaneFromIframe(mixerContext, url, mixerPlaneOpts)
var object3d = mixerPlane.object3d
scene.add(object3d)
onRenderFcts.push(function(delta, now){
mixerPlane.update(delta, now)
})
object3d.position.copy(position)
object3d.scale.multiplyScalar(2)
// look at player
var target = player.character.root.position.clone()
target.y = object3d.position.y
object3d.lookAt(target)
return object3d
}
//////////////////////////////////////////////////////////////////////////////////
// render the scene //
//////////////////////////////////////////////////////////////////////////////////
onRenderFcts.push(function(){
renderer.render( scene, camera );
})
//////////////////////////////////////////////////////////////////////////////////
// loop runner //
//////////////////////////////////////////////////////////////////////////////////
var lastTimeMsec= null
requestAnimationFrame(function animate(nowMsec){
// keep looping
requestAnimationFrame( animate );
// measure time
lastTimeMsec = lastTimeMsec || nowMsec-1000/60
var deltaMsec = Math.min(200, nowMsec - lastTimeMsec)
lastTimeMsec = nowMsec
// call each update function
onRenderFcts.forEach(function(onRenderFct){
onRenderFct(deltaMsec/1000, nowMsec/1000)
})
})
})
</script></body>