diff --git a/js/game.js b/js/game.js index 5b598af..b5757d7 100644 --- a/js/game.js +++ b/js/game.js @@ -29,7 +29,7 @@ let global = { charStage: { [CHARACTER.KNIGHT]: 0, }, - version: 2_001_004, + version: 2_001_005, }, game = { character: CHARACTER.KNIGHT, difficulty: 0, diff --git a/js/graphics.js b/js/graphics.js index b500177..52ecaf1 100644 --- a/js/graphics.js +++ b/js/graphics.js @@ -1730,56 +1730,51 @@ const graphics = { draw.lore(x + 3, y + height - 11, "Go back"); }, /** - * Calculates the map paths, then draws the map on the canvas. - * @param {boolean} onlyCalc - whether to only calculate the map paths. Defaults to `false`. - * @param {number} area - overrides the area of the map being calculated and drawn. + * Draws the map on the canvas. + * @param {number} area - overrides the area of the map being drawn. */ - map(onlyCalc = false, area = get.area(game.floor + (game.state === STATE.EVENT_FIN ? 1 : 0))) { - let render = !onlyCalc; + map(area = get.area(game.floor + (game.state === STATE.EVENT_FIN ? 1 : 0))) { + // setup + let availableLocations = getAvailibleLocations(); // draw map - if (render) { - draw.rect("#000"); - draw.image(I.map.top, 3, 12); - draw.image(I.map.row, 16, 19, I.map.row.width, 174); - draw.image(I.map.bottom, 16, 184); - if (game.state === STATE.EVENT_FIN) { - if (game.floor % 10 == 9) { - draw.image(I.map.select, 18 + (9 * 32), 12); - draw.image(I.map.select, 12 + (10 * 32), 12); - } else if (game.floor % 10 === 0) { - draw.image(I.map.select_first, 13, 12); - } else { - draw.image(I.map.select, 13 + (game.floor % 10 * 32), 12); - }; - } else if (game.floor > 0) { - if (game.floor % 10 == 0) { - draw.image(I.map.select, 18 + (9 * 32), 12); - draw.image(I.map.select, 12 + (10 * 32), 12); - } else if (game.floor % 10 == 1) { - draw.image(I.map.select_first, 13, 12); - } else { - draw.image(I.map.select, 13 + ((game.floor % 10 - 1) * 32), 12); - }; + draw.rect("#000"); + draw.image(I.map.top, 3, 12); + draw.image(I.map.row, 16, 19, I.map.row.width, 174); + draw.image(I.map.bottom, 16, 184); + if (game.state === STATE.EVENT_FIN) { + if (game.floor % 10 == 9) { + draw.image(I.map.select, 18 + (9 * 32), 12); + draw.image(I.map.select, 12 + (10 * 32), 12); + } else if (game.floor % 10 === 0) { + draw.image(I.map.select_first, 13, 12); + } else { + draw.image(I.map.select, 13 + (game.floor % 10 * 32), 12); + }; + } else if (game.floor > 0) { + if (game.floor % 10 == 0) { + draw.image(I.map.select, 18 + (9 * 32), 12); + draw.image(I.map.select, 12 + (10 * 32), 12); + } else if (game.floor % 10 == 1) { + draw.image(I.map.select_first, 13, 12); + } else { + draw.image(I.map.select, 13 + ((game.floor % 10 - 1) * 32), 12); }; - draw.image(I.extra.deck, 22, 16); - if (game.select[0] === S.MAP && game.mapSelect == getAvailibleLocations().length) draw.image(I.select.deck, 21, 15); - draw.image(I.extra.end, 22, 179); - if (game.select[0] === S.MAP && game.mapSelect == -1) draw.image(I.select.round, 21, 178); - draw.lore(1, 1, "floor " + game.floor + " - " + game.gold + " gold", {"color": "#f44"}); - draw.lore(399, 1, "seed: " + game.seed, {"color": "#fff", "text-align": DIR.LEFT}); }; + draw.image(I.extra.deck, 22, 16); + if (game.select[0] === S.MAP && game.mapSelect == availableLocations.length) draw.image(I.select.deck, 21, 15); + draw.image(I.extra.end, 22, 179); + if (game.select[0] === S.MAP && game.mapSelect == -1) draw.image(I.select.round, 21, 178); + draw.lore(1, 1, "floor " + game.floor + " - " + game.gold + " gold", {"color": "#f44"}); + draw.lore(399, 1, "seed: " + game.seed, {"color": "#fff", "text-align": DIR.LEFT}); // draw scribbles - if (render) { - for (let x = area * 10; x < (area + 1) * 10; x++) { - for (let y = 0; y < game.map[x].length; y++) { - if (typeof game.map[x][y] != "number") continue; - draw.image(I.map.scribble_back, 25 + ((x - area * 10) * 32) + 8 - 4, 18 + (y * 32) + 8 - 3 - 2.5, 80 / 2, 80 / 2); - draw.imageSector(I.map.scribbles, game.map[x][y] * 64, 0, 64, 70, 25 + ((x - area * 10) * 32) + 8, 18 + (y * 32) + 8 - 3, 64 / 2, 70 / 2); - }; + for (let x = area * 10; x < (area + 1) * 10; x++) { + for (let y = 0; y < game.map[x].length; y++) { + if (typeof game.map[x][y] != "number") continue; + draw.image(I.map.scribble_back, 25 + ((x - area * 10) * 32) + 8 - 4, 18 + (y * 32) + 8 - 3 - 2.5, 80 / 2, 80 / 2); + draw.imageSector(I.map.scribbles, game.map[x][y] * 64, 0, 64, 70, 25 + ((x - area * 10) * 32) + 8, 18 + (y * 32) + 8 - 3, 64 / 2, 70 / 2); }; }; // calculate nodes and draw paths - let store = []; for (let x = area * 10; x < (area + 1) * 10 && x < game.map.length; x++) { for (let y = 0; y < game.map[x].length; y++) { if (typeof game.map[x][y] != "object") continue; @@ -1789,14 +1784,13 @@ const graphics = { drawX = 25 + 10 + 8 + ((x - area * 10) * 32); drawY = 90 + 8; }; - if (render && x % 10 == 0) { + if (x % 10 == 0) { if (game.traveled[x] === y) draw.line(drawX + 8, drawY + 8, 18, drawY + 8, "#842", 3); else draw.line(drawX + 8, drawY + 8, 18, drawY + 8, "#b84", 3); }; let posX, posY, connectNode = []; const calcNode = (nodeX, nodeY) => { connectNode = [nodeX - x, nodeY]; - store.push([x, y, nodeX, nodeY]); if (game.map[nodeX][nodeY][0] === ROOM.BOSS) { posX = 25 + 10 + 8 + ((nodeX - area * 10) * 32); posY = 90 + 8; @@ -1815,7 +1809,7 @@ const graphics = { break; }; }; - if (render && !(game.traveled[x] === y && game.traveled[x + connectNode[0]] === connectNode[1])) { + if (!(game.traveled[x] === y && game.traveled[x + connectNode[0]] === connectNode[1])) { draw.curvedLine(drawX + 8, drawY + 8, (drawX + posX) / 2 + 8, (x % 2 == 0 ? drawY : posY) + 8, posX + 8, posY + 8, "#b84", 3); }; }; @@ -1829,121 +1823,72 @@ const graphics = { break; }; }; - if (render && !(game.traveled[x] === y && game.traveled[x + connectNode[0]] === connectNode[1])) { + if (!(game.traveled[x] === y && game.traveled[x + connectNode[0]] === connectNode[1])) { draw.curvedLine(drawX + 8, drawY + 8, (drawX + posX) / 2 + 8, (x % 2 == 0 ? drawY : posY) + 8, posX + 8, posY + 8, "#b84", 3); }; }; }; }; // draw traveled path - if (render) { - let drawX, drawY; - for (let x = area * 10; x < game.traveled.length && x < (area + 1) * 10; x++) { - let y = game.traveled[x]; - if (game.map[x][y]) { - if (drawX && drawY) { - let posX = 25 + ((x - area * 10) * 32) + game.map[x][y][1]; - let posY = 18 + (y * 32) + game.map[x][y][2]; - if (game.map[x][y][0] === ROOM.BOSS) { - posX = 25 + 10 + 8 + ((x - area * 10) * 32); - posY = 90 + 8; - }; - draw.curvedLine(drawX + 8, drawY + 8, (drawX + posX) / 2 + 8, (x % 2 == 1 ? drawY : posY) + 8, posX + 8, posY + 8, "#842", 3); - drawX = posX; - drawY = posY; - } else { - drawX = 25 + ((x - area * 10) * 32) + game.map[x][y][1]; - drawY = 18 + (y * 32) + game.map[x][y][2]; + let drawX, drawY; + for (let x = area * 10; x < game.traveled.length && x < (area + 1) * 10; x++) { + let y = game.traveled[x]; + if (game.map[x][y]) { + if (drawX && drawY) { + let posX = 25 + ((x - area * 10) * 32) + game.map[x][y][1]; + let posY = 18 + (y * 32) + game.map[x][y][2]; + if (game.map[x][y][0] === ROOM.BOSS) { + posX = 25 + 10 + 8 + ((x - area * 10) * 32); + posY = 90 + 8; }; + draw.curvedLine(drawX + 8, drawY + 8, (drawX + posX) / 2 + 8, (x % 2 == 1 ? drawY : posY) + 8, posX + 8, posY + 8, "#842", 3); + drawX = posX; + drawY = posY; + } else { + drawX = 25 + ((x - area * 10) * 32) + game.map[x][y][1]; + drawY = 18 + (y * 32) + game.map[x][y][2]; }; }; }; // draw nodes - if (render) { - let availableLocations = getAvailibleLocations(); - const coordSel = availableLocations[game.mapSelect] ? availableLocations[game.mapSelect] : []; - const coordOn = game.location ? game.location : []; - for (let x = area * 10; x < (area + 1) * 10; x++) { - for (let y = 0; y < game.map[x].length; y++) { - if (typeof game.map[x][y] != "object") continue; - let drawX = 25 + ((x - area * 10) * 32) + game.map[x][y][1]; - let drawY = 18 + (y * 32) + game.map[x][y][2]; - if (game.map[x][y][0] === ROOM.BATTLE) { - draw.image(I.map.node.battle, drawX, drawY); - if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.battle, drawX - 1, drawY - 1); - else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.battle, drawX - 1, drawY - 1); - } else if (game.map[x][y][0] === ROOM.PRIME) { - draw.image(I.map.node.death_zone, drawX, drawY); - if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.death_zone, drawX - 1, drawY - 1); - else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.death_zone, drawX - 1, drawY - 1); - } else if (game.map[x][y][0] === ROOM.TREASURE) { - if (game.map[x][y][3]) { - draw.image(I.map.node.treasure_open, drawX, drawY); - if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.treasure_open, drawX - 1, drawY - 1); - else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.treasure_open, drawX - 1, drawY - 1); - } else { - draw.image(I.map.node.treasure, drawX, drawY); - if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.treasure, drawX - 1, drawY - 1); - else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.treasure, drawX - 1, drawY - 1); - }; - } else if (game.map[x][y][0] === ROOM.ORB) { - draw.image(I.map.node.orb, drawX, drawY); - if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.orb, drawX - 1, drawY - 1); - else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.orb, drawX - 1, drawY - 1); - } else if (game.map[x][y][0] === ROOM.BOSS) { - drawX += 10; - draw.image(I.map.node.boss, drawX, 90); - if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.boss, drawX - 1, 90 - 1); - else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.boss, drawX - 1, 90 - 1); - } else if (game.map[x][y][0] === ROOM.EVENT) { - draw.image(I.map.node.event, drawX, drawY); - if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.event, drawX - 1, drawY - 1); - else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.event, drawX - 1, drawY - 1); - }; - }; - }; - }; - // create paths - paths = {}; - for (let index = 0; index < store.length; index++) { - const coords = store[index]; - if (coords[2] > coords[0]) { - if (!paths[coords[0]]) paths[coords[0]] = {}; - if (!paths[coords[0]][coords[1]]) paths[coords[0]][coords[1]] = []; - if (!paths[coords[0]][coords[1]].some(location => location[0] === coords[2] && location[1] === coords[3])) { - paths[coords[0]][coords[1]].push([coords[2], coords[3]]); - }; - } else if (coords[0] > coords[2]) { - if (!paths[coords[2]]) paths[coords[2]] = {}; - if (!paths[coords[2]][coords[3]]) paths[coords[2]][coords[3]] = []; - if (!paths[coords[2]][coords[3]].some(location => location[0] === coords[0] && location[1] === coords[1])) { - paths[coords[2]][coords[3]].push([coords[0], coords[1]]); - }; - }; - if (coords[0] === 0) { - if (!paths[-1]) paths[-1] = []; - if (!paths[-1].some(location => location[0] === coords[0] && location[1] === coords[1])) { - paths[-1].push([coords[0], coords[1]]); - }; - } else if (coords[0] === 10) { - if (!paths[9]) paths[9] = {}; - if (!paths[9][2]) paths[9][2] = []; - if (!paths[9][2].includes([coords[0], coords[1]])) { - paths[9][2].push([coords[0], coords[1]]); - }; - }; - }; - // sort paths - for (const x in paths) { - if (paths.hasOwnProperty(x)) { - if (x == -1) { - paths[x].sort(); - } else { - for (const y in paths[x]) { - if (paths[x].hasOwnProperty(y)) { - paths[x][y].sort(); - }; + const coordSel = availableLocations[game.mapSelect] ? availableLocations[game.mapSelect] : []; + const coordOn = game.location ? game.location : []; + for (let x = area * 10; x < (area + 1) * 10; x++) { + for (let y = 0; y < game.map[x].length; y++) { + if (typeof game.map[x][y] != "object") continue; + let drawX = 25 + ((x - area * 10) * 32) + game.map[x][y][1]; + let drawY = 18 + (y * 32) + game.map[x][y][2]; + if (game.map[x][y][0] === ROOM.BATTLE) { + draw.image(I.map.node.battle, drawX, drawY); + if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.battle, drawX - 1, drawY - 1); + else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.battle, drawX - 1, drawY - 1); + } else if (game.map[x][y][0] === ROOM.PRIME) { + draw.image(I.map.node.death_zone, drawX, drawY); + if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.death_zone, drawX - 1, drawY - 1); + else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.death_zone, drawX - 1, drawY - 1); + } else if (game.map[x][y][0] === ROOM.TREASURE) { + if (game.map[x][y][3]) { + draw.image(I.map.node.treasure_open, drawX, drawY); + if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.treasure_open, drawX - 1, drawY - 1); + else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.treasure_open, drawX - 1, drawY - 1); + } else { + draw.image(I.map.node.treasure, drawX, drawY); + if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.treasure, drawX - 1, drawY - 1); + else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.treasure, drawX - 1, drawY - 1); }; + } else if (game.map[x][y][0] === ROOM.ORB) { + draw.image(I.map.node.orb, drawX, drawY); + if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.orb, drawX - 1, drawY - 1); + else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.orb, drawX - 1, drawY - 1); + } else if (game.map[x][y][0] === ROOM.BOSS) { + drawX += 10; + draw.image(I.map.node.boss, drawX, 90); + if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.boss, drawX - 1, 90 - 1); + else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.boss, drawX - 1, 90 - 1); + } else if (game.map[x][y][0] === ROOM.EVENT) { + draw.image(I.map.node.event, drawX, drawY); + if (x == coordSel[0] && y == coordSel[1]) draw.image(I.map.node.select.event, drawX - 1, drawY - 1); + else if (x == coordOn[0] && y == coordOn[1]) draw.image(I.map.node.select_blue.event, drawX - 1, drawY - 1); }; }; }; diff --git a/js/map.js b/js/map.js index 867f13f..a4e5067 100644 --- a/js/map.js +++ b/js/map.js @@ -134,56 +134,87 @@ async function mapRow(row) { }; }; if (row % 10 == 9) return [false, false, await mapPiece(row, 0, MAP_PIECE.BOSS), false, false, false]; - let arr = [await mapPiece(row, 0), await mapPiece(row, 1), await mapPiece(row, 2), await mapPiece(row, 3), await mapPiece(row, 4), await mapPiece(row, 5)]; - if (row % 10 > 0) { - game.map.push(arr); - graphics.map(true, get.area(row + 1)); - if (row % 10 > 1) { - let available = [0, 1, 2, 3, 4, 5]; - let rand = available.splice(randomInt(0, available.length - 1), 1)[0]; - while (true) { - if (arr[rand] && !pathHasTypes([row, rand], [ROOM.TREASURE, ROOM.PRIME])) { - arr[rand] = await mapPiece(row, rand, MAP_PIECE.TREASURE); - break; - } else if (available.length) { - rand = available.splice(randomInt(0, available.length - 1), 1)[0]; - } else { - break; + return [await mapPiece(row, 0), await mapPiece(row, 1), await mapPiece(row, 2), await mapPiece(row, 3), await mapPiece(row, 4), await mapPiece(row, 5)]; +}; + +/** + * Calculates the paths of a map region. + * @param {number} xMin - the inclusive start of the map region to calculate paths for. Defaults to `0`. + * @param {number} xMax - the exclusive end of the map region to calculate paths for. Defaults to `Infinity`. + */ +function calculateMapPaths(xMin = 0, xMax = Infinity) { + // calculate connections + let store = []; + for (let x = xMin; x < xMax && x < game.map.length; x++) { + for (let y = 0; y < game.map[x].length; y++) { + if (!game.map[x][y]) continue; + if (x % 10 != 9 && game.map[x + 1]) { + for (num = 0; num < game.map[x + 1].length; num++) { + if (game.map[x + 1][y - num]) { + store.push([x, y, x + 1, y - num]); + break; + } else if (game.map[x + 1][y + num]) { + store.push([x, y, x + 1, y + num]); + break; + }; }; }; - }; - if (row % 10 >= 3 && death_zones < 2) { - let available = [0, 1, 2, 3, 4, 5]; - let rand = available.splice(randomInt(0, available.length - 1), 1)[0]; - while (true) { - if (arr[rand] && arr[rand][0] !== ROOM.TREASURE && !pathHasTypes([row, rand], [ROOM.TREASURE, ROOM.PRIME])) { - arr[rand] = await mapPiece(row, rand, MAP_PIECE.PRIME); - death_zones++; - break; - } else if (available.length) { - rand = available.splice(randomInt(0, available.length - 1), 1)[0]; - } else { - break; + if (x % 10 != 0) { + for (num = 0; num < game.map[x - 1].length; num++) { + if (game.map[x - 1][y - num]) { + store.push([x, y, x - 1, y - num]); + break; + } else if (game.map[x - 1][y + num]) { + store.push([x, y, x - 1, y + num]); + break; + }; }; }; }; - if (row % 2 == eventShift && row % 10 < 7) { - let available = [0, 1, 2, 3, 4, 5]; - let rand = available.splice(randomInt(0, available.length - 1), 1)[0]; - while (true) { - if (arr[rand] && arr[rand][0] !== ROOM.TREASURE && arr[rand][0] !== ROOM.PRIME && !pathHasTypes([row, rand], [ROOM.EVENT])) { - arr[rand] = await mapPiece(row, rand, MAP_PIECE.EVENT); - break; - } else if (available.length) { - rand = available.splice(randomInt(0, available.length - 1), 1)[0]; - } else { - break; + }; + // create paths + for (let index = 0; index < store.length; index++) { + const coords = store[index]; + if (coords[2] > coords[0]) { + if (!paths[coords[0]]) paths[coords[0]] = {}; + if (!paths[coords[0]][coords[1]]) paths[coords[0]][coords[1]] = []; + if (!paths[coords[0]][coords[1]].some(location => location[0] === coords[2] && location[1] === coords[3])) { + paths[coords[0]][coords[1]].push([coords[2], coords[3]]); + }; + } else if (coords[0] > coords[2]) { + if (!paths[coords[2]]) paths[coords[2]] = {}; + if (!paths[coords[2]][coords[3]]) paths[coords[2]][coords[3]] = []; + if (!paths[coords[2]][coords[3]].some(location => location[0] === coords[0] && location[1] === coords[1])) { + paths[coords[2]][coords[3]].push([coords[0], coords[1]]); + }; + }; + if (coords[0] === 0) { + if (!paths[-1]) paths[-1] = []; + if (!paths[-1].some(location => location[0] === coords[0] && location[1] === coords[1])) { + paths[-1].push([coords[0], coords[1]]); + }; + } else if (coords[0] === 10) { + if (!paths[9]) paths[9] = {}; + if (!paths[9][2]) paths[9][2] = []; + if (!paths[9][2].some(location => location[0] === coords[0] && location[1] === coords[1])) { + paths[9][2].push([coords[0], coords[1]]); + }; + }; + }; + // sort paths + for (const x in paths) { + if (paths.hasOwnProperty(x)) { + if (x == -1) { + paths[x].sort(); + } else { + for (const y in paths[x]) { + if (paths[x].hasOwnProperty(y)) { + paths[x][y].sort(); + }; }; }; }; - game.map.pop(); }; - return arr; }; /** @@ -194,7 +225,55 @@ async function generateArea(num) { death_zones = 0; eventShift = randomInt(0, 1); for (let index = 0; index < 10; index++) { - game.map.push(await mapRow(index + num * 10)); + let rowNum = index + num * 10; + game.map.push(await mapRow(rowNum)); + calculateMapPaths(Math.max(rowNum - 1, 0)); + if (rowNum % 10 > 0 && rowNum % 10 < 8) { + let newRow = game.map[rowNum]; + if (rowNum % 10 > 1) { + let available = [0, 1, 2, 3, 4, 5]; + let rand = available.splice(randomInt(0, available.length - 1), 1)[0]; + while (true) { + if (newRow[rand] && !pathHasTypes([rowNum, rand], [ROOM.TREASURE, ROOM.PRIME])) { + newRow[rand] = await mapPiece(rowNum, rand, MAP_PIECE.TREASURE); + break; + } else if (available.length) { + rand = available.splice(randomInt(0, available.length - 1), 1)[0]; + } else { + break; + }; + }; + }; + if (rowNum % 10 >= 3 && death_zones < 2) { + let available = [0, 1, 2, 3, 4, 5]; + let rand = available.splice(randomInt(0, available.length - 1), 1)[0]; + while (true) { + if (newRow[rand] && newRow[rand][0] !== ROOM.TREASURE && !pathHasTypes([rowNum, rand], [ROOM.TREASURE, ROOM.PRIME])) { + newRow[rand] = await mapPiece(rowNum, rand, MAP_PIECE.PRIME); + death_zones++; + break; + } else if (available.length) { + rand = available.splice(randomInt(0, available.length - 1), 1)[0]; + } else { + break; + }; + }; + }; + if (rowNum % 2 == eventShift && rowNum % 10 < 7) { + let available = [0, 1, 2, 3, 4, 5]; + let rand = available.splice(randomInt(0, available.length - 1), 1)[0]; + while (true) { + if (newRow[rand] && newRow[rand][0] !== ROOM.TREASURE && newRow[rand][0] !== ROOM.PRIME && !pathHasTypes([rowNum, rand], [ROOM.EVENT])) { + newRow[rand] = await mapPiece(rowNum, rand, MAP_PIECE.EVENT); + break; + } else if (available.length) { + rand = available.splice(randomInt(0, available.length - 1), 1)[0]; + } else { + break; + }; + }; + }; + }; }; let row = 3 + num * 10; while (death_zones === 0) { @@ -265,7 +344,6 @@ async function generateMap() { await generateArea(0); await generateArea(1); addScribbles(); - graphics.map(true); changeMusic(); loaded = true; }; diff --git a/js/technical.js b/js/technical.js index 1f00dc8..0b564da 100644 --- a/js/technical.js +++ b/js/technical.js @@ -102,7 +102,7 @@ window.onload = async function() { if (game.map.length === 0) { await generateMap(); } else { - graphics.map(true); + calculateMapPaths(); changeMusic(); loaded = true; };