Advertisement
Jack_Fog

Untitled

Apr 26th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <body></body>
  2. <script src="http://gamingJS.com/Three.js"></script>
  3. <script src="http://gamingJS.com/ChromeFixes.js"></script>
  4. <script>
  5.   // This is where stuff in our game will happen:
  6.   var scene = new THREE.Scene();
  7.  
  8.   // This is what sees the stuff:
  9.   var aspect_ratio = window.innerWidth / window.innerHeight;
  10.   var camera = new THREE.PerspectiveCamera(75, aspect_ratio, 1, 10000);
  11.   camera.position.z = 500;
  12.   scene.add(camera)
  13.  
  14.   // This will draw what the camera sees onto the screen:
  15.   var renderer = new THREE.CanvasRenderer();
  16.   renderer.setSize(window.innerWidth, window.innerHeight);
  17.   document.body.appendChild(renderer.domElement);
  18.  
  19.   // ******** START CODING ON THE NEXT LINE ********
  20. var marker = new THREE.Object3D();
  21. scene.add(marker);
  22.  
  23. var cover = new THREE.MeshNormalMaterial();
  24. var body  = new THREE.SphereGeometry(100);
  25. var avatar= new THREE.Mesh(body,cover);
  26. marker.add(avatar);
  27.  
  28. var hand = new THREE.SphereGeometry(50);
  29.  
  30. var right_hand = new THREE.Mesh(hand,cover);
  31. right_hand.position.set(-130,0,0);
  32. avatar.add(right_hand);
  33.  
  34. var left_hand = new THREE.Mesh(hand,cover);
  35. left_hand.position.set(130,0,0);
  36. avatar.add(left_hand);
  37.  
  38. var foot=new THREE.CylinderGeometry(10);
  39.  
  40. var right_foot = new THREE.Mesh(foot,cover);
  41. right_foot.position.set(-30,-120,0);
  42. avatar.add(right_foot);
  43.  
  44. var left_foot = new THREE.Mesh(foot,cover);
  45. left_foot.position.set(30,-120,0);
  46. avatar.add(left_foot);
  47. marker.add(camera);
  48.  
  49. //Bäume platzieren
  50.  
  51. makeTreeAt(500,0);
  52. makeTreeAt(-500,0);
  53. makeTreeAt(750,-1000);
  54. makeTreeAt(-750,-1000);
  55.  
  56. function makeTreeAt(x,z) {
  57.   var trunk = new THREE.Mesh(
  58.     new THREE.CylinderGeometry(50,50,200),
  59.     new THREE.MeshBasicMaterial({color:0xA0522D})
  60.     );
  61.     var top = new THREE.Mesh(
  62.       new THREE.SphereGeometry(150),
  63.       new THREE.MeshBasicMaterial({color:0x228B22})
  64.       );
  65.      
  66.       top.position.y = 175;
  67.       trunk.add(top);
  68.       trunk.position.set(x, -75, z);
  69.       scene.add(trunk);
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.   // Now, animate what the camera sees on the screen:
  77.   var is_cartwheeling =false;
  78.   var is_flipping =false;
  79.   renderer.render(scene, camera);
  80.   function animate() {
  81.   requestAnimationFrame(animate);
  82.   if(is_cartwheeling) {
  83.   avatar.rotation.z = avatar.rotation.z +0.05;
  84.   }
  85.   if (is_flipping) {
  86.   avatar.rotation.x = avatar.rotation.x +0.05;  
  87.   }
  88.   renderer.render(scene, camera);
  89.   }
  90.   animate();
  91.  
  92.   document.addEventListener('keydown',function(event) {
  93.     var code = event.keyCode;
  94.     if (code == 37)marker.position.x = marker.position.x-5; //nach links
  95.     if (code == 38)marker.position.z = marker.position.z-5; //hoch
  96.     if (code == 39)marker.position.x = marker.position.x+5; //nach rechts
  97.     if (code == 40)marker.position.z = marker.position.z+5; // nach unten
  98.    
  99.     if (code == 67) is_cartwheeling = !is_cartwheeling;//c
  100.     if (code == 70) is_flipping = !is_flipping;//f
  101.   });
  102.   </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement