Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <body bgcolor="#FFFFFF">
- <head>
- <title>s-haha-n game</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <Link rel=stylesheet href="css/base.css"/>
- </head>
- <body>
- <div id="message"></div>
- <script src="js/three.min.js"></script>
- <script src="js/Detector.js"></script>
- <script src="js/Stats.js"></script>
- <script src="js/OrbitControls.js"></script>
- <script src="js/THREEx.KeyboardState.js"></script>
- <script src="js/THREEx.FullScreen.js"></script>
- <script src="js/THREEx.WindowResize.js"></script>
- <!-- jQuery code to display an information button and box when clicked. -->
- <script src="js/jquery-1.9.1.js"></script>
- <script src="js/jquery-ui.js"></script>
- <link rel=stylesheet href="css/jquery-ui.css" />
- <link rel=stylesheet href="css/info.css"/>
- <script src="js/info.js"></script>
- <div style="position: absolute; bottom: 20px;">Bottom Text<br>By Shahan Akhter</br></div>
- <div id="infoButton"></div>
- <div id="infoBox" title="Help/Info">
- <img src="http://i.imgur.com/HWIvMOo.png?1" alt="Controls" width="570" height="300">
- <br><h1>'1' or '2' to switch Cameras<br></br>
- 'I' to get big (Shift+I) to get small<br></br>
- 'zero-0' to spin platforms<br></br>
- Shift to slow down --- RED IS BAD<br></br>
- 'm' to Fullscreen</h1></br>
- </div>
- <div id="ThreeJS" style="z=index: 2;"></div>
- <script>
- var container, scene, renderer, controls, stats;
- var keyboard = new THREEx.KeyboardState();
- var clock = new THREE.Clock();
- var cube;
- var camera;
- var matx = new THREE.MeshBasicMaterial({color: 0xffffff, wireframe:true});
- // custom global variables
- var MovingCube;
- var chaseCamera, topCamera;
- var chaseCameraActive = true;
- var particleGroup, particleAttributes;
- var collidableMeshList = [];
- var arrowList = [];
- var directionList = [];
- var health = 100000;
- init();
- animate();
- // FUNCTIONS
- function init()
- {
- // SCENE
- scene = new THREE.Scene();
- // CAMERA
- var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
- var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000;
- // camera 1
- topCamera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
- scene.add(topCamera);
- topCamera.position.set(0,400,1100);
- topCamera.lookAt(scene.position);
- // camera 2
- chaseCamera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
- scene.add(chaseCamera);
- // RENDERER
- if ( Detector.webgl )
- renderer = new THREE.WebGLRenderer( {antialias:true} );
- else
- renderer = new THREE.CanvasRenderer();
- renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
- container = document.getElementById( 'ThreeJS' );
- container.appendChild( renderer.domElement );
- // EVENTS
- THREEx.WindowResize(renderer, topCamera);
- THREEx.FullScreen.bindKey({ charCode : 'm'.charCodeAt(0) });
- // CONTROLS
- // MUST REMOVE THIS LINE FOR THIS DEMO.
- // controls = ...
- // LIGHT
- var light = new THREE.PointLight(0xFFFFFF , 1.5);
- light.position.set(0,400,-500);
- scene.add(light);
- var lightbulb = new THREE.Mesh(
- new THREE.SphereGeometry( 10, 16, 8 ),
- new THREE.MeshBasicMaterial( { color: 0x00FFFF} )
- );
- lightbulb.position = light.position;
- scene.add(lightbulb);
- var light2 = new THREE.PointLight(0xFFFFFF , 1.5);
- light2.position.set(0,400,500);
- scene.add(light2);
- var lightbulb2 = new THREE.Mesh(
- new THREE.SphereGeometry( 10, 16, 8 ),
- new THREE.MeshBasicMaterial( { color: 0x00FFFF} )
- );
- lightbulb2.position = light2.position;
- scene.add(lightbulb2);
- var ambientlight = new THREE.AmbientLight(0x111111);
- scene.add( ambientlight );
- // SKYBOX/FOG
- var skyBoxGeometry = new THREE.CubeGeometry( 10000, 10000, 10000 );
- var skyBoxMaterial = new THREE.MeshBasicMaterial( { color: 0x9999ff, side: THREE.BackSide } );
- var skyBox = new THREE.Mesh( skyBoxGeometry, skyBoxMaterial );
- // scene.add(skyBox);
- scene.fog = new THREE.FogExp2( 0x9999ff, 0.00025 );
- renderer.setClearColorHex(0xB24700, 1);
- ////////////
- // CUSTOM //
- ////////////
- var loader = new THREE.JSONLoader();
- loader.load( "models/ref.js", function(geometry){
- var material = new THREE.MeshPhongMaterial({color: 0x66768C});
- mesh = new THREE.Mesh(geometry, material);
- mesh.position.set(-50,280,0);
- // mesh.rotation.y = 4;
- mesh.scale.set(4,4,4);
- scene.add(mesh);
- });
- loader.load( "models/tallplat.js", function(geometry){
- var material = new THREE.MeshPhongMaterial({color: 0x218A70});
- tallplat= new THREE.Mesh(geometry, material);
- tallplat.position.set(0,100,0);
- //tallplat.scale.set(0.7,0.7,0.7);
- scene.add(tallplat);
- });
- loader.load( "models/rot1.js", function(geometry){
- var material = new THREE.MeshLambertMaterial({color: 0x0F0005});
- rot1= new THREE.Mesh(geometry, material);
- rot1.position.set(0,50,0);
- rot1.scale.set(5,5,5);
- scene.add(rot1);
- });
- loader.load( "models/rot2.js", function(geometry){
- var material = new THREE.MeshPhongMaterial({color: 0x000005});
- rot2= new THREE.Mesh(geometry, material);
- rot2.position.set(0,0,0);
- rot2.scale.set(85,85,85);
- scene.add(rot2);
- });
- //particles
- var particleTexture = THREE.ImageUtils.loadTexture( 'images/spikey.png' );
- particleGroup = new THREE.Object3D();
- particleAttributes = { startSize: [], startPosition: [], randomness: [] };
- var totalParticles = 200;
- var radiusRange = 14;
- for( var i = 0; i < totalParticles; i++ )
- {
- var spriteMaterial = new THREE.SpriteMaterial( { map: particleTexture, useScreenCoordinates: false, color: 0xffffff } );
- var sprite = new THREE.Sprite( spriteMaterial );
- sprite.scale.set( 7, 7, 1.0 ); // imageWidth, imageHeight
- sprite.position.set( Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5 );
- // for a cube:
- // sprite.position.multiplyScalar( radiusRange );
- // for a solid sphere:
- // sprite.position.setLength( radiusRange * Math.random() );
- // for a spherical shell:
- sprite.position.setLength( radiusRange * (Math.random() * 0.1 + 0.9) );
- // sprite.color.setRGB( Math.random(), Math.random(), Math.random() );
- sprite.material.color.setHSL( Math.random(), 0.9, 0.7 );
- // sprite.opacity = 0.80; // translucent particles
- sprite.material.blending = THREE.AdditiveBlending; // "glowing" particles
- particleGroup.add( sprite );
- // add variable qualities to arrays, if they need to be accessed later
- particleAttributes.startPosition.push( sprite.position.clone() );
- particleAttributes.randomness.push( Math.random() );
- }
- particleGroup.position.y = 230;
- particleGroup.position.x = -30;
- scene.add( particleGroup );
- //collision
- var wallGeometry = new THREE.CubeGeometry( 7, 7, 7, 1, 1, 1 );
- var wallMaterial = new THREE.MeshBasicMaterial( {color: 0xFF0000} );
- //var wireMaterial = new THREE.MeshBasicMaterial( { color: 0x000000, wireframe:true } );
- var wall = new THREE.Mesh(wallGeometry, wallMaterial);
- wall.position.set(-30, 230, 0);
- scene.add(wall);
- collidableMeshList.push(wall);
- //var wall = new THREE.Mesh(wallGeometry, wireMaterial);
- //wall.position.set(300, 200, 0);
- //scene.add(wall);
- var wall2 = new THREE.Mesh(wallGeometry, wallMaterial);
- wall2.position.set(200, 0, 0);
- wall2.scale.set(1,50,1);
- //wall2.rotation.y += 3.14159 / 2;
- scene.add(wall2);
- collidableMeshList.push(wall2);
- //var wall2 = new THREE.Mesh(wallGeometry, wireMaterial);
- //wall2.position.set(-200, 200, 0);
- //wall2.rotation.y = 3.14159 / 2;
- //scene.add(wall2);
- //collidableMeshList.push(light);//whyyy not???
- //what can and can't be pushed here?!
- }//end init
- function clearText()
- { document.getElementById('message').innerHTML = '--------- If you touch Red, his will display your health, which seems to be constantly going down I will fix that.';}
- function appendText(txt)
- { document.getElementById('message').innerHTML = '--------- This is your health: ' + health;}
- function animate()
- {
- requestAnimationFrame( animate );
- render();
- update();
- }
- function animate()
- {
- requestAnimationFrame( animate );
- render();
- update();
- }
- function update()
- {
- var delta = clock.getDelta(); // seconds.
- var moveDistance = 500 * delta; // 200 pixels per second
- var rotateAngle = Math.PI / 1.5 * delta; // pi/2
- if ( keyboard.pressed("shift") ){
- moveDistance = 200 * delta; // 200 pixels per second
- var rotateAngle = Math.PI / 2 * delta; // pi/2
- }
- // set the geometry to dynamic
- // so that it allow updates
- mesh.geometry.dynamic = true;
- // changes to the vertices
- mesh.geometry.verticesNeedUpdate = true;
- // changes to the normals
- mesh.geometry.normalsNeedUpdate = true;
- //super mode
- if ( keyboard.pressed("I") ) {
- mesh.scale.set(6,6,6);
- }
- if ( keyboard.pressed("shift+I") ) {
- mesh.scale.set(4,4,4);
- }
- if ( keyboard.pressed("0") ) {
- tallplat.rotation.y += .09;
- rot1.rotation.y += 0.1;
- rot2.rotation.y += -.01;
- }
- tallplat.rotation.y += 0.0009;
- rot1.rotation.y += 0.001;
- rot2.rotation.y += -0.001;
- //lightbulb.rotation.y += 0.05;
- // move forwards/backwards/left/right
- if ( keyboard.pressed("A") )
- mesh.translateZ( -moveDistance );
- if ( keyboard.pressed("D") )
- mesh.translateZ( moveDistance );
- if ( keyboard.pressed("S") )
- mesh.translateX( -moveDistance );
- if ( keyboard.pressed("W") )
- mesh.translateX( moveDistance );
- if ( keyboard.pressed("E") ) mesh.position.y = mesh.position.y-6;
- if ( keyboard.pressed("Q") ) mesh.position.y = mesh.position.y+6;
- var rotation_matrix = new THREE.Matrix4().identity();
- if ( keyboard.pressed("left") )
- mesh.rotateOnAxis( new THREE.Vector3(0,1,0), rotateAngle);
- if ( keyboard.pressed("right") )
- mesh.rotateOnAxis( new THREE.Vector3(0,1,0), -rotateAngle);
- if ( keyboard.pressed("o") )
- mesh.rotateOnAxis( new THREE.Vector3(1,0,0), rotateAngle);
- if ( keyboard.pressed("p") )
- mesh.rotateOnAxis( new THREE.Vector3(1,0,0), -rotateAngle);
- if ( keyboard.pressed("up") )
- mesh.rotateOnAxis( new THREE.Vector3(0,0,1), rotateAngle);
- if ( keyboard.pressed("down") )
- mesh.rotateOnAxis( new THREE.Vector3(0,0,1), -rotateAngle);
- if ( keyboard.pressed("Z") )
- {
- mesh.position.set(0,0,0);
- mesh.rotation.set(0,0,0);
- }
- var relativeCameraOffset = new THREE.Vector3(-70,15,0);
- var cameraOffset = relativeCameraOffset.applyMatrix4( mesh.matrixWorld );
- chaseCamera.position.x = cameraOffset.x;
- chaseCamera.position.y = cameraOffset.y;
- chaseCamera.position.z = cameraOffset.z;
- chaseCamera.lookAt( mesh.position );
- //camera.updateMatrix();
- //camera.updateProjectionMatrix();
- if ( keyboard.pressed("1") )
- { chaseCameraActive = true; }
- if ( keyboard.pressed("2") )
- { chaseCameraActive = false; }
- if ( keyboard.pressed("9") ){
- // mesh = THREE.Mesh(geometry, matx);
- //change ref mesh?!
- }
- var time = 4 * clock.getElapsedTime();
- for ( var c = 0; c < particleGroup.children.length; c ++ )
- {
- var sprite = particleGroup.children[ c ];
- // particle wiggle
- //var wiggleScale = 2;
- //sprite.position.x += wiggleScale * (Math.random() - 0.5);
- //sprite.position.y += wiggleScale * (Math.random() - 0.5);
- //sprite.position.z += wiggleScale * (Math.random() - 0.5);
- // pulse away/towards center
- // individual rates of movement
- var a = particleAttributes.randomness[c] + 1;
- var pulseFactor = Math.sin(a * time) * 0.1 + 0.9;
- sprite.position.x = particleAttributes.startPosition[c].x * pulseFactor;
- sprite.position.y = particleAttributes.startPosition[c].y * pulseFactor;
- sprite.position.z = particleAttributes.startPosition[c].z * pulseFactor;
- }
- //rotate the entire group
- //particleGroup.rotation.x = time * 0.5;
- //particleGroup.rotation.y = time * 0.09;
- particleGroup.rotation.z = time * 0.09;
- // collision detection:
- // determines if any of the rays from the cube's origin to each vertex
- // intersects any face of a mesh in the array of target meshes
- // for increased collision accuracy, add more vertices to the cube;
- // for example, new THREE.CubeGeometry( 64, 64, 64, 8, 8, 8, wireMaterial )
- // HOWEVER: when the origin of the ray is within the target mesh, collisions do not occur
- var originPoint = mesh.position.clone();
- clearText();
- for (var vertexIndex = 0; vertexIndex < mesh.geometry.vertices.length; vertexIndex++)
- {
- var localVertex = mesh.geometry.vertices[vertexIndex].clone();
- var globalVertex = localVertex.applyMatrix4( mesh.matrix );
- var directionVector = globalVertex.sub( mesh.position );
- var ray = new THREE.Raycaster( originPoint, directionVector.clone().normalize() );
- var collisionResults = ray.intersectObjects( collidableMeshList );
- if ( collisionResults.length > 0 && collisionResults[0].distance < directionVector.length() )
- appendText(" health");
- health--;
- // if(health <= 0) echo "OH NOES";
- }
- controls.update();
- stats.update();
- }//end animate
- function render()
- {
- if (chaseCameraActive)
- { renderer.render( scene, chaseCamera ); }
- else
- { renderer.render( scene, topCamera ); }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement