css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id="overlay">
	<div class="content">
		<img src="https://s10.postimg.org/tl0fb3mqx/image.png">
		<div>Click Anywhere to Start</div>
	</div>
</div>
<div id="UI">
	<div class="points">0</div>
	<div class="restart hidden">
		<div style="text-align: center; margin-top: -30px; position: relative; z-index: 10;"><img src="https://s10.postimg.org/tl0fb3mqx/image.png"></div>
		<div class="points">0</div>
		<div class="restartgame">RESTART</div>
	</div>
</div>
<div id="world" class="Three"></div>
            
          
!
            
              body, html {
	width: 100%;
	height: 100%;
	overflow: hidden;
}

#overlay {
	position: fixed;
	top: 0px;
	left: 0px;
	background-color: #34B5F6;
	height: 100%;
	width: 100%;
	z-index: 15;
	transition: all 400ms;
	
	.content {
		text-align: center;
		width: 100%;
		max-width: 400px;
		position: absolute;
		left: 50%;
		margin-left: -200px;
		top: 38%;
		transition: all 400ms;
		color: #FFF;
		transform: scale(1);
		
		img { 
			width: 100%;
		}
		div {
			display: block;
			width: 100%;
			text-align: center;
		}
	}
	
	&.hidden {
		opacity: 0;
		
		.content {
			transform: scale(0.5);
		}
	}
}

.Three {
	position: absolute;
	top: 0;
	bottom: 0;
	left: 0;
	right: 0;
	z-index: 0;
	overflow: hidden;
}
.hidden {
	display: none;
}
#UI {
	position: fixed;
	top: 0px;
	left: 0px;
	z-index: 9;
	pointer-events: none;
	
	.points {
		position: fixed;
		top: 10%;
		right: 10%;
		font-size: 100px;
		color: #FFF;
		font-weight: bold;
		text-shadow: 1px 2px 4px rgba(0,0,0,0.5);
	}
	.restart {
		pointer-events: all;
		position: fixed;
		width: 360px;
		height: 200px;
		left: 50%;
		margin-left: -155px;
		top: 50%;
		margin-top: -100px;
		background-color: #FFF;
		
		.points {
			position: absolute;
			height: 100%;
			width: 50%;
			line-height: 200px;
			text-align: center;
			text-shadow: none;
			font-size:  100px;
			color: #34B5F6;
			top: 0px;
			left: 0px;
		}
		.restartgame {
			position: absolute;
			right: 0px;
			top: 0px;
			width: 50%;
			height: 100%;
			color: #FFF;
			background-color: #34B5F6;
			font-weight: bold;
			line-height: 200px;
			text-align: center;
			font-size: 20px;
			cursor: pointer;
		}
	}
}

            
          
!
            
              'use strict';

// MESHES INCLUDED AS JS FILE

var cube = [],
    light, gobalLight, shadowLight, backLight;

// useful mathematic constants
var PI = Math.PI;

var monkeys = [],
    monkey,
    gravity = 0.2,
    road,
    roads = [],
    foreground,
    foregrounds = 0,
    citys = [],
    shills = [],
    floorlvl = 81,
    started = false,
    obsticle,
    obsticles = [],
    points = 0,
    pointgo = true,
    isdone = false;

function addPoint () {
	if(pointgo == true) {
		points++;
		$('#UI .points').html(points);
		pointgo = false;
		setTimeout(function(){
			pointgo = true; 
		}, 100);
	}
}

$('#UI .restartgame').on('click tap',function(){
	history.go(0);
});


// init the scene
var WIDTH = window.innerWidth,
    HEIGHT = window.innerHeight,
    RATIO = WIDTH / HEIGHT;

var FIELDVIEW = 60,
    NEAR = 1,
    FAR = 5000,
    CAMERA = new THREE.PerspectiveCamera(FIELDVIEW, RATIO, NEAR, FAR),
    SCENE = new THREE.Scene(),
    RENDERER = new THREE.WebGLRenderer({
	    alpha: true,
	    antialias: true
    });
