hextris/js/wavegen.js

200 lines
4.9 KiB
JavaScript
Raw Normal View History

function blockDestroyed() {
2014-06-01 01:56:52 +00:00
if (waveone.nextGen > 1000) {
waveone.nextGen -= 7 * settings.creationSpeedModifier;
} 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
2014-07-04 16:47:37 +00:00
function waveGen(hex) {
this.lastGen = 0;
this.last = 0;
this.nextGen = 3000;
this.start = 0;
2014-05-22 19:29:35 +00:00
this.colors = colors;
this.ct = 0;
2014-07-04 16:47:37 +00:00
this.hex = hex;
this.difficulty = 1;
this.dt = 0;
2014-05-22 19:29:35 +00:00
this.update = function() {
this.currentFunction();
2014-06-29 18:35:10 +00:00
this.dt += 16.6666667;
this.computeDifficulty();
2014-07-26 14:54:41 +00:00
if ((this.dt - this.lastGen)*settings.creationSpeedModifier > this.nextGen) {
if (this.nextGen > 1000) {
this.nextGen -= 4.5 * ((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-07-04 16:42:44 +00:00
var fv = randInt(0, MainHex.sides);
addNewBlock(fv, colors[randInt(0, colors.length)], 1.6 + (this.difficulty/15) * 3);
if (this.ct > 7) {
2014-07-26 14:42:10 +00:00
var nextPattern = randInt(0, 20 + 8);
if (nextPattern > 8 + 17) {
this.ct = 0;
this.currentFunction = this.doubleGeneration;
} else if (nextPattern > 8 + 14) {
this.ct = 0;
this.currentFunction = this.crosswiseGeneration;
} else if (nextPattern > 8 + 11) {
this.ct = 0;
this.currentFunction = this.spiralGeneration;
} else if (nextPattern > 8 + 8) {
this.ct = 0;
this.currentFunction = this.circleGeneration;
} else if (nextPattern > 8 + 5) {
this.ct = 0;
this.currentFunction = this.halfCircleGeneration;
this.ct = 0
2014-07-26 14:42:10 +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.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-07-04 16:42:44 +00:00
for (var i = 0; i < MainHex.sides; i++) {
addNewBlock(i, colorList[i % numColors], 1.5 + (this.difficulty/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.halfCircleGeneration = function() {
if (this.dt - this.lastGen > (this.nextGen+500)/2) {
var numColors = randInt(1, 3);
var c = colors[randInt(0, colors.length)];
var colorList = [c, c, c];
if (numColors == 2) {
colorList = [c, colors[randInt(0, colors.length)],c];
}
var d = randInt(0,6);
for (var i = 0; i < 3; i++) {
addNewBlock((d+i) % 6, colorList[i], 1.5 + (this.difficulty/15) * 3);
}
this.ct += 5;
this.lastGen = this.dt;
this.shouldChangePattern();
}
};
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.difficulty/15) * 3);
2014-07-04 16:42:44 +00:00
addNewBlock((i + 3) % MainHex.sides, colors[ri], 0.6 + (this.difficulty/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) {
2014-07-04 16:42:44 +00:00
addNewBlock(5 - (this.ct % MainHex.sides), colors[randInt(0, colors.length)], 1.5 + (this.difficulty/15) * (3/2));
}
else {
2014-07-04 16:42:44 +00:00
addNewBlock(this.ct % MainHex.sides, colors[randInt(0, colors.length)], 1.5 + (this.difficulty/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.difficulty/15) * 3);
2014-07-04 16:42:44 +00:00
addNewBlock((i + 1) % MainHex.sides, colors[randInt(0, colors.length)], 1.5 + (this.difficulty/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;
2014-07-26 23:58:58 +00:00
}