diff --git a/css/main.css b/css/main.css index 2ccc42e..1e387c2 100644 --- a/css/main.css +++ b/css/main.css @@ -12,50 +12,198 @@ background: url(../img/ground_tiles.png) 640px 541px; } -.groundBottomLeft { - background: url(../img/ground_tiles.png) 288px 382px; +.leftRight_1 { + background: url(../img/ground_tiles.png) 224px 285px; } -.groundLeft { - background: url(../img/ground_tiles.png) 288px 414px; -} - -.groundTopLeft { - background: url(../img/ground_tiles.png) 288px 445px; -} - -.groundTopRight { - background: url(../img/ground_tiles.png) 224px 443px; -} - -.groundTop { - background: url(../img/ground_tiles.png) 256px 445px; -} - -.groundRight { +.leftRight_2 { background: url(../img/ground_tiles.png) 224px 414px; } -.groundBottomRight { - background: url(../img/ground_tiles.png) 224px 382px; +.leftRight_3 { + background: url(../img/ground_tiles.png) 224px 541px; } -.groundBottom { - background: url(../img/ground_tiles.png) 254px 381px; +.leftRight_5 { + background: url(../img/ground_tiles.png) 414px 544px; } -.corner_wg1 { +.grass { + background: url(../img/ground_tiles.png) 640px 635px; +} + +.leftRightT_1 { + background: url(../img/ground_tiles.png) 192px 317px; +} + +.leftRightTT_1 { + background: url(../img/ground_tiles.png) 224px 253px; +} + +.leftRightT_2 { background: url(../img/ground_tiles.png) 192px 445px; } -.corner_wg2 { +.leftRightT_3 { + background: url(../img/ground_tiles.png) 160px 510px; +} + +.leftRightT_5 { + background: url(../img/ground_tiles.png) 383px 540px; +} + +.topDown_1 { + background: url(../img/ground_tiles.png) 256px 253px; +} + +.topDown_2 { + background: url(../img/ground_tiles.png) 252px 381px; +} + +.topDown_3 { + background: url(../img/ground_tiles.png) 256px 509px; +} + +.topDown_5 { + background: url(../img/ground_tiles.png) 448px 509px; +} + +.rightLeft_1 { + background: url(../img/ground_tiles.png) 288px 285px; +} + +.rightLeft_2 { + background: url(../img/ground_tiles.png) 288px 413px; +} + +.rightLeft_3 { + background: url(../img/ground_tiles.png) 288px 541px; +} + +.rightLeft_5 { + background: url(../img/ground_tiles.png) 480px 541px; +} + +.rightLeftT_1 { + background: url(../img/ground_tiles.png) 160px 317px; +} + +.rightLeftTT_1 { + background: url(../img/ground_tiles.png) 288px 254px; +} + +.rightLeftT_2 { background: url(../img/ground_tiles.png) 160px 445px; } -.corner_wg3 { +.rightLeftT_3 { + background: url(../img/ground_tiles.png) 192px 509px; +} + +.rightLeftT_5 { + background: url(../img/ground_tiles.png) 352px 541px; +} + +.downTop_1 { + background: url(../img/ground_tiles.png) 256px 317px; +} + +.downTop_2 { + background: url(../img/ground_tiles.png) 256px 445px; +} + +.downTop_3 { + background: url(../img/ground_tiles.png) 256px 573px; +} + +.downTop_5 { + background: url(../img/ground_tiles.png) 448px 573px; +} + +.rightLeftB_1 { + background: url(../img/ground_tiles.png) 192px 285px; +} + +.rightLeftBB_1 { + background: url(../img/ground_tiles.png) 224px 317px; +} + +.leftRightB_1 { + background: url(../img/ground_tiles.png) 160px 285px; +} + +.leftRightBB_1 { + background: url(../img/ground_tiles.png) 288px 317px; +} + +.leftRightB_2 { + background: url(../img/ground_tiles.png) 192px 413px; +} + +.leftRightB_3 { + background: url(../img/ground_tiles.png) 160px 541px; +} + +.leftRightB_5 { + background: url(../img/ground_tiles.png) 383px 509px; +} + +.rightLeftB_2 { background: url(../img/ground_tiles.png) 160px 413px; } -.corner_wg4 { - background: url(../img/ground_tiles.png) 192px 413px; +.rightLeftB_3 { + background: url(../img/ground_tiles.png) 192px 541px; +} + +.rightLeftB_5 { + background: url(../img/ground_tiles.png) 352px 509px; +} + +.rightLeftBU_2 { + background: url(../img/ground_tiles.png) 288px 445px; +} + +.rightLeftBU_3 { + background: url(../img/ground_tiles.png) 288px 573px; +} + +.rightLeftBU_5 { + background: url(../img/ground_tiles.png) 480px 573px; +} + +.leftRightBU_2 { + background: url(../img/ground_tiles.png) 224px 445px; +} + +.leftRightBU_3 { + background: url(../img/ground_tiles.png) 224px 573px; +} + +.leftRightBU_5 { + background: url(../img/ground_tiles.png) 416px 573px; +} + +.rightLeftTU_2 { + background: url(../img/ground_tiles.png) 224px 381px; +} + +.rightLeftTU_3 { + background: url(../img/ground_tiles.png) 224px 509px; +} + +.rightLeftTU_5 { + background: url(../img/ground_tiles.png) 416px 509px; +} + +.leftRightTU_2 { + background: url(../img/ground_tiles.png) 288px 381px; +} + +.leftRightTU_3 { + background: url(../img/ground_tiles.png) 288px 509px; +} + +.leftRightTU_5 { + background: url(../img/ground_tiles.png) 480px 509px; } \ No newline at end of file diff --git a/js/main.js b/js/main.js index cb38626..581443d 100644 --- a/js/main.js +++ b/js/main.js @@ -14,27 +14,157 @@ socket.on('getmap', function (map) { for(var w=0;w=map.length-1 || h>=map[w].length-1)) spClass = "water"; - else if(map[w][h]=="1") - spClass = "groundBottom"; - else if(map[w][h]=="2") - spClass = "groundTop"; - else if(map[w][h]=="3") - spClass = "groundLeft"; + 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 = "groundRight"; - else if(map[w][h]=="5") - spClass = "groundBottomRight"; + 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 = "groundBottomLeft"; - else if(map[w][h]=="7") - spClass = "groundTopRight"; - else if(map[w][h]=="8") - spClass = "groundTopLeft"; - else if(map[w][h]=="9") - spClass = "corner_wg1"; - domMap.append(''); + 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(''); } } }); \ No newline at end of file diff --git a/s_map.js b/s_map.js index c88e3d8..5668eac 100644 --- a/s_map.js +++ b/s_map.js @@ -1,6 +1,47 @@ module.exports = { generateMap: function(width, height) { var map = []; + var i = 0; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","4","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","4","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","4","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","4","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","4","4","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","4","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","4","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + map[i++] = ["0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"]; + + var g = [6,5,4,3,2]; + for(var k=0;k 4) - map[w][h] = "0"; - } - } - } - } - - - - for(i=0;i<4;i++) { //expand all islands + for(i=0;i<8;i++) { //expand all islands var orgMap = []; for(var w=0;w=width-1 || h>=height-1)) { - map[w-1][h]="#" - map[w+1][h]="#" - map[w][h-1]="#" - map[w][h+1]="#" - map[w-1][h-1]="#" - map[w-1][h+1]="#" - map[w+1][h-1]="#" - map[w+1][h+1]="#" + var exP = 80; + for(var w=1;w=width-1 || h>=height-1)) { + for(var w=0;wwidth-5 || h>height-5) { + map[w][h] = "0"; //border water + } + } + } + + for(i=0;i<10;i++) { //fill water holes + for(var w=1;w 5) + if(groundCtn >= 5) map[w][h] = "#"; } } @@ -116,45 +130,25 @@ module.exports = { //Set ground type for(var w=0;w=width-1 || h>=height-1)) { - if(map[w+1][h]=="#") { - map[w][h] = "1"; - } - if(map[w-1][h]=="#") { - map[w][h] = "2"; - } - - if(map[w][h-1]=="#") { - map[w][h] = "3"; - } - - if(map[w][h+1]=="#") { - map[w][h] = "4"; - } - - if(map[w][h+1]=="#" && map[w+1][h]=="#") { - map[w][h] = "5"; - } - - if(map[w][h-1]=="#" && map[w+1][h]=="#") { - map[w][h] = "6"; - } - - if(map[w][h+1]=="#" && map[w-1][h]=="#") { - map[w][h] = "7"; - } - - if(map[w][h-1]=="#" && map[w-1][h]=="#") { - map[w][h] = "8"; - } - - if(map[w-1][h-1]=="#") { - map[w][h] = "9"; - } + if(map[w][h] == "#") { + map[w][h] = "4"; //set ground } } } + // var g = [4,3,2]; + // for(var k=0;k=width-1 || h>=height-1) && (map[w-1][h]==i || map[w][h-1]==i || map[w][h+1]==i || map[w+1][h]==i || map[w+1][h+1]==i || map[w-1][h-1]==i || map[w+1][h-1]==i || map[w-1][h+1]==i)) { + // map[w][h] = (i-1)+""; //set ground + // } + // } + // } + // } + + return map; } };