hextris/js/wavegen.js

178 lines
4.5 KiB
JavaScript
Raw Normal View History

function blockDestroyed() {
2014-06-01 01:56:52 +00:00
if (waveone.nextGen > 1000) {
2014-06-01 01:54:23 +00:00
waveone.nextGen -= 5;
} else {
2014-06-01 01:56:52 +00:00
waveone.nextGen = 1000;
}
if (waveone.difficulty < 15) {
2014-06-01 01:54:23 +00:00
waveone.difficulty += 0.04;
} else {
waveone.difficulty = 15;
}
}
2014-05-24 00:22:53 +00:00
function waveGen(clock) {
this.lastGen = 0;
this.last = 0;
this.nextGen = 1300; // - 1500; //delay before starting
this.start = 0;
2014-05-22 19:29:35 +00:00
this.colors = colors;
this.ct = 0;
2014-05-22 19:29:35 +00:00
this.clock = clock;
2014-05-24 00:22:53 +00:00
this.difficulty = 0;
2014-05-24 02:41:55 +00:00
this.integerDifficulty = this.difficulty;
this.dt = 0;
2014-05-22 19:29:35 +00:00
this.update = function() {
this.currentFunction();
this.dt += 16.6666667 * spaceModifier;
this.computeDifficulty();
if (this.dt - this.lastGen * (1/settings.creationSpeedModifier) > this.nextGen) {
2014-06-01 01:56:52 +00:00
if (this.nextGen > 1000) {
2014-06-01 02:00:25 +00:00
this.nextGen -= (.4 * (this.nextGen/1300)) * settings.creationSpeedModifier;
}
}
2014-05-24 23:50:57 +00:00
};
this.randomGeneration = function() {
if (this.dt - this.lastGen > this.nextGen) {
2014-05-24 02:41:55 +00:00
this.ct++;
this.lastGen = this.dt;
2014-05-24 02:46:01 +00:00
var fv = randInt(0, MainClock.sides);
addNewBlock(fv, colors[randInt(0, colors.length)], 1.3 + (this.integerDifficulty/15) * 3);
if (this.ct > 7) {
2014-05-24 18:15:07 +00:00
var nextPattern = randInt(0, 20 + 4);
if (nextPattern > 4 + 17) {
this.ct = 0;
this.currentFunction = this.doubleGeneration;
} else if (nextPattern > 4 + 14) {
this.ct = 0;
this.currentFunction = this.crosswiseGeneration;
} else if (nextPattern > 4 + 11) {
this.ct = 0;
this.currentFunction = this.spiralGeneration;
}
else if (nextPattern > 4 + 8) {
2014-05-24 02:41:55 +00:00
this.ct = 0;
this.currentFunction = this.circleGeneration;
2014-05-24 18:15:07 +00:00
}
2014-05-22 19:29:35 +00:00
}
2014-05-24 00:22:53 +00:00
2014-05-22 19:29:35 +00:00
}
2014-05-24 00:22:53 +00:00
};
2014-05-24 02:41:55 +00:00
this.computeDifficulty = function() {
if (this.difficulty < 15) {
2014-05-24 02:41:55 +00:00
if (this.difficulty < 8) {
2014-06-01 01:54:23 +00:00
this.difficulty += (this.dt - this.last)/(2000000);
2014-05-24 02:41:55 +00:00
}
else {
2014-06-01 01:54:23 +00:00
this.difficulty += (this.dt - this.last)/(40000000);
2014-05-24 02:41:55 +00:00
}
}
this.integerDifficulty = Math.floor(this.difficulty);
};
this.circleGeneration = function() {
if (this.dt - this.lastGen > this.nextGen + 500) {
2014-05-24 17:56:41 +00:00
var numColors = randInt(1, 4);
2014-05-24 02:41:55 +00:00
if (numColors == 3) {
2014-05-24 17:56:41 +00:00
numColors = randInt(1, 4);
2014-05-24 02:41:55 +00:00
}
var colorList = [];
nextLoop:
for (var i = 0; i < numColors; i++) {
var q = randInt(0, colors.length);
for (var j in colorList) {
if (colorList[j] == colors[q]) {
i--;
continue nextLoop;
}
}
colorList.push(colors[q]);
}
2014-05-24 02:46:01 +00:00
for (var i = 0; i < MainClock.sides; i++) {
addNewBlock(i, colorList[i % numColors], 1.5 + (this.integerDifficulty/15) * 3);
2014-05-24 02:41:55 +00:00
}
2014-05-24 02:41:55 +00:00
this.ct += 15;
this.lastGen = this.dt;
this.shouldChangePattern(1);
2014-05-24 02:41:55 +00:00
}
};
this.crosswiseGeneration = function() {
2014-05-24 23:50:57 +00:00
if (this.dt - this.lastGen > this.nextGen) {
2014-05-24 02:41:55 +00:00
var ri = randInt(0, colors.length);
var i = randInt(0, colors.length);
addNewBlock(i, colors[ri], 0.6 + (this.integerDifficulty/15) * 3);
2014-05-24 02:46:01 +00:00
addNewBlock((i + 3) % MainClock.sides, colors[ri], 0.6 + (this.integerDifficulty/15) * 3);
2014-05-24 02:41:55 +00:00
this.ct += 1.5;
this.lastGen = this.dt;
this.shouldChangePattern();
2014-05-24 02:41:55 +00:00
}
};
this.spiralGeneration = function() {
var dir = randInt(0, 2);
if (this.dt - this.lastGen > this.nextGen * (5/9)) {
if (dir) {
addNewBlock(5 - (this.ct % MainClock.sides), colors[randInt(0, colors.length)], 1.5 + (this.integerDifficulty/15) * (3/2));
}
else {
addNewBlock(this.ct % MainClock.sides, colors[randInt(0, colors.length)], 1.5 + (this.integerDifficulty/15) * (3/2));
}
2014-05-24 02:41:55 +00:00
this.ct += 1;
this.lastGen = this.dt;
this.shouldChangePattern();
2014-05-24 02:41:55 +00:00
}
};
this.doubleGeneration = function() {
if (this.dt - this.lastGen > this.nextGen) {
2014-05-24 02:41:55 +00:00
var i = randInt(0, colors.length);
addNewBlock(i, colors[randInt(0, colors.length)], 1.5 + (this.integerDifficulty/15) * 3);
addNewBlock((i + 1) % MainClock.sides, colors[randInt(0, colors.length)], 1.5 + (this.integerDifficulty/15) * 3);
2014-05-24 02:41:55 +00:00
this.ct += 2;
this.lastGen = this.dt;
this.shouldChangePattern();
2014-05-24 02:41:55 +00:00
}
};
this.setRandom = function() {
this.ct = 0;
this.currentFunction = this.randomGeneration;
};
this.shouldChangePattern = function(x) {
if (x) {
var q = randInt(0, 4);
this.ct = 0;
switch (q) {
case 0:
this.currentFunction = this.doubleGeneration;
break;
case 1:
this.currentFunction = this.spiralGeneration;
break;
case 2:
this.currentFunction = this.crosswiseGeneration;
break;
}
}
else if (this.ct > 8) {
2014-05-24 02:41:55 +00:00
if (randInt(0, 2) === 0) {
this.setRandom();
return 1;
}
}
return 0;
};
2014-05-24 00:22:53 +00:00
// rest of generation functions
this.currentFunction = this.randomGeneration;
}