-
Notifications
You must be signed in to change notification settings - Fork 3
/
tileset2.js
63 lines (55 loc) · 3.19 KB
/
tileset2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function TileSet(type, imageUrlArray, pattern) {
// starts off with 9 set, ends with 4 set
// topleft, topmiddle, topright, middleleft, middlemiddle, middleright, bottomleft, bottommiddle, bottomright
// topsingle, leftsingle, rightsingle, bottomsingle
this.tileArray = new Array(imageUrlArray.length-1);
this.type = tileType;
this.num = typeNum;
for(i = 0; i<imageUrlArray.length; i++){
this.tileArray[i] = new Image();
this.tileArray[i].src = imageUrlArray[i];
}
this.aryComp = function(array1, array2){
for(i = 0; i<array1.length; i++){
for(k = 0; k<array1[i].length; k++){
if( ( array1[i][k] != array2[i][k] ) && ( array2[i][k] != 9 ) ) return false;
}
}
return true;
}
this.getTile = function(sur){
// get sent a 3x3 array of the tiles around current spot (this one being the middle)
if(sur != null){
for(i = 0; i<sur.length; i++){
for(k = 0; k<sur[1].length; k++){
if(sur[i][k] != this.num){
sur[i][k] = 0;
}
}
}
}
if(sur != null && this.num != sur[1][1]) return false;
if(this.type == "full"){
if( this.aryComp(sur, [[9,0,9],[0,this.num,this.num],[9,this.num,9]] ) ){ return this.tileArray[0];
} else if( this.aryComp(sur, [[9,0,9],[this.num,this.num,this.num],[9,this.num,9]] ) ){ return this.tileArray[1];
} else if( this.aryComp(sur, [[9,0,9],[this.num,this.num,0],[9,this.num,9]] ) ){ return this.tileArray[2];
} else if( this.aryComp(sur, [[9,this.num,9],[0,this.num,this.num],[9,this.num,9]] ) ){ return this.tileArray[3];
} else if( this.aryComp(sur, [[9,this.num,9],[this.num,this.num,this.num],[9,this.num,9]] ) ){ return this.tileArray[4];
} else if( this.aryComp(sur, [[9,this.num,9],[this.num,this.num,0],[9,this.num,9]] ) ){ return this.tileArray[5];
} else if( this.aryComp(sur, [[9,this.num,9],[0,this.num,this.num],[9,0,9]] ) ){ return this.tileArray[6];
} else if( this.aryComp(sur, [[9,this.num,9],[this.num,this.num,this.num],[9,0,9]] ) ){ return this.tileArray[7];
} else if( this.aryComp(sur, [[9,this.num,9],[this.num,this.num,0],[9,0,9]] ) ){ return this.tileArray[8];
} else if( this.aryComp(sur, [[9,0,9],[0,this.num,0],[9,this.num,9]] ) ){ return this.tileArray[9];
} else if( this.aryComp(sur, [[9,0,9],[0,this.num,this.num],[9,0,9]] ) ){ return this.tileArray[10];
} else if( this.aryComp(sur, [[9,0,9],[this.num,this.num,0],[9,0,9]] ) ){ return this.tileArray[11];
} else if( this.aryComp(sur, [[9,this.num,9],[0,this.num,0],[9,0,9]] ) ){ return this.tileArray[12];
} else if( this.aryComp(sur, [[9,0,9],[this.num,this.num,this.num],[9,0,9]] ) ){ return this.tileArray[13];
} else if( this.aryComp(sur, [[9,this.num,9],[0,this.num,0],[9,this.num,9]] ) ){ return this.tileArray[14];
} else { return this.tileArray[15]; }
} else if(this.type == "dual"){
if( this.aryComp(sur, [[9,0,9],[9,this.num,9],[9,this.num,9]])){ return this.tileArray[0]; // top
} else if( this.aryComp(sur, [[9,0,9],[9,this.num,9],[9,0,9]])){ return this.tileArray[0]; // bottom
} else { return this.tileArray[1]; }
} else if(this.type == "single"){ return this.tileArray[0]; }
}
}