Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/hextris/js/wavegen.js
1036 views
1
function blockDestroyed() {
2
if (waveone.nextGen > 1350) {
3
waveone.nextGen -= 30 * settings.creationSpeedModifier;
4
} else if (waveone.nextGen > 600) {
5
waveone.nextGen -= 8 * settings.creationSpeedModifier;
6
} else {
7
waveone.nextGen = 600;
8
}
9
10
if (waveone.difficulty < 35) {
11
waveone.difficulty += 0.085 * settings.speedModifier;
12
} else {
13
waveone.difficulty = 35;
14
}
15
}
16
17
function waveGen(hex) {
18
this.lastGen = 0;
19
this.last = 0;
20
this.nextGen = 2700;
21
this.start = 0;
22
this.colors = colors;
23
this.ct = 0;
24
this.hex = hex;
25
this.difficulty = 1;
26
this.dt = 0;
27
this.update = function() {
28
this.currentFunction();
29
this.dt = (settings.platform == 'mobile' ? 14 : 16.6667) * MainHex.ct;
30
this.computeDifficulty();
31
if ((this.dt - this.lastGen) * settings.creationSpeedModifier > this.nextGen) {
32
if (this.nextGen > 600) {
33
this.nextGen -= 11 * ((this.nextGen / 1300)) * settings.creationSpeedModifier;
34
}
35
}
36
};
37
38
this.randomGeneration = function() {
39
if (this.dt - this.lastGen > this.nextGen) {
40
this.ct++;
41
this.lastGen = this.dt;
42
var fv = randInt(0, MainHex.sides);
43
addNewBlock(fv, colors[randInt(0, colors.length)], 1.6 + (this.difficulty / 15) * 3);
44
var lim = 5;
45
if (this.ct > lim) {
46
var nextPattern = randInt(0, 3 + 21);
47
if (nextPattern > 15) {
48
this.ct = 0;
49
this.currentFunction = this.doubleGeneration;
50
} else if (nextPattern > 10) {
51
this.ct = 0;
52
this.currentFunction = this.crosswiseGeneration;
53
} else if (nextPattern > 7) {
54
this.ct = 0;
55
this.currentFunction = this.spiralGeneration;
56
} else if (nextPattern > 4) {
57
this.ct = 0;
58
this.currentFunction = this.circleGeneration;
59
} else if (nextPattern > 1) {
60
this.ct = 0;
61
this.currentFunction = this.halfCircleGeneration;
62
}
63
}
64
}
65
};
66
67
this.computeDifficulty = function() {
68
if (this.difficulty < 35) {
69
var increment;
70
if (this.difficulty < 8) {
71
increment = (this.dt - this.last) / (5166667) * settings.speedModifier;
72
} else if (this.difficulty < 15) {
73
increment = (this.dt - this.last) / (72333333) * settings.speedModifier;
74
} else {
75
increment = (this.dt - this.last) / (90000000) * settings.speedModifier;
76
}
77
78
this.difficulty += increment * (1/2);
79
}
80
};
81
82
this.circleGeneration = function() {
83
if (this.dt - this.lastGen > this.nextGen + 500) {
84
var numColors = randInt(1, 4);
85
if (numColors == 3) {
86
numColors = randInt(1, 4);
87
}
88
89
var colorList = [];
90
nextLoop: for (var i = 0; i < numColors; i++) {
91
var q = randInt(0, colors.length);
92
for (var j in colorList) {
93
if (colorList[j] == colors[q]) {
94
i--;
95
continue nextLoop;
96
}
97
}
98
colorList.push(colors[q]);
99
}
100
101
for (var i = 0; i < MainHex.sides; i++) {
102
addNewBlock(i, colorList[i % numColors], 1.5 + (this.difficulty / 15) * 3);
103
}
104
105
this.ct += 15;
106
this.lastGen = this.dt;
107
this.shouldChangePattern(1);
108
}
109
};
110
111
this.halfCircleGeneration = function() {
112
if (this.dt - this.lastGen > (this.nextGen + 500) / 2) {
113
var numColors = randInt(1, 3);
114
var c = colors[randInt(0, colors.length)];
115
var colorList = [c, c, c];
116
if (numColors == 2) {
117
colorList = [c, colors[randInt(0, colors.length)], c];
118
}
119
120
var d = randInt(0, 6);
121
for (var i = 0; i < 3; i++) {
122
addNewBlock((d + i) % 6, colorList[i], 1.5 + (this.difficulty / 15) * 3);
123
}
124
125
this.ct += 8;
126
this.lastGen = this.dt;
127
this.shouldChangePattern();
128
}
129
};
130
131
this.crosswiseGeneration = function() {
132
if (this.dt - this.lastGen > this.nextGen) {
133
var ri = randInt(0, colors.length);
134
var i = randInt(0, colors.length);
135
addNewBlock(i, colors[ri], 0.6 + (this.difficulty / 15) * 3);
136
addNewBlock((i + 3) % MainHex.sides, colors[ri], 0.6 + (this.difficulty / 15) * 3);
137
this.ct += 1.5;
138
this.lastGen = this.dt;
139
this.shouldChangePattern();
140
}
141
};
142
143
this.spiralGeneration = function() {
144
var dir = randInt(0, 2);
145
if (this.dt - this.lastGen > this.nextGen * (2 / 3)) {
146
if (dir) {
147
addNewBlock(5 - (this.ct % MainHex.sides), colors[randInt(0, colors.length)], 1.5 + (this.difficulty / 15) * (3 / 2));
148
} else {
149
addNewBlock(this.ct % MainHex.sides, colors[randInt(0, colors.length)], 1.5 + (this.difficulty / 15) * (3 / 2));
150
}
151
this.ct += 1;
152
this.lastGen = this.dt;
153
this.shouldChangePattern();
154
}
155
};
156
157
this.doubleGeneration = function() {
158
if (this.dt - this.lastGen > this.nextGen) {
159
var i = randInt(0, colors.length);
160
addNewBlock(i, colors[randInt(0, colors.length)], 1.5 + (this.difficulty / 15) * 3);
161
addNewBlock((i + 1) % MainHex.sides, colors[randInt(0, colors.length)], 1.5 + (this.difficulty / 15) * 3);
162
this.ct += 2;
163
this.lastGen = this.dt;
164
this.shouldChangePattern();
165
}
166
};
167
168
this.setRandom = function() {
169
this.ct = 0;
170
this.currentFunction = this.randomGeneration;
171
};
172
173
this.shouldChangePattern = function(x) {
174
if (x) {
175
var q = randInt(0, 4);
176
this.ct = 0;
177
switch (q) {
178
case 0:
179
this.currentFunction = this.doubleGeneration;
180
break;
181
case 1:
182
this.currentFunction = this.spiralGeneration;
183
break;
184
case 2:
185
this.currentFunction = this.crosswiseGeneration;
186
break;
187
}
188
} else if (this.ct > 8) {
189
if (randInt(0, 2) === 0) {
190
this.setRandom();
191
return 1;
192
}
193
}
194
195
return 0;
196
};
197
198
// rest of generation functions
199
200
this.currentFunction = this.randomGeneration;
201
}
202
203