RENDERER.setClearColor( 0x9AE3FF, 1);
RENDERER.shadowMapEnabled = true;
RENDERER.setSize(WIDTH, HEIGHT);
var mouse = new THREE.Vector2();

document.querySelector("#world").appendChild(RENDERER.domElement);

// render the scene
window.onresize = function () {
	WIDTH = window.innerWidth;
	HEIGHT = window.innerHeight;
	RATIO = WIDTH / HEIGHT;

	RENDERER.setSize(WIDTH, HEIGHT);

	CAMERA.aspect = RATIO;
	CAMERA.updateProjectionMatrix();
};
function initLight() {
	var globalLight = new THREE.HemisphereLight(0x92D2DB, 0x92D2DB, .2)

	var shadowLight = new THREE.DirectionalLight(0xdbc092, .9);
	shadowLight.position.set(200, 200, 200);
	shadowLight.castShadow = true;
	shadowLight.shadowDarkness = .2;
	shadowLight.shadowMapWidth = shadowLight.shadowMapHeight = 2048;

	var backLight = new THREE.DirectionalLight(0xdb92d2, .4);
	backLight.position.set(-100, 100, 100);
	backLight.castShadow = true;
	backLight.shadowDarkness = .1;
	backLight.shadowMapWidth = shadowLight.shadowMapHeight = 2048;

	SCENE.add(globalLight);
	SCENE.add(shadowLight);
	SCENE.add(backLight);
}
var obsticletopGeom = new THREE.BoxGeometry(8,100,30);
var obsticlebottomGeom = new THREE.BoxGeometry(8,100,30);

obsticle = function() {
	
	this.offy = Math.floor(Math.random() * 60) + 1;
	this.offy = this.offy - 30;
	
	this.obsticletop = new THREE.Mesh(obsticletopGeom, whiteMat);
	this.obsticletop.position.z = 0;
	this.obsticletop.position.y = 185;
	this.topy = 90 + this.offy;
	this.obsticletop.position.x = 0;
	
	this.obsticlebottom = new THREE.Mesh(obsticlebottomGeom, whiteMat);
	this.obsticlebottom.position.z = 0;
	this.obsticlebottom.position.y = -185;
	this.bottomy = -90 + this.offy;
	this.obsticlebottom.position.x = 0;
	
	this.obsticle = new THREE.Object3D();
	this.obsticle.add(this.obsticletop);
	this.obsticle.add(this.obsticlebottom);
	
	this.obsticle.position.y = 0;
	this.obsticle.position.x = 230;
	this.obsticle.position.z = -20;
	
	SCENE.add(this.obsticle);
	obsticles.push([this.obsticle, this.obsticletop, this.topy, this.obsticlebottom, this.bottomy]);
	
}

monkey = function() {

	this.hitboxGeom = new THREE.BoxGeometry(10,21,6);
	this.hitbox = new THREE.Mesh(this.hitboxGeom, whiteMat);
	this.hitbox.position.z = -10;
	this.hitbox.position.y = 0;
	this.hitbox.position.x = -28;
	this.hitbox.visible = false;
	
	this.brightface = new THREE.Object3D();
	this.brightface.add(face);
	this.brightface.add(browL);
	this.brightface.add(browR);
	this.brightface.add(face2);
	this.brightface.add(face3);
	this.brightface.add(face4);
	this.brightface.add(face5);

	// HEAD
	this.head = new THREE.Object3D();
	this.head.add(headm);
	this.head.add(headm2);
	this.head.add(headm3);
	this.head.add(headm4);
	this.head.add(headm5);
	this.head.add(this.brightface);
	this.head.add(eyeL);
	this.head.add(eyeR);
	this.eyeL = eyeL;
	this.eyeR = eyeR;

	this.head.position.y = 10;
	this.head.position.x = 2; 

	// TAIL

	this.tail = new THREE.Object3D();
	this.tail.add(tail);
	this.tail.add(tail2);
	this.tail.add(tail3);
	this.tail.add(tailcurl);

	this.tail.position.y = -1.5;
	this.tail.position.x = -7;

	this.tailcurl = tailcurl;

	// BODY

	this.torso = new THREE.Object3D();
	this.torso.add(torso);
	this.torso.add(torso2);
	this.torso.add(torso3);
	this.torso.add(torso4);
	this.torso.add(torso5);
	this.torso.add(torso6);  
	this.torso.add(this.tail);

	// BOARD

	this.board = new THREE.Object3D();
	this.board.add(board);
	this.board.add(boardend1);
	this.board.add(boardend2);
	this.board.add(stripe);

	this.board.position.y = -2.5;
	this.board.rotation.x = 0.3;

	// FEET

	this.feet = new THREE.Object3D();
	this.feet.add(footL);
	this.feet.add(footL2);
	this.feet.add(footR);
	this.feet.add(footR2); 
	this.feet.add(this.board); 


	this.feet.position.y = -4.5;  

	// LEFT ARM

	this.armL = new THREE.Object3D();
	this.armL.add(armL);
	this.armL.add(armL2);

	this.armL.position.z = 3.5;
	this.armL.position.x = -2;   
	this.armL.position.y = 0; 

	// RIGHT ARM

	this.armR = new THREE.Object3D();
	this.armR.add(armR);
	this.armR.add(armR2);

	this.armR.position.z = 3.5;
	this.armR.position.x = 6; 
	this.armR.position.y = 0; 

	//MONKEY	

	this.body = new THREE.Object3D();
	this.body.add(this.head);
	this.body.add(this.torso);
	this.body.add(this.feet);
	this.body.add(this.armL);
	this.body.add(this.armR);

	this.monkey = new THREE.Object3D();
	this.monkey.add(this.body);

	this.monkey.position.y = 0;
	this.monkey.position.x = -30;
	this.monkey.position.z = -10;


	this.monkey.rotation.y = 0.3;


	SCENE.add(this.monkey);

	monkeys = {
		'monkey' : this.monkey,
		'head' : this.head,
		'eyeL' : this.eyeL,
		'eyeR' : this.eyeR,
		'tail' : this.tail,
		'tailcurl' : this.tailcurl,
		'gravity': -gravity,
		'direction': 'up',
		'vy' : 0,
		'brightface' : this.brightface,
		'armL' : this.armL,
		'armR' : this.armR,
		'body' : this.body,
		'hitbox' : this.hitbox
	}
	SCENE.add(monkeys['hitbox']);
};

var road = function() {
	var greyMat = new THREE.MeshBasicMaterial ({
		color: 0xBEBEBE
	});
	var darkgreyMat = new THREE.MeshBasicMaterial ({
		color: 0x333333
	});

	var pathGeom = new THREE.BoxGeometry(1000,2,60);
	var roadGeom = new THREE.BoxGeometry(1000,1,20);

	var bpath = new THREE.Mesh(pathGeom, greyMat);
	bpath.position.z = -20;
	bpath.position.y = 0;
	bpath.position.x = 0

	var road = new THREE.Mesh(roadGeom, darkgreyMat);
	road.position.z = -19;
	road.position.y = 11;
	road.position.x = 0

	var tpath2 = new THREE.Mesh(pathGeom, greyMat);
	tpath2.position.z = -20;
	tpath2.position.y = 0;
	tpath2.position.x = 0;

	var road2 = new THREE.Mesh(roadGeom, darkgreyMat);
	road2.position.z = -19;
	road2.position.y = -11;
	road2.position.x = 0;

	this.bottompath = new THREE.Object3D();
	this.bottompath.add(bpath);
	this.bottompath.add(road);

	this.tpath = new THREE.Object3D();
	this.tpath.add(tpath2);
	this.tpath.add(road2);

	this.bottompath.position.y = -118;
	this.tpath.position.y = 118;


	SCENE.add(this.bottompath);
	SCENE.add(this.tpath);
}


var foreground = function(i) {
	var greenMat = new THREE.MeshLambertMaterial ({
		color: 0x7BE29F, 
		shading:THREE.FlatShading
	});
	var greyMat = new THREE.MeshBasicMaterial ({
		color: 0xBEBEBE, 
		shading:THREE.FlatShading
	});
	
	var darkgreyMat = new THREE.MeshBasicMaterial ({
		color: 0x333333, 
		shading:THREE.FlatShading
	});

	var hillGeom = new THREE.SphereGeometry(400,10,10);
	var hillsGeom = new THREE.SphereGeometry(300,10,10);

	var building1p1Geom = new THREE.BoxGeometry(70,140,40);
	var building1p2Geom = new THREE.BoxGeometry(30,20,40);
	var building3p1Geom = new THREE.BoxGeometry(30,50,30);
	var building4Geom = new THREE.BoxGeometry(80,110,40);
	var building2p1Geom = new THREE.BoxGeometry(70,140,40);

	var glassGeom = new THREE.BoxGeometry(10,20,1);
	var glass1Geom = new THREE.BoxGeometry(10,10,1);

	this.hillgroup = new THREE.Object3D();
	if(foregrounds != 1){
		if((foregrounds % 4) == 1){
			this.building1pt1 = new THREE.Mesh(building1p1Geom, whiteMat);

			this.building2pt1 = new THREE.Mesh(building2p1Geom, whiteMat);

			this.building1pt2 = new THREE.Mesh(building1p2Geom, whiteMat);
			this.building1pt2.position.y = 80;
			this.building1pt2.position.x = 20;

			this.glass = new THREE.Mesh(glassGeom, darkgreyMat);
			this.glass.position.y = 0;
			this.glass.position.x = 20;
			this.glass.position.z = 21;

			this.glass1z2 = this.glass.clone();
			this.glass1z2.position.x = 50;
			this.glass2z2 = this.glass.clone();

			this.glassrowx2 = new THREE.Object3D();
			this.glassrowx2.add(this.glass1z2);
			this.glassrowx2.add(this.glass2z2);

			this.glassrowx2z1 = this.glassrowx2.clone();
			this.glassrowx2z1.position.x = -35;
			this.glassrowx2z1.position.y = 10;
			this.glassrowx2z2 = this.glassrowx2.clone();
			this.glassrowx2z2.position.y = 40;
			this.glassrowx2z2.position.x = -35;

			this.glass1 = this.glass.clone();
			this.glass1.position.x = 20;
			this.glass2 = this.glass.clone();
			this.glass2.position.x = 0;
			this.glass3 = this.glass.clone();
			this.glass3.position.x = -20;

			this.glassrowx3 = new THREE.Object3D();
			this.glassrowx3.add(this.glass1);
			this.glassrowx3.add(this.glass2);
			this.glassrowx3.add(this.glass3);

			this.glassrowx3z1 = this.glassrowx3.clone();
			this.glassrowx3z1.position.y = -20;

			this.glassrowx3z2 = this.glassrowx3.clone();
			this.glassrowx3z2.position.y = 20;

			this.glassrowx3z3 = this.glassrowx3.clone();
			this.glassrowx3z3.position.y = 50;

			this.glassrowx3z4 = this.glassrowx3.clone();
			this.glassrowx3z4.position.y = -50;



			this.glassx1 = new THREE.Mesh(glass1Geom, darkgreyMat);
			this.glassx1.position.y = 75;
			this.glassx1.position.x = 20;
			this.glassx1.position.z = 21;

			this.buildingbig = new THREE.Object3D();
			this.buildingbig.add(this.building1pt1);
			this.buildingbig.add(this.building1pt2);
			this.buildingbig.add(this.glassx1);
			this.buildingbig.add(this.glassrowx3z1);
			this.buildingbig.add(this.glassrowx3z2);
			this.buildingbig.add(this.glassrowx3z3);
			this.buildingbig.add(this.glassrowx3z4);

			this.buildingbig.position.y = 460;
			this.buildingbig.position.x = 30;

			this.building1 = this.buildingbig.clone();

			this.building2 = new THREE.Object3D();
			this.building2.add(this.building2pt1);
			this.building2.add(this.glassrowx2z1);
			this.building2.add(this.glassrowx2z2);

			this.building2.position.y = 390;
			this.building2.position.z = -20; 
			this.building2.position.x = 100;

			this.b3glass = this.glass.clone();
			this.b3glass.position.x = 0;
			this.b3glass.position.y = 0.5;
			this.b3glass.position.z = 16;

			this.building3Mesh = new THREE.Mesh(building3p1Geom, whiteMat);
			this.building3 = new THREE.Object3D();
			this.building3.add(this.building3Mesh);
			this.building3.add(this.b3glass);

			this.building3.position.y = 410;
			this.building3.position.z = 25; 
			this.building3.rotation.y = -.2; 
			this.building3.position.x = -22;

			this.b4glassrowx3z1 = this.glassrowx3.clone();
			this.b4glassrowx3z1.position.x = -5;
			this.b4glassrowx3z1.position.y = 5;

			this.b4glassrowx3z2 = this.glassrowx3.clone();
			this.b4glassrowx3z2.position.x = -5;
			this.b4glassrowx3z2.position.y = 35;

			this.b4glassrowx3z3 = this.glassrowx3.clone();
			this.b4glassrowx3z3.position.x = -5;
			this.b4glassrowx3z3.position.y = -25;

			this.building4Mesh = new THREE.Mesh(building4Geom, whiteMat);
			this.building4 = new THREE.Object3D();
			this.building4.add(this.building4Mesh);
			this.building4.add(this.b4glassrowx3z1);
			this.building4.add(this.b4glassrowx3z2);
			this.building4.add(this.b4glassrowx3z3);

			this.building4.position.y = 425;
			this.building4.position.z = -15; 
			this.building4.rotation.y = -.2; 
			this.building4.position.x = -62;
			
			this.hillgroup.add(this.building1);
			this.hillgroup.add(this.building2);
			this.hillgroup.add(this.building3);
			this.hillgroup.add(this.building4);
		}
	}


	this.hill = new THREE.Mesh(hillGeom, greenMat);
	this.hill.position.z = 0;
	this.hill.position.y = 0;
	this.hill.position.x = 0;

	this.hills = new THREE.Mesh(hillsGeom, greenMat);
	this.hills.position.z = 50;
	this.hills.position.y = 50;
	this.hills.position.x = -200;

	
	this.hillgroup.add(this.hill);
	this.hillgroup.add(this.hills);
	

	this.hillgroup.position.z = -600;
	this.hillgroup.position.y = -450;
	this.hillgroup.position.x = (400 * foregrounds) -400;

	SCENE.add(this.hillgroup);

	shills.push(this.hillgroup);
}

CAMERA.position.z = 200;

var requestframe = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame ||
    // IE Fallback, you can even fallback to onscroll
    function (callback) {
	    window.setTimeout(callback, 1000 / 60);
    };

function loop() {
	setTimeout(function(){
		render();
		requestframe(loop);
	}, 13);
}

var count = 0;

$(document).mousemove(function(event){
	// calculate mouse position in normalized device coordinates
	// (-1 to +1) for both components

	mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
	mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;	

	mouse.fx = -mouse.y / 6;
	mouse.fy = (mouse.x / 6) + 0.3;

	//monkeys['monkey'].rotation.y = + ((mouse.x / 6) + 0.3);
	//monkeys['monkey'].rotation.x = + (-mouse.y / 6);
});



$(document).on("click tap", function(){
	if(isdone == false){
		if(started == true){
			if(monkeys['gravity'] == -gravity){
				monkeys['gravity'] = gravity;
			} else if(monkeys['gravity'] == gravity) {
				monkeys['gravity'] = -gravity;
			}
		}

		started = true;
		$('#overlay').addClass('hidden');
	}
});

var tailxdir = 0;
var tailydir = 0;

var Player;

function render() {
	var moveleftfar = 2.5 + (mouse.x / 2),
	    moveleftfarclose = 0.3 + mouse.x,
	    moveleftclose = 3.5 + (mouse.x / 2);

	count++;

	monkeys['hitbox'].position.y = monkeys['monkey'].position.y;

	if(started == true){
		
		Player = monkeys['hitbox'];
		
		

		if (monkeys['gravity'] == gravity) {
			if (monkeys['monkey'].rotation.x < 3.5 + (-mouse.y / 6)) {
				monkeys['monkey'].rotation.x += 0.2 + (-mouse.y / 6)
			}
			if (monkeys['monkey'].rotation.x > 3.5 + (-mouse.y / 6)) {
				monkeys['monkey'].rotation.x = 3.5 + (-mouse.y / 6)
			}
			if (monkeys['monkey'].rotation.y < 3 - ((mouse.x / 6) + 0.2)) {
				monkeys['monkey'].rotation.y += 0.2 
			}
			if (monkeys['monkey'].rotation.y > 3 - ((mouse.x / 6) + 0.2)) {
				monkeys['monkey'].rotation.y = 3 - ((mouse.x / 6) + 0.2)
			}
			if (monkeys['brightface'].position.x >= -2) {
				monkeys['brightface'].position.x -= 0.1
			}
			if (monkeys['head'].position.x >= -1) {
				monkeys['head'].position.x -= 0.1
			}
			if (monkeys['armR'].position.x >= 3) {
				monkeys['armR'].position.x -= 0.1
			}
			if (monkeys['armL'].position.x >= -4) {
				monkeys['armL'].position.x -= 0.1
			}
			if (monkeys['eyeL'].position.x >= 0) {
				monkeys['eyeL'].position.x -= 0.1
			}
			if (monkeys['eyeR'].position.x >= -3) {
				monkeys['eyeR'].position.x -= 0.1
			}
		} else if (monkeys['gravity'] == -gravity) {
			if (monkeys['monkey'].rotation.x > -0.4 + (-mouse.y / 6)) {
				monkeys['monkey'].rotation.x -= 0.2 + (-mouse.y / 6)
			}
			if (monkeys['monkey'].rotation.x < -0.4 + (-mouse.y / 6)) {
				monkeys['monkey'].rotation.x = -0.4 + (-mouse.y / 6)
			}
			if (monkeys['monkey'].rotation.y > 0 + (-mouse.y / 6)) {
				monkeys['monkey'].rotation.y -= 0.2 + ((mouse.x / 6) + 0.2)
			}
			if (monkeys['monkey'].rotation.y < 0 + ((mouse.x / 6) + 0.2)) {
				monkeys['monkey'].rotation.y = 0.2 + ((mouse.x / 6) + 0.2)
			}
			if (monkeys['brightface'].position.x <= 0) {
				monkeys['brightface'].position.x += 0.2
			}
			if (monkeys['head'].position.x <= 2) {
				monkeys['head'].position.x += 0.1
			}
			if (monkeys['armR'].position.x < 6) {
				monkeys['armR'].position.x += 0.1
			}
			if (monkeys['armL'].position.x <= -2) {
				monkeys['armL'].position.x += 0.1
			}
			if (monkeys['eyeL'].position.x <= 3) {
				monkeys['eyeL'].position.x += 0.1
			}
			if (monkeys['eyeR'].position.x <= 0) {
				monkeys['eyeR'].position.x += 0.1
			}
		}

		monkeys['monkey'].position.y += monkeys['vy'];

		// MAKE FLOOR
		if(monkeys['monkey'].position.y <= -floorlvl){
			monkeys['vy'] = monkeys['vy']*-0.2;
			monkeys['monkey'].position.y = -floorlvl;
		}
		if(monkeys['monkey'].position.y >= floorlvl){
			monkeys['vy'] = monkeys['vy']*-0.2;
			monkeys['monkey'].position.y = floorlvl;
		}



		if((count % 100) == 1) {
			foregrounds++;
			new foreground();
		}
		
		if((count % 100) == 1) {
			new obsticle();
		}


		for (var i = 0; i < shills.length; i++) { 
			if(isdone == false){
				shills[i].position.x -= moveleftfar;
			}
		}
		
		for (var o = 0; o < obsticles.length; o++) { 
			if(obsticles[o][1].position.y > obsticles[o][2]){
				obsticles[o][1].position.y -= 4;
			} else {
				obsticles[o][1].position.y = obsticles[o][2];
			}
			if(obsticles[o][3].position.y < obsticles[o][4]){
				obsticles[o][3].position.y += 4;
			} else {
				obsticles[o][3].position.y = obsticles[o][4];
			}
			if(isdone == false){
				obsticles[o][0].position.x -= moveleftclose;
			}
			//obsticles.push([this.obsticle, this.obsticletop, this.topy, this.obsticlebottom, this.bottomy]);
			if(monkeys['monkey'].position.x + 18 >= obsticles[o][0].position.x && monkeys['monkey'].position.x + 18 <= obsticles[o][0].position.x + 20 && monkeys['monkey'].position.y - 50 >= obsticles[o][4] && monkeys['monkey'].position.y + 50 <= obsticles[o][2]){
				if(isdone == false){
					addPoint();
				}
			} else if(monkeys['monkey'].position.x + 18 >= obsticles[o][0].position.x && monkeys['monkey'].position.x + 18 <= obsticles[o][0].position.x + 20) {
				if(isdone == false){
					if(monkeys['gravity'] == -gravity){
					} else if(monkeys['gravity'] == gravity) {
						monkeys['gravity'] = -gravity;
					}
				}
				isdone = true;
				$('.restart').removeClass('hidden');
			}
		}
		
		
		
		monkeys['vy'] += monkeys['gravity'];

	}

	if((count % 300) == 1) {
		monkeys['eyeL'].scale.y = .2;
		monkeys['eyeL'].position.y = -1.5;
		monkeys['eyeR'].scale.y = .2;
		monkeys['eyeR'].position.y = -1.5;

		setTimeout(function(){
			monkeys['eyeL'].scale.y = 1;
			monkeys['eyeL'].position.y = -1;
			monkeys['eyeR'].scale.y = 1;
			monkeys['eyeR'].position.y = -1;
		}, 200);
	}
	if((count % 200) == 1) {
		monkeys['tailcurl'].scale.y = .5;
		monkeys['tailcurl'].position.y = 6;

		setTimeout(function(){
			monkeys['tailcurl'].scale.y = 1;
			monkeys['tailcurl'].position.y = 5.5;
		}, 200);
	}


	if(monkeys['tail'].rotation.x >= -0.4) {
		if(tailxdir == 1){
			monkeys['tail'].rotation.x -= 0.01;
		}
	} else { tailxdir = 0; }
	if(monkeys['tail'].rotation.x <= 0.6) {
		if(tailxdir == 0){
			monkeys['tail'].rotation.x += 0.01;
		}
	} else { tailxdir = 1; }
	if(monkeys['tail'].rotation.y >= -0.3) {
		if(tailydir == 1){
			monkeys['tail'].rotation.y -= 0.01;
		}
	} else { tailydir = 0; }
	if(monkeys['tail'].rotation.y <= 0.5) {
		if(tailydir == 0){
			monkeys['tail'].rotation.y += 0.01;
		}
	} else { tailydir = 1; }

	RENDERER.render(SCENE, CAMERA);
}

function threeStart() {
	initLight();
	new monkey();
	new road();
	for (var i = 0; i < 5; i++) { 
		foregrounds++;
		new foreground();
	}
	new foreground();
	loop();
}

threeStart();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console