flowers growing

This commit is contained in:
ericrius1 2016-03-04 17:55:45 -08:00
parent 3ad2d1aa9b
commit 65c8f7cc45
2 changed files with 21 additions and 11 deletions

View file

@ -20,11 +20,14 @@
_this.flowers = []; _this.flowers = [];
// _this.STARTING_FLOWER_DIMENSIONS = {x: 0.1, y: 0.001, z: 0.1} // _this.STARTING_FLOWER_DIMENSIONS = {x: 0.1, y: 0.001, z: 0.1}
_this.STARTING_FLOWER_DIMENSIONS = { _this.STARTING_FLOWER_DIMENSIONS = {
x: 0.1, x: 0.001,
y: 0.01, y: 0.001,
z: 0.1 z: 0.001
} }
_this.debounceRange = {min: 500, max: 1000};
_this.canCreateFlower = true;
}; };
GrowingPlant.prototype = { GrowingPlant.prototype = {
@ -34,9 +37,14 @@
// we're being watered- every now and then spawn a new flower to add to our growing list // we're being watered- every now and then spawn a new flower to add to our growing list
// If we don't have any flowers yet, immediately grow one // If we don't have any flowers yet, immediately grow one
var data = JSON.parse(data[0]); var data = JSON.parse(data[0]);
if (_this.flowers.length < 1000) {
_this.createFlower(data.position, data.surfaceNormal); if(_this.canCreateFlower) {
_this.createFlower(data.position, data.surfaceNormal);
_this.canCreateFlower = false;
Script.setTimeout(function() {
_this.canCreateFlower = true;
}, randFloat(_this.debounceRange.min, this.debounceRange.max));
} }
_this.flowers.forEach(function(flower) { _this.flowers.forEach(function(flower) {
@ -44,6 +52,7 @@
}); });
}, },
createFlower: function(position, surfaceNormal) { createFlower: function(position, surfaceNormal) {
@ -64,7 +73,7 @@
startingPosition: position, startingPosition: position,
rotation: flowerRotation, rotation: flowerRotation,
maxYDimension: randFloat(0.2, 1.5), maxYDimension: randFloat(0.2, 1.5),
growthRate: randFloat(0.0001, 0.001) growthRate: {x: 0.0002, y: 0.001, z: 0.0002}
}; };
print(_this.STARTING_FLOWER_DIMENSIONS.y) print(_this.STARTING_FLOWER_DIMENSIONS.y)
flower.grow = function() { flower.grow = function() {
@ -72,7 +81,7 @@
if (flower.dimensions.y > flower.maxYDimension) { if (flower.dimensions.y > flower.maxYDimension) {
return; return;
} }
flower.dimensions.y += flower.growthRate; flower.dimensions = Vec3.sum(flower.dimensions, flower.growthRate);
flower.position = Vec3.sum(flower.startingPosition, Vec3.multiply(Quat.getUp(flower.rotation), flower.dimensions.y / 2)); flower.position = Vec3.sum(flower.startingPosition, Vec3.multiply(Quat.getUp(flower.rotation), flower.dimensions.y / 2));
//As we grow we must also move ourselves in direction we grow! //As we grow we must also move ourselves in direction we grow!
Entities.editEntity(flower.id, { Entities.editEntity(flower.id, {

View file

@ -64,7 +64,7 @@
castRay: function() { castRay: function() {
var spoutProps = Entities.getEntityProperties(_this.waterSpout, ["position, rotation"]); var spoutProps = Entities.getEntityProperties(_this.waterSpout, ["position, rotation"]);
var direction = Quat.getFront(spoutProps.rotation) var direction = Quat.getFront(spoutProps.rotation)
var end = Vec3.sum(spoutProps.position, Vec3.multiply(10, direction)); var end = Vec3.sum(spoutProps.position, Vec3.multiply(5, direction));
Overlays.editOverlay(_this.rayCastLine, { Overlays.editOverlay(_this.rayCastLine, {
start: spoutProps.position, start: spoutProps.position,
end: end end: end
@ -131,9 +131,10 @@
z: 0.01 z: 0.01
}, },
emitOrientation: Quat.fromPitchYawRollDegrees(0, 180, 0), emitOrientation: Quat.fromPitchYawRollDegrees(0, 180, 0),
particleRadius: 0.04, particleRadius: 0.01,
radiusSpread: 0.01, radiusSpread: 0.001,
radiusStart: 0.03, radiusStart: 0.01,
radiusFinish: 0.01,
alpha: 0.9, alpha: 0.9,
alphaSpread: .1, alphaSpread: .1,
alphaStart: 0.7, alphaStart: 0.7,