From 7429b1ae6d5adbb4bbbfcf340bfeaedcbca9b0d6 Mon Sep 17 00:00:00 2001 From: cracker0dks Date: Sat, 18 May 2019 15:32:28 +0200 Subject: [PATCH] add chest to the game --- css/main.css | 40 +++-- img/chest.png | Bin 0 -> 6365 bytes s_map.js | 464 ++++++++++++++++++++++++++------------------------ server.js | 4 +- 4 files changed, 270 insertions(+), 238 deletions(-) create mode 100644 img/chest.png diff --git a/css/main.css b/css/main.css index 6f4d382..71615bc 100644 --- a/css/main.css +++ b/css/main.css @@ -1,34 +1,35 @@ .sprite { width: 32px; height: 32px; - position: absolute; + position: absolute; } .animate { - background-position:left bottom !important; + background-position: left bottom !important; } -.spriteUtils{ +.spriteUtils { position: absolute; -webkit-transform: scale(0.7); transform: scale(0.7); transform-origin: 0; } -.flower{ +.flower { width: 32px; height: 32px; - background: url(../img/objectlayer.png) 125px -29px;; + background: url(../img/objectlayer.png) 125px -29px; + ; } -.tree1{ +.tree1 { width: 60px; height: 60px; z-index: 110 !important; background: url(../img/objectlayer.png) 315px -70px; } -.stone1{ +.stone1 { width: 32px; height: 35px; background: url(../img/objectlayer.png) 158px -65px; @@ -48,7 +49,7 @@ top: -13px; left: -13px; background: url(../img/guy_sprite.png) 0px 0px; - -webkit-transform: scale(0.7); + -webkit-transform: scale(0.7); transform: scale(0.7); transform-origin: 0; } @@ -150,23 +151,36 @@ } #main { - -webkit-transform: scale(1.5); - transform: scale(2); - transform-origin: 0; + -webkit-transform: scale(1.5); + transform: scale(2); + transform-origin: 0; } -.fass{ +.fass { width: 32px; height: 43px; background: url(../img/objectlayer.png) 157px -18px; } -.forest{ +.forest { width: 46px; height: 46px; background: url(../img/ground_tiles.png) -135px -17px; } +.treasure-closed { + width: 34px; + height: 36px; + background: url(../img/chest.png) 95px -221px; +} + +.treasure-open { + width: 34px; + height: 36px; + background: url(../img/chest.png) 55px -213px; +} + + .water { background: url(../img/ground_tiles.png) 192px 254px; } diff --git a/img/chest.png b/img/chest.png new file mode 100644 index 0000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7^zzCgCbwsYfK{k8dyr%-?GU#Oe#!_Sx-=m5OFz z-A~t3Lpm21tUY$UR!YlSz#y0=yP$SNYq^hIgO-8xY~$h{2ZsRSLWwi)^wq<|uWcK? zotxTxKHQR@s!*u%4e_*Pg@Con7c#Nitrb@`@tfTVa56dXGe2WjH&j;i-G(iIXm0raNaY|b0OJn<8*duTP@Sx0P^{!}=XpYELXIgE(62g&C-!YCDU@B0 zf;P4PT<^9FguOQMcF!&OjXa1l>|Py|-*JWMmGz1*cTV$(fz{f9ZP|t>rY2 Xqn!AP^Skv2h%Fm;1XgX>|JA<$?8Cu~ literal 0 HcmV?d00001 diff --git a/s_map.js b/s_map.js index 1c9a65e..4e0ac91 100644 --- a/s_map.js +++ b/s_map.js @@ -1,187 +1,205 @@ module.exports = { - generateMap: function(width, height) { - var map = []; - var utilMap = []; + generateMap: function (width, height) { + var map = []; + var utilMap = []; - var g = [6,5,4,3,2]; - for(var k=0;k width - 7 || h > height - 7) { + map[w][h] = "0"; //border water + } + } + } + + /* groundtypes + g = ground w = water + */ + // + + //Set ground type + for (var w = 0; w < width; w++) { + for (var h = 0; h < height; h++) { + if (map[w][h] == "#") { //is ground + map[w][h] = "6"; //set ground + + if (Math.random() < 0.011) { + utilMap[w][h] = "forest"; + } else if (utilMap[w - 1][h] == "forest" || utilMap[w][h - 1] == "forest" || utilMap[w - 1][h - 1] == "forest") { + if (Math.random() < 0.8) { + utilMap[w][h] = "forest"; + } + } else if (Math.random() < 0.011) { + utilMap[w][h] = "flower"; + } else if (Math.random() < 0.011) { + utilMap[w][h] = "tree1"; + } else if (Math.random() < 0.011) { + utilMap[w][h] = "stone1"; + } else if (Math.random() < 0.011) { + utilMap[w][h] = "fass"; + } + } + } + } + + for (var w = 0; w < width; w++) { //fill forest + for (var h = 0; h < height; h++) { + if (map[w][h] == "6") { + if ((utilMap[w - 1][h] == "forest" && utilMap[w + 1][h] == "forest") || (utilMap[w][h - 1] == "forest" && utilMap[w][h + 1] == "forest")) { + utilMap[w][h] = "forest"; + } + } + } + } + + var treasureSet = false; + while (!treasureSet) { + for (var w = 0; w < width; w++) { //fill forest + for (var h = 0; h < height; h++) { + if (map[w][h] == "6" && Math.random() < 0.00001 && !treasureSet) { + treasureSet = true; + utilMap[w][h] = "treasure-closed"; + console.log(w, h, "treasure") + } + } + } + } + + + var g = [6, 5, 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 + } + } + } + } + + var cssMap = addCssClass(map); + + return { "map": map, "cssMap": cssMap, "utilMap": utilMap }; } - - for(var i=0;i<2;i++) { - for(var w=7;wwidth-7 || h>height-7) { - map[w][h] = "0"; //border water - } - } - } - - /* groundtypes - g = ground w = water - */ - // - - //Set ground type - for(var w=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 - } - } - } - } - - var cssMap = addCssClass(map); - - return {"map": map, "cssMap":cssMap, "utilMap":utilMap}; - } }; +function rndBetween(start, end) { + return Math.floor(Math.random() * end) + start; +} + function rand(p) { - if(p > Math.random()*100) + if (p > Math.random() * 100) return true; return false; } function addCssClass(map) { - var cssMap = []; - for(var w=0;w=map.length-1 || h>=map[w].length-1)) { - if(Math.random()<0.001) + if (map[w][h] == "0" || (w <= 0 || h <= 0 || w >= map.length - 1 || h >= map[w].length - 1)) { + if (Math.random() < 0.001) spClass = "water_1"; - else if(Math.random()<0.001) + else if (Math.random() < 0.001) spClass = "water_2"; else 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") + 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") + 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") + else if (map[w + 1][h - 1] == "2" && map[w - 1][h + 1] == "2") spClass = "leftRightTT_1"; else spClass = "leftRightT_1"; @@ -189,13 +207,13 @@ function addCssClass(map) { 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") + 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") + 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") + else if (map[w - 1][h - 1] == "2" && map[w + 1][h - 1] == "2") spClass = "rightLeftTT_1"; else spClass = "rightLeftT_1"; @@ -203,13 +221,13 @@ function addCssClass(map) { 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") + 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") + 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") + else if (map[w - 1][h - 1] == "2" && map[w + 1][h + 1] == "2") spClass = "rightLeftBB_1"; else spClass = "rightLeftB_1"; @@ -217,13 +235,13 @@ function addCssClass(map) { 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") + 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") + 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") + else if (map[w - 1][h + 1] == "2" && map[w - 1][h + 1] == "2") spClass = "leftRightBB_1"; else spClass = "leftRightB_1"; @@ -232,99 +250,99 @@ function addCssClass(map) { spClass = "leftRightB_1"; } - else if(map[w][h-1]=="3" && map[w][h]=="2" && map[w-1][h]=="3") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + else if (map[w][h] == "4") spClass = "ground"; - else if(map[w][h-1]=="4" && map[w][h]=="5" && map[w][h+1]=="6") + 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") + 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")) + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + 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") + else if (map[w][h - 1] == "5" && map[w][h] == "5" && map[w - 1][h] == "5") spClass = "rightLeftB_5"; - cssMap[w][h] = spClass; + cssMap[w][h] = spClass; } } - return cssMap; + return cssMap; } diff --git a/server.js b/server.js index aa63899..46d48c3 100644 --- a/server.js +++ b/server.js @@ -11,8 +11,8 @@ app.use(express.static(__dirname + '/')); var server = require('http').Server(app); var io = require('socket.io')(server); var map = require("./s_map.js"); -var mapWidth = 500; -var mapHeight = 500; +var mapWidth = 100; +var mapHeight = 100; var maxX = mapWidth * 32; var maxY = mapHeight * 32; var newmap = map.generateMap(mapWidth,mapHeight);