170 lines
7.2 KiB
JavaScript
170 lines
7.2 KiB
JavaScript
|
|
var socket = io();
|
|
|
|
socket.on('connect', function () {
|
|
console.log("connect!");
|
|
socket.emit("getmap", 100, 100);
|
|
});
|
|
|
|
socket.on('getmap', function (map) {
|
|
console.log(map);
|
|
var domMap = $("#map");
|
|
|
|
domMap.empty();
|
|
for(var w=0;w<map.length;w++) {
|
|
for(var h=0;h<map[w].length;h++) {
|
|
var spClass = "ground";
|
|
if(map[w][h]=="0" || (w<=0 || h<=0 || w>=map.length-1 || h>=map[w].length-1))
|
|
spClass = "water";
|
|
else if((map[w][h-1]=="0" && map[w][h]=="1" && map[w][h+1]=="2" && map[w-1][h+1]=="1") || (map[w-1][h-1]=="0" && map[w][h]=="1" && map[w+1][h]=="2" && map[w+1][h-1]=="1") || (map[w+1][h]=="2" && map[w][h]=="1" && map[w][h+1]=="2")) {
|
|
if(map[w][h+1]=="2" && map[w+1][h]=="2") {
|
|
if(map[w-1][h+1]=="1" && map[w+1][h-1]=="2")
|
|
spClass = "topDown_1";
|
|
else if(map[w+1][h-1]=="1" && map[w-1][h+1]=="2")
|
|
spClass = "leftRight_1";
|
|
else if(map[w+1][h-1]=="2" && map[w-1][h+1]=="2")
|
|
spClass = "leftRightTT_1";
|
|
else
|
|
spClass = "leftRightT_1";
|
|
}
|
|
else
|
|
spClass = "leftRightT_1";
|
|
}
|
|
else if((map[w][h+1]=="0" && map[w][h]=="1" && map[w][h-1]=="2" && map[w-1][h-1]=="1") || (map[w-1][h]=="0" && map[w][h]=="1" && map[w+1][h]=="2" && map[w+1][h+1]=="1") || (map[w+1][h]=="2" && map[w][h]=="1" && map[w][h-1]=="2")) {
|
|
if(map[w][h-1]=="2" && map[w+1][h]=="2") {
|
|
if(map[w-1][h-1]=="1" && map[w+1][h+1]=="2")
|
|
spClass = "topDown_1";
|
|
else if(map[w+1][h+1]=="1" && map[w-1][h-1]=="2")
|
|
spClass = "rightLeft_1";
|
|
else if(map[w-1][h-1]=="2" && map[w+1][h-1]=="2")
|
|
spClass = "rightLeftTT_1";
|
|
else
|
|
spClass = "rightLeftT_1";
|
|
}
|
|
else
|
|
spClass = "rightLeftT_1";
|
|
}
|
|
else if((map[w][h-1]=="0" && map[w][h]=="1" && map[w][h+1]=="2" && map[w+1][h+1]=="1") || (map[w+1][h]=="0" && map[w][h]=="1" && map[w-1][h]=="2" && map[w-1][h-1]=="1") || (map[w-1][h]=="2" && map[w][h]=="1" && map[w][h+1]=="2")) {
|
|
if(map[w][h+1]=="2" && map[w-1][h]=="2") {
|
|
if(map[w+1][h+1]=="1" && map[w-1][h-1]=="2")
|
|
spClass = "downTop_1";
|
|
else if(map[w-1][h-1]=="1" && map[w+1][h+1]=="2")
|
|
spClass = "leftRight_1";
|
|
else if(map[w-1][h-1]=="2" && map[w+1][h+1]=="2")
|
|
spClass = "rightLeftBB_1";
|
|
else
|
|
spClass = "rightLeftB_1";
|
|
}
|
|
else
|
|
spClass = "rightLeftB_1";
|
|
}
|
|
else if((map[w+1][h]=="0" && map[w][h]=="1" && map[w-1][h]=="2" && map[w-1][h+1]=="1") || (map[w][h+1]=="0" && map[w][h]=="1" && map[w][h-1]=="2" && map[w+1][h-1]=="1") || (map[w-1][h]=="2" && map[w][h]=="1" && map[w][h-1]=="2")) {
|
|
if(map[w][h-1]=="2" && map[w-1][h]=="2") {
|
|
if(map[w+1][h-1]=="1" && map[w-1][h+1]=="2")
|
|
spClass = "downTop_1";
|
|
else if(map[w-1][h+1]=="1" && map[w+1][h-1]=="2")
|
|
spClass = "rightLeft_1";
|
|
else if(map[w-1][h+1]=="2" && map[w-1][h+1]=="2")
|
|
spClass = "leftRightBB_1";
|
|
else
|
|
spClass = "leftRightB_1";
|
|
}
|
|
else
|
|
spClass = "leftRightB_1";
|
|
}
|
|
|
|
else if(map[w][h-1]=="3" && map[w][h]=="2" && map[w-1][h]=="3")
|
|
spClass = "rightLeftBU_2";
|
|
else if(map[w][h-1]=="4" && map[w][h]=="3" && map[w-1][h]=="4")
|
|
spClass = "rightLeftBU_3";
|
|
else if(map[w][h-1]=="6" && map[w][h]=="5" && map[w-1][h]=="6")
|
|
spClass = "rightLeftBU_5";
|
|
|
|
else if(map[w][h+1]=="3" && map[w][h]=="2" && map[w-1][h]=="3")
|
|
spClass = "leftRightBU_2";
|
|
else if(map[w][h+1]=="4" && map[w][h]=="3" && map[w-1][h]=="4")
|
|
spClass = "leftRightBU_3";
|
|
else if(map[w][h+1]=="6" && map[w][h]=="5" && map[w-1][h]=="6")
|
|
spClass = "leftRightBU_5";
|
|
|
|
else if(map[w][h+1]=="3" && map[w][h]=="2" && map[w+1][h]=="3")
|
|
spClass = "rightLeftTU_2";
|
|
else if(map[w][h+1]=="4" && map[w][h]=="3" && map[w+1][h]=="4")
|
|
spClass = "rightLeftTU_3";
|
|
else if(map[w][h+1]=="6" && map[w][h]=="5" && map[w+1][h]=="6")
|
|
spClass = "rightLeftTU_5";
|
|
|
|
else if(map[w][h-1]=="3" && map[w][h]=="2" && map[w+1][h]=="3")
|
|
spClass = "leftRightTU_2";
|
|
else if(map[w][h-1]=="4" && map[w][h]=="3" && map[w+1][h]=="4")
|
|
spClass = "leftRightTU_3";
|
|
else if(map[w][h-1]=="6" && map[w][h]=="5" && map[w+1][h]=="6")
|
|
spClass = "leftRightTU_5";
|
|
|
|
else if(map[w][h-1]=="0" && map[w][h]=="1" && map[w][h+1]=="2")
|
|
spClass = "leftRight_1";
|
|
else if(map[w][h-1]=="1" && map[w][h]=="2" && map[w][h+1]=="3")
|
|
spClass = "leftRight_2";
|
|
else if(map[w][h-1]=="2" && map[w][h]=="3" && map[w][h+1]=="4")
|
|
spClass = "leftRight_3";
|
|
else if(map[w][h]=="4")
|
|
spClass = "ground";
|
|
else if(map[w][h-1]=="4" && map[w][h]=="5" && map[w][h+1]=="6")
|
|
spClass = "leftRight_5";
|
|
else if(map[w][h]=="6")
|
|
spClass = "grass";
|
|
else if((map[w][h+1]=="1" && map[w][h]=="1" && map[w+1][h]=="1") || (map[w][h-1]=="1" && map[w][h]=="1" && map[w+1][h]=="1") || (map[w-1][h]=="1" && map[w][h]=="1" && map[w][h+1]=="1") || (map[w-1][h]=="1" && map[w][h]=="1" && map[w][h-1]=="1"))
|
|
spClass = "water";
|
|
else if(map[w][h+1]=="2" && map[w][h]=="2" && map[w+1][h]=="2")
|
|
spClass = "leftRightT_2";
|
|
else if(map[w][h+1]=="3" && map[w][h]=="3" && map[w+1][h]=="3")
|
|
spClass = "leftRightT_3";
|
|
else if(map[w][h+1]=="5" && map[w][h]=="5" && map[w+1][h]=="5")
|
|
spClass = "leftRightT_5";
|
|
else if(map[w-1][h]=="0" && map[w][h]=="1" && map[w+1][h]=="2")
|
|
spClass = "topDown_1";
|
|
else if(map[w-1][h]=="1" && map[w][h]=="2" && map[w+1][h]=="3")
|
|
spClass = "topDown_2";
|
|
else if(map[w-1][h]=="2" && map[w][h]=="3" && map[w+1][h]=="4")
|
|
spClass = "topDown_3";
|
|
else if(map[w-1][h]=="4" && map[w][h]=="5" && map[w+1][h]=="6")
|
|
spClass = "topDown_5";
|
|
else if(map[w][h+1]=="0" && map[w][h]=="1" && map[w][h-1]=="2")
|
|
spClass = "rightLeft_1";
|
|
else if(map[w][h+1]=="1" && map[w][h]=="2" && map[w][h-1]=="3")
|
|
spClass = "rightLeft_2";
|
|
else if(map[w][h+1]=="2" && map[w][h]=="3" && map[w][h-1]=="4")
|
|
spClass = "rightLeft_3";
|
|
else if(map[w][h+1]=="4" && map[w][h]=="5" && map[w][h-1]=="6")
|
|
spClass = "rightLeft_5";
|
|
else if(map[w][h-1]=="2" && map[w][h]=="2" && map[w+1][h]=="2")
|
|
spClass = "rightLeftT_2";
|
|
else if(map[w][h-1]=="3" && map[w][h]=="3" && map[w+1][h]=="3")
|
|
spClass = "rightLeftT_3";
|
|
else if(map[w][h-1]=="5" && map[w][h]=="5" && map[w+1][h]=="5")
|
|
spClass = "rightLeftT_5";
|
|
else if(map[w+1][h]=="0" && map[w][h]=="1" && map[w-1][h]=="2")
|
|
spClass = "downTop_1";
|
|
else if(map[w+1][h]=="1" && map[w][h]=="2" && map[w-1][h]=="3")
|
|
spClass = "downTop_2";
|
|
else if(map[w+1][h]=="2" && map[w][h]=="3" && map[w-1][h]=="4")
|
|
spClass = "downTop_3";
|
|
else if(map[w+1][h]=="4" && map[w][h]=="5" && map[w-1][h]=="6")
|
|
spClass = "downTop_5";
|
|
else if(map[w][h+1]=="2" && map[w][h]=="2" && map[w-1][h]=="2")
|
|
spClass = "leftRightB_2";
|
|
else if(map[w][h+1]=="3" && map[w][h]=="3" && map[w-1][h]=="3")
|
|
spClass = "leftRightB_3";
|
|
else if(map[w][h+1]=="5" && map[w][h]=="5" && map[w-1][h]=="5")
|
|
spClass = "leftRightB_5";
|
|
else if(map[w][h-1]=="2" && map[w][h]=="2" && map[w-1][h]=="2")
|
|
spClass = "rightLeftB_2";
|
|
else if(map[w][h-1]=="3" && map[w][h]=="3" && map[w-1][h]=="3")
|
|
spClass = "rightLeftB_3";
|
|
else if(map[w][h-1]=="5" && map[w][h]=="5" && map[w-1][h]=="5")
|
|
spClass = "rightLeftB_5";
|
|
|
|
domMap.append('<img style="top:'+(w*32)+'px; left:'+(h*32)+'px" src="./img/plain.png" i="'+map[w][h]+'" class="sprite '+spClass+'">');
|
|
}
|
|
}
|
|
}); |