Path: blob/main/public/games/files/hextris/js/wavegen.js
1036 views
function blockDestroyed() {1if (waveone.nextGen > 1350) {2waveone.nextGen -= 30 * settings.creationSpeedModifier;3} else if (waveone.nextGen > 600) {4waveone.nextGen -= 8 * settings.creationSpeedModifier;5} else {6waveone.nextGen = 600;7}89if (waveone.difficulty < 35) {10waveone.difficulty += 0.085 * settings.speedModifier;11} else {12waveone.difficulty = 35;13}14}1516function waveGen(hex) {17this.lastGen = 0;18this.last = 0;19this.nextGen = 2700;20this.start = 0;21this.colors = colors;22this.ct = 0;23this.hex = hex;24this.difficulty = 1;25this.dt = 0;26this.update = function() {27this.currentFunction();28this.dt = (settings.platform == 'mobile' ? 14 : 16.6667) * MainHex.ct;29this.computeDifficulty();30if ((this.dt - this.lastGen) * settings.creationSpeedModifier > this.nextGen) {31if (this.nextGen > 600) {32this.nextGen -= 11 * ((this.nextGen / 1300)) * settings.creationSpeedModifier;33}34}35};3637this.randomGeneration = function() {38if (this.dt - this.lastGen > this.nextGen) {39this.ct++;40this.lastGen = this.dt;41var fv = randInt(0, MainHex.sides);42addNewBlock(fv, colors[randInt(0, colors.length)], 1.6 + (this.difficulty / 15) * 3);43var lim = 5;44if (this.ct > lim) {45var nextPattern = randInt(0, 3 + 21);46if (nextPattern > 15) {47this.ct = 0;48this.currentFunction = this.doubleGeneration;49} else if (nextPattern > 10) {50this.ct = 0;51this.currentFunction = this.crosswiseGeneration;52} else if (nextPattern > 7) {53this.ct = 0;54this.currentFunction = this.spiralGeneration;55} else if (nextPattern > 4) {56this.ct = 0;57this.currentFunction = this.circleGeneration;58} else if (nextPattern > 1) {59this.ct = 0;60this.currentFunction = this.halfCircleGeneration;61}62}63}64};6566this.computeDifficulty = function() {67if (this.difficulty < 35) {68var increment;69if (this.difficulty < 8) {70increment = (this.dt - this.last) / (5166667) * settings.speedModifier;71} else if (this.difficulty < 15) {72increment = (this.dt - this.last) / (72333333) * settings.speedModifier;73} else {74increment = (this.dt - this.last) / (90000000) * settings.speedModifier;75}7677this.difficulty += increment * (1/2);78}79};8081this.circleGeneration = function() {82if (this.dt - this.lastGen > this.nextGen + 500) {83var numColors = randInt(1, 4);84if (numColors == 3) {85numColors = randInt(1, 4);86}8788var colorList = [];89nextLoop: for (var i = 0; i < numColors; i++) {90var q = randInt(0, colors.length);91for (var j in colorList) {92if (colorList[j] == colors[q]) {93i--;94continue nextLoop;95}96}97colorList.push(colors[q]);98}99100for (var i = 0; i < MainHex.sides; i++) {101addNewBlock(i, colorList[i % numColors], 1.5 + (this.difficulty / 15) * 3);102}103104this.ct += 15;105this.lastGen = this.dt;106this.shouldChangePattern(1);107}108};109110this.halfCircleGeneration = function() {111if (this.dt - this.lastGen > (this.nextGen + 500) / 2) {112var numColors = randInt(1, 3);113var c = colors[randInt(0, colors.length)];114var colorList = [c, c, c];115if (numColors == 2) {116colorList = [c, colors[randInt(0, colors.length)], c];117}118119var d = randInt(0, 6);120for (var i = 0; i < 3; i++) {121addNewBlock((d + i) % 6, colorList[i], 1.5 + (this.difficulty / 15) * 3);122}123124this.ct += 8;125this.lastGen = this.dt;126this.shouldChangePattern();127}128};129130this.crosswiseGeneration = function() {131if (this.dt - this.lastGen > this.nextGen) {132var ri = randInt(0, colors.length);133var i = randInt(0, colors.length);134addNewBlock(i, colors[ri], 0.6 + (this.difficulty / 15) * 3);135addNewBlock((i + 3) % MainHex.sides, colors[ri], 0.6 + (this.difficulty / 15) * 3);136this.ct += 1.5;137this.lastGen = this.dt;138this.shouldChangePattern();139}140};141142this.spiralGeneration = function() {143var dir = randInt(0, 2);144if (this.dt - this.lastGen > this.nextGen * (2 / 3)) {145if (dir) {146addNewBlock(5 - (this.ct % MainHex.sides), colors[randInt(0, colors.length)], 1.5 + (this.difficulty / 15) * (3 / 2));147} else {148addNewBlock(this.ct % MainHex.sides, colors[randInt(0, colors.length)], 1.5 + (this.difficulty / 15) * (3 / 2));149}150this.ct += 1;151this.lastGen = this.dt;152this.shouldChangePattern();153}154};155156this.doubleGeneration = function() {157if (this.dt - this.lastGen > this.nextGen) {158var i = randInt(0, colors.length);159addNewBlock(i, colors[randInt(0, colors.length)], 1.5 + (this.difficulty / 15) * 3);160addNewBlock((i + 1) % MainHex.sides, colors[randInt(0, colors.length)], 1.5 + (this.difficulty / 15) * 3);161this.ct += 2;162this.lastGen = this.dt;163this.shouldChangePattern();164}165};166167this.setRandom = function() {168this.ct = 0;169this.currentFunction = this.randomGeneration;170};171172this.shouldChangePattern = function(x) {173if (x) {174var q = randInt(0, 4);175this.ct = 0;176switch (q) {177case 0:178this.currentFunction = this.doubleGeneration;179break;180case 1:181this.currentFunction = this.spiralGeneration;182break;183case 2:184this.currentFunction = this.crosswiseGeneration;185break;186}187} else if (this.ct > 8) {188if (randInt(0, 2) === 0) {189this.setRandom();190return 1;191}192}193194return 0;195};196197// rest of generation functions198199this.currentFunction = this.randomGeneration;200}201202203