Skip to content

Instantly share code, notes, and snippets.

@CharlotteGore
Created April 3, 2015 14:32
Show Gist options
  • Save CharlotteGore/59b303793983ac39ac5c to your computer and use it in GitHub Desktop.
Save CharlotteGore/59b303793983ac39ac5c to your computer and use it in GitHub Desktop.
Hexr Engine
// load the webgl world..
var world = require('./world')(document.getElementById('screen'));
// load the level data (universe.json) into the universe module..
var universe = require('./mapper.js')(require('./universe.json'));
// initialise a map..
var level = universe.initialiseLevel('1-1');
// add the parallax meshes to the scene...
each(level.getParallaxMeshes(), function (mesh){
// Hack! Ah ah! It'll save every one of us!
mesh.scale.set(2,2,2);
mesh.position.z = -50;
mesh.material.color = new THREE.Color(0x999999)
world.scene.add(mesh);
});
// add the normal meshes to the scene...
each(level.getTileMeshes(), function (mesh){
//mesh.material = new THREE.MeshBasicMaterial({ color : 0xffffff})
world.scene.add(mesh);
});
// create a game loop callback..
var fn = (function gameTick(worldTime){
// make the camera pan back and forth..
var progress = -8 + Math.abs(-1 + ((worldTime.now % 4 / 4) * 2)) * 16;
world.cameraman.setPosition({ x : progress, y : 0, z : 50}); world.cameraman.lookAt({ x : progress,y : 0, z : 50})
}).bind(world);
// register our game loop callback with the webgl world.
world.on('tick', fn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment