mapVersion1

This commit is contained in:
rofl256 2016-10-20 10:45:29 +02:00
parent 114e2bbc44
commit 2fbd703d33
3 changed files with 407 additions and 135 deletions

View File

@ -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;
}

View File

@ -14,27 +14,157 @@ socket.on('getmap', function (map) {
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")
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")
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('<img style="top:'+(w*32)+'px; left:'+(h*32)+'px" src="./img/plain.png" class="sprite '+spClass+'">');
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+'">');
}
}
});

172
s_map.js
View File

@ -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<g.length;k++) {
var i = g[k]+"";
for(var w=1;w<map.length-1;w++) {
for(var h=1;h<map[w].length-1;h++) {
if(map[w][h] == "0" && (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;
for(var w=0;w<width;w++) {
map[w] = [];
for(var h=0;h<height;h++) {
@ -9,11 +50,7 @@ module.exports = {
map[w][h] = "0";
} else {
map[w][h] = "0";
p = 1;
if(map[w-1][h]=="#")
p+=43;
if(map[w][h-1]=="#")
p+=43;
p = 0.1;
if(rand(p))
map[w][h] = "#";
}
@ -22,39 +59,7 @@ module.exports = {
//preprocessing
for(i=0;i<2;i++) { //Reduce little ilands
for(var w=0;w<width;w++) {
for(var h=0;h<height;h++) {
if(map[w][h]=="#") {
var waterCnt = 0;
if(map[w-1][h]=="0")
waterCnt++;
if(map[w+1][h]=="0")
waterCnt++;
if(map[w][h-1]=="0")
waterCnt++;
if(map[w][h+1]=="0")
waterCnt++;
if(map[w-1][h-1]=="0")
waterCnt++;
if(map[w-1][h+1]=="0")
waterCnt++;
if(map[w+1][h-1]=="0")
waterCnt++;
if(map[w+1][h+1]=="0")
waterCnt++;
if(waterCnt > 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;w++) {
orgMap[w] = [];
@ -63,26 +68,35 @@ module.exports = {
}
}
for(var w=0;w<width;w++) {
for(var h=0;h<height;h++) {
if(orgMap[w][h]=="#" && !(w<=0 || h<=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;w++) {
for(var h=1;h<height-1;h++) {
if(orgMap[w][h]=="#") {
if(rand(exP)) map[w-1][h]="#"
if(rand(exP)) map[w+1][h]="#"
if(rand(exP)) map[w][h-1]="#"
if(rand(exP)) map[w][h+1]="#"
if(rand(exP)) map[w-1][h-1]="#"
if(rand(exP)) map[w-1][h+1]="#"
if(rand(exP)) map[w+1][h-1]="#"
if(rand(exP)) map[w+1][h+1]="#"
}
}
}
}
for(i=0;i<4;i++) { //fill water holes
for(var w=0;w<width;w++) {
for(var h=0;h<height;h++) {
if(map[w][h]=="0" && !(w<=0 || h<=0 || w>=width-1 || h>=height-1)) {
for(var w=0;w<width;w++) {
for(var h=0;h<height;h++) {
if(h<4 || w<4 || w>width-5 || h>height-5) {
map[w][h] = "0"; //border water
}
}
}
for(i=0;i<10;i++) { //fill water holes
for(var w=1;w<width-1;w++) {
for(var h=1;h<height-1;h++) {
if(map[w][h]=="0") {
var groundCtn = 0;
if(map[w-1][h]=="#")
groundCtn++;
@ -101,7 +115,7 @@ module.exports = {
if(map[w+1][h+1]=="#")
groundCtn++;
if(groundCtn > 5)
if(groundCtn >= 5)
map[w][h] = "#";
}
}
@ -116,45 +130,25 @@ module.exports = {
//Set ground type
for(var w=0;w<width;w++) {
for(var h=0;h<height;h++) {
if(map[w][h]=="0" && !(w<=0 || h<=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<g.length;k++) {
// var i = g[k]+"";
// for(var w=0;w<width;w++) {
// for(var h=0;h<height;h++) {
// if(map[w][h] == "0" && !(w<=0 || h<=0 || w>=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;
}
};