Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/hextris/js/checking.js
1036 views
1
function search(twoD,oneD){
2
// Searches a two dimensional array to see if it contains a one dimensional array. indexOf doesn't work in this case
3
for(var i=0;i<twoD.length;i++){
4
if(twoD[i][0] == oneD[0] && twoD[i][1] == oneD[1]) {
5
return true;
6
}
7
}
8
return false;
9
}
10
11
function floodFill(hex, side, index, deleting) {
12
if (hex.blocks[side] === undefined || hex.blocks[side][index] === undefined) return;
13
14
//store the color
15
var color = hex.blocks[side][index].color;
16
//nested for loops for navigating the blocks
17
for(var x =-1;x<2;x++){
18
for(var y =-1;y<2;y++){
19
//make sure the they aren't diagonals
20
if(Math.abs(x)==Math.abs(y)){continue;}
21
//calculate the side were exploring using mods
22
var curSide =(side+x+hex.sides)%hex.sides;
23
//calculate the index
24
var curIndex = index+y;
25
//making sure the block exists at this side and index
26
if(hex.blocks[curSide] === undefined){continue;}
27
if(hex.blocks[curSide][curIndex] !== undefined){
28
// checking equivalency of color, if its already been explored, and if it isn't already deleted
29
if(hex.blocks[curSide][curIndex].color == color && search(deleting,[curSide,curIndex]) === false && hex.blocks[curSide][curIndex].deleted === 0 ) {
30
//add this to the array of already explored
31
deleting.push([curSide,curIndex]);
32
//recall with next block explored
33
floodFill(hex,curSide,curIndex,deleting);
34
}
35
}
36
}
37
}
38
}
39
40
function consolidateBlocks(hex,side,index){
41
//record which sides have been changed
42
var sidesChanged =[];
43
var deleting=[];
44
var deletedBlocks = [];
45
//add start case
46
deleting.push([side,index]);
47
//fill deleting
48
floodFill(hex,side,index,deleting);
49
//make sure there are more than 3 blocks to be deleted
50
if(deleting.length<3){return;}
51
var i;
52
for(i=0; i<deleting.length;i++) {
53
var arr = deleting[i];
54
//just making sure the arrays are as they should be
55
if(arr !== undefined && arr.length==2) {
56
//add to sides changed if not in there
57
if(sidesChanged.indexOf(arr[0])==-1){
58
sidesChanged.push(arr[0]);
59
}
60
//mark as deleted
61
hex.blocks[arr[0]][arr[1]].deleted = 1;
62
deletedBlocks.push(hex.blocks[arr[0]][arr[1]]);
63
}
64
}
65
66
// add scores
67
var now = MainHex.ct;
68
if(now - hex.lastCombo < settings.comboTime ){
69
settings.comboTime = (1/settings.creationSpeedModifier) * (waveone.nextGen/16.666667) * 3;
70
hex.comboMultiplier += 1;
71
hex.lastCombo = now;
72
var coords = findCenterOfBlocks(deletedBlocks);
73
hex.texts.push(new Text(coords['x'],coords['y'],"x "+hex.comboMultiplier.toString(),"bold Q","#fff",fadeUpAndOut));
74
}
75
else{
76
settings.comboTime = 240;
77
hex.lastCombo = now;
78
hex.comboMultiplier = 1;
79
}
80
var adder = deleting.length * deleting.length * hex.comboMultiplier;
81
hex.texts.push(new Text(hex.x,hex.y,"+ "+adder.toString(),"bold Q ",deletedBlocks[0].color,fadeUpAndOut));
82
hex.lastColorScored = deletedBlocks[0].color;
83
score += adder;
84
}
85
86