hextris/js/wavegen.js

62 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-05-24 00:22:53 +00:00
// In each generator function you need a few things
// Something defining when the next block is being generated
// Something defining which and when the next function is going to be passed
function waveGen(clock) {
2014-05-22 19:29:35 +00:00
this.lastGen = Date.now();
2014-05-24 00:22:53 +00:00
this.nextGen = 1500; // - 1500; //delay before starting
this.start = Date.now();
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-22 19:29:35 +00:00
this.update = function() {
2014-05-24 00:22:53 +00:00
if (this.difficulty < 15) {
if (this.difficulty < 8) {
this.difficulty = Math.floor((Date.now() - this.start)/5000); // every 5 seconds raise the difficulty
}
else {
this.difficulty = Math.floor((Date.now() - this.start)/10000 + 3);
}
2014-05-24 00:22:53 +00:00
}
2014-05-24 00:22:53 +00:00
this.currentFunction();
};
this.randomGeneration = function() {
2014-05-22 19:29:35 +00:00
var now = Date.now();
if (now - this.lastGen > this.nextGen) {
2014-05-24 00:22:53 +00:00
this.lastGen = now;
if (this.nextGen > 1000) {
if (this.difficulty < 8) {
this.nextGen -= 15 * ((this.nextGen)/1100);
}
else {
this.nextGen -= 5 * ((this.nextGen)/1100);
}
if (this.difficulty)
console.log(this.nextGen);
2014-05-22 19:29:35 +00:00
}
var fv = randInt(0, 6);
addNewBlock(fv, colors[randInt(0, colors.length)], 1.5 + (this.difficulty/15) * 3);
2014-05-24 00:22:53 +00:00
// var nextPattern = randInt(0, 6)
// if () {
// this.currentFunction = this.
// }
2014-05-22 19:29:35 +00:00
}
2014-05-24 00:22:53 +00:00
};
// rest of generation functions
this.currentFunction = this.randomGeneration;
}
function generatorFunction() {
2014-05-22 19:29:35 +00:00
}
2014-05-24 00:22:53 +00:00
// In each generator function you need a few things
// Something defining when the next block is being generated
// Something defining which and when the next function is going to be passed