-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
131 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//= require Unit | ||
|
||
GLOBE.FactoryUnit = function() { | ||
GLOBE.Unit.call(this, 'Factory', 10); | ||
|
||
this.building = null; | ||
|
||
this.joins = []; | ||
|
||
this.addToScene = function(scene) { | ||
var geometry = new THREE.CubeGeometry(50, 50, 50, 1, 1, 1); | ||
material = new THREE.MeshLambertMaterial( { color: 0x999999 } ); | ||
this.building = new THREE.Mesh( geometry, material ); | ||
|
||
this.building.position = this.node.normal.clone().multiplyScalar(20); | ||
this.building.position.addSelf(this.node.position); | ||
|
||
this.building.lookAt(this.building.position.clone().addSelf(this.node.normal)); | ||
|
||
scene.add(this.building); | ||
}; | ||
|
||
this.removeFromScene = function(scene) { | ||
scene.removeFromScene(building); | ||
delete this.building; | ||
this.building=null; | ||
for(i=0; i<this.joins.length; i++) { | ||
scene.removeFromScene(this.joins[i]); | ||
delete this.joins[i]; | ||
} | ||
this.joins = []; | ||
} | ||
|
||
this.addNeighbour = function(neighbour, scene) { | ||
if(neighbour.unit!=null && neighbour.unit.constructor == GLOBE.FactoryUnit) { | ||
var midpoint = this.node.position.clone().addSelf(neighbour.position).multiplyScalar(0.5); | ||
var avgnormal = this.node.normal.clone().addSelf(neighbour.normal); | ||
var offset = avgnormal.multiplyScalar(40).addSelf(midpoint); | ||
var joinCurve = new THREE.QuadraticBezierCurve3(this.node.position, offset, neighbour.position) | ||
var joinGeom = new THREE.Geometry(); | ||
joinGeom.vertices = joinCurve.getSpacedPoints(8).map(function(value) { return new THREE.Vertex(value); }); | ||
var joinMaterial = new THREE.LineBasicMaterial( { color: 0x00ff00 }); | ||
var join = new THREE.Line( joinGeom, joinMaterial, THREE.LineStrip); | ||
|
||
this.joins.push(join); | ||
scene.add(join); | ||
} | ||
}; | ||
}; | ||
|
||
GLOBE.Unit.prototype.clone = function() { | ||
return new GLOBE.FactoryUnit(); | ||
}; | ||
|
||
GLOBE.FactoryUnit.prototype = new GLOBE.Unit(); | ||
GLOBE.FactoryUnit.prototype.constructor = GLOBE.FactoryUnit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,57 @@ | ||
//= require Globe | ||
//= require FactoryUnit | ||
|
||
GLOBE.Gameplay = function(network, scene) { | ||
this.scene=scene; | ||
this.network=network; | ||
|
||
this.reset(); | ||
this.units = { factory: new GLOBE.FactoryUnit() }; | ||
|
||
//amount of manufactured goods required to build various things | ||
this.FactoryCost = 10; | ||
this.SpaceCost = 1000; | ||
|
||
this.reset(); | ||
}; | ||
|
||
GLOBE.Gameplay.prototype.constructor = GLOBE.Gameplay; | ||
|
||
GLOBE.Gameplay.prototype.reset = function() { | ||
this.pollution=0; //planetary pollution | ||
this.capacity=0; //rate of manufacture | ||
this.manufactured_goods=this.FactoryCost; //current stock of manufactured goods | ||
this.state = { | ||
pollution: 0, //planetary pollution | ||
//current stock of manufactured goods | ||
manufactured_goods: Math.round(1.5*this.units.factory.cost) | ||
}; | ||
|
||
for(i=0; i<this.network.length; i++) { | ||
var node = this.network[i]; | ||
if("building" in node && node.building!=null) { | ||
this.scene.removeObject(node.building); | ||
delete node.building; | ||
} | ||
if("joins" in node) { | ||
for(i=0; i<joins.length; i++) { | ||
this.scene.removeObject(node.joins[i]); | ||
delete node.joins[i]; | ||
} | ||
if("unit" in node && node.unit!=null) { | ||
node.unit.erase(this.scene) | ||
delete node.unit; | ||
} | ||
|
||
this.network[i].building=null; | ||
this.network[i].joins = []; | ||
node.unit=null; | ||
} | ||
} | ||
|
||
GLOBE.Gameplay.prototype.handlePlacement = function(placement) { | ||
var node = this.network[placement]; | ||
|
||
if(node.building!=null) return; | ||
|
||
var geometry = new THREE.CubeGeometry(50, 50, 50, 1, 1, 1); | ||
material = new THREE.MeshLambertMaterial( { color: 0x999999 } ); | ||
building = new THREE.Mesh( geometry, material ); | ||
|
||
building.position = node.normal.clone().multiplyScalar(20); | ||
building.position.addSelf(node.position); | ||
|
||
building.lookAt(building.position.clone().addSelf(network[placement].normal)); | ||
|
||
this.scene.add(building); | ||
|
||
node.building = building; | ||
if(this.units.factory.clone().place(node, this.state, this.scene) == false) return; | ||
|
||
for(i=0; i<node.neighbours.length; i++) { | ||
var neighbour = this.network[node.neighbours[i]]; | ||
if(neighbour.building != null) { | ||
var midpoint = node.position.clone().addSelf(neighbour.position).multiplyScalar(0.5); | ||
var avgnormal = node.normal.clone().addSelf(neighbour.normal); | ||
var offset = avgnormal.multiplyScalar(40).addSelf(midpoint); | ||
var joinCurve = new THREE.QuadraticBezierCurve3(node.position, offset, neighbour.position) | ||
var joinGeom = new THREE.Geometry(); | ||
joinGeom.vertices = joinCurve.getSpacedPoints(8).map(function(value) { return new THREE.Vertex(value); }); | ||
var joinMaterial = new THREE.LineBasicMaterial( { color: 0x00ff00 }); | ||
var join = new THREE.Line( joinGeom, joinMaterial, THREE.LineStrip); | ||
|
||
node.joins.push(join); | ||
this.scene.add(join); | ||
if(neighbour.unit!=null) { | ||
node.unit.addNeighbour(neighbour, this.scene); | ||
//neighbour.addNeighbour(node.unit); | ||
} | ||
} | ||
}; | ||
|
||
GLOBE.Gameplay.prototype.update = function() { | ||
this.network | ||
for(i=0; i<this.network.length; i++) { | ||
var node = this.network[i]; | ||
if(node.unit == null) continue; | ||
node.unit.update(this.state, this.scene); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
GLOBE.Unit = function(name, cost, production, pollution) { | ||
this.name = name; | ||
this.cost = cost; | ||
this.production = production || cost; | ||
this.pollution = pollution || this.production; | ||
this.node = null; | ||
}; | ||
|
||
GLOBE.Unit.prototype.addToScene = function(scene) {}; | ||
|
||
GLOBE.Unit.prototype.removeFromScene = function(scene) {}; | ||
|
||
GLOBE.Unit.prototype.addNeighbour = function(neighbour, scene) {}; | ||
|
||
GLOBE.Unit.prototype.place = function(node, state, scene) { | ||
if(node.unit != null) return false; | ||
//if(state.manufactured_goods < this.cost) return false; | ||
|
||
this.node=node; | ||
node.unit=this; | ||
this.addToScene(scene); | ||
|
||
state.manufactured_goods -= this.cost; | ||
|
||
return true; | ||
}; | ||
|
||
GLOBE.Unit.prototype.remove = function(state, scene) { | ||
this.erase(scene); | ||
} | ||
|
||
GLOBE.Unit.prototype.erase = function(scene) { | ||
this.node=null; | ||
this.removeFromScene(scene); | ||
} | ||
|
||
GLOBE.Unit.prototype.update = function(state, scene) { | ||
state.manufactured_goods += this.production; | ||
state.pollution += this.pollution; | ||
}; | ||
|
||
GLOBE.Unit.prototype.clone = function() {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ation-874544aa383eeeeaf78a293246fb890e.js → ...ation-49ed8df66b3e558853c30972f29d94d1.js
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file renamed
BIN
+127 KB
...on-874544aa383eeeeaf78a293246fb890e.js.gz → ...on-49ed8df66b3e558853c30972f29d94d1.js.gz
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
public/assets/application-5287cc5b85a2d6eb4763b02f3f90fa4c.css.gz
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
public/assets/blueprint/ie-ad5fb044a45a197277638f4cedcc9411.css.gz
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
public/assets/blueprint/print-8d01042d44acf14ae6a81d29833fa375.css.gz
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
public/assets/blueprint/screen-933ed51b81231421bc9f31745cfb33d5.css.gz
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters