Skip to content

Commit

Permalink
Add volcano to oasis at doom start
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksanb committed Jul 11, 2014
1 parent 5f69e12 commit 87ca779
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
3 changes: 3 additions & 0 deletions res/layers.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[
{
"type": "DesertLayer",
"dependencies": [
"VolcanoFactory"
],
"displayName": "Desert",
"startFrame": 480,
"endFrame": 6728,
Expand Down
17 changes: 17 additions & 0 deletions src/DesertLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ function DesertLayer(layer) {
this.camera = this.cameraController.camera;
this.scene.add(this.camera);

var volcanoFactory = new VolcanoFactory( this.scene );
this.volcano = volcanoFactory.create(
new THREE.Vector3( 920.5, -5,-272.03 ),
28, // Base scale
100, // Max lava ball size
120, // Number of lava balls
false // Party mode
);

this.waterHexes = [];

this.waterPond = new THREE.Object3D();
Expand Down Expand Up @@ -144,6 +153,14 @@ DesertLayer.prototype.render = function(renderer, interpolation) {
DesertLayer.prototype.update = function(frame, relativeFrame) {
this.cameraController.updateCamera(relativeFrame);

if (frame < 4400) {
this.scene.remove(this.volcano);
} else if (frame > 4400) {
this.scene.add(this.volcano);
this.volcano.update( frame - 4600 );
this.volcano.position.y = clamp(-10, -10 + (frame - 4400) / 27, 20);
}

for (var i = 0; i < this.waterHexes.length; i++) {
var hex = this.waterHexes[i];

Expand Down
48 changes: 31 additions & 17 deletions src/VolcanoFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function VolcanoFactory( scene ) {
Loader.loadTexture( 'res/explosion.png' );

return {
create: function create( position, baseRadius, nlavaBalls, skittles ) {
create: function create( position, baseScale, maxLavaBallSize, nlavaBalls, skittles ) {
var lavaBallMaterial = new THREE.ShaderMaterial( SHADERS.volcano );
var volcano = new THREE.Object3D();
volcano.position = position.clone();
Expand All @@ -27,22 +27,37 @@ function VolcanoFactory( scene ) {

var lavaBalls = [];
for (var i = 0; i < nlavaBalls; i++) {
var lavaBall = lavaBallFactory.create( 8, 10 );
var lavaBall = lavaBallFactory.create( 10, maxLavaBallSize, 7 );
lavaBalls.push( lavaBall );
}

var lavaFloor = lavaBallFactory.create( baseRadius, 20 );
lavaFloor.scale.y = 0.1;
var lavaFloor = lavaBallFactory.create( 100, 50, 20 );
lavaFloor.scale.x = baseScale;
lavaFloor.scale.z = baseScale;
lavaFloor.scale.y = 0.2;

volcano.add( lavaFloor );
scene.add( volcano );

volcano.update = function update( relativeFrame ) {
lavaBallMaterial.uniforms[ 'time' ].value = relativeFrame / 200;

for ( var i = 0; i < lavaBalls.length; i++ ) {
lavaBalls[ i ].update( relativeFrame );
};
};

volcano.show = function show( visible ) {
if (visible) {
scene.add(volcano);
for (var i = 0; i < nlavaBalls; i++) {
scene.add(lavaBalls[i]);
}
} else {
scene.remove(volcano);
for (var i = 0; i < nlavaBalls; i++) {
scene.remove(lavaBalls[i]);
}
}
}

return volcano;
Expand All @@ -52,8 +67,8 @@ function VolcanoFactory( scene ) {

function LavaBallFactory( scene, material, skittles ) {
return {
create: function create( scale, detail ) {
var mappedSize = clamp(5, scale / Math.random(), 50);
create: function create( scale, maxSize, detail ) {
var mappedSize = clamp(5, scale / Math.random(), maxSize);
var lavaBallGeometry = new THREE.SphereGeometry( mappedSize, detail, detail );
var lavaBall = new THREE.Mesh(
lavaBallGeometry,
Expand All @@ -65,23 +80,22 @@ function LavaBallFactory( scene, material, skittles ) {
lavaBall.period = 60 * 7 ;
lavaBall.generateDirection = function generateDirection() {
this.direction = new THREE.Vector3(
-6 + 12 * Math.random(),
25 + 15 * Math.random(),
-6 + 12 * Math.random() );
(-scale / 2 + scale * Math.random()) * 2,
8 * scale * Math.random(),
(-scale / 2 + scale * Math.random()) * 2 );
};

lavaBall.generateDirection();

lavaBall.update = function update( relativeFrame ) {
var internalFrame = relativeFrame % this.period;

if ( internalFrame < this.internalOffset ) {
this.inScene == false;
if (relativeFrame < 0) {
this.position = new THREE.Vector3(0, 0, 0);
scene.remove(this);
return;
} else if ( this.inScene == null ) {
scene.add( this );
this.inScene == true;
}
scene.add(this);

var internalFrame = relativeFrame % this.period;

this.position = this.direction.clone()
.multiplyScalar( internalFrame - this.internalOffset )
Expand Down

0 comments on commit 87ca779

Please sign in to comment.