rename laby to loadingMaze

This commit is contained in:
Adrien MALINGREY 2024-03-20 16:41:00 +01:00
parent 852394c54c
commit d0446e680d
3 changed files with 19 additions and 19 deletions

View File

@ -144,8 +144,8 @@
</head> </head>
<body> <body>
<div id="loading"> <div id="loading">
<div id="labyShadow"> <div id="loadingMazeShadow">
<table id="labyTable"></table> <table id="loadingMazeTable"></table>
</div> </div>
<div id="loadingMessage">Construction du labyrinthe : <span id="progress">0</span>%</div> <div id="loadingMessage">Construction du labyrinthe : <span id="progress">0</span>%</div>
<div> <div>

28
main.js
View File

@ -14,13 +14,13 @@ import MazeMesh from './MazeMesh.js'
// LOADING // LOADING
const labyWidth = 23 const loadingMazeWidth = 23
const labyHeight = 23 const loadingMazeHeight = 23
for(let y=0; y < labyHeight; y++) { for(let y=0; y < loadingMazeHeight; y++) {
let tr = document.createElement("tr") let tr = document.createElement("tr")
labyTable.appendChild(tr) loadingMazeTable.appendChild(tr)
for(let x=0; x < labyWidth; x++) { for(let x=0; x < loadingMazeWidth; x++) {
let td = document.createElement("td") let td = document.createElement("td")
tr.appendChild(td) tr.appendChild(td)
} }
@ -30,7 +30,7 @@ let walls
function dig(x, y) { function dig(x, y) {
walls[y][x] = false walls[y][x] = false
labyTable.children[y].children[x].className = "ground" loadingMazeTable.children[y].children[x].className = "ground"
} }
const directions = [[0, 1], [0, -1], [1, 0], [-1, 0]] const directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]
@ -41,7 +41,7 @@ function* build(x, y) {
let y1 = y + dy let y1 = y + dy
let x2 = x1 + dx let x2 = x1 + dx
let y2 = y1 + dy let y2 = y1 + dy
if (0 <= x2 && x2 < labyWidth && 0 <= y2 && y2 < labyHeight && walls[y2][x2]) { if (0 <= x2 && x2 < loadingMazeWidth && 0 <= y2 && y2 < loadingMazeHeight && walls[y2][x2]) {
dig(x1, y1) dig(x1, y1)
yield x1, y1 yield x1, y1
dig(x2, y2) dig(x2, y2)
@ -51,18 +51,18 @@ function* build(x, y) {
} }
} }
function* endlessLaby() { function* endlessLoadingMaze() {
while (true) { while (true) {
for (const tr of labyTable.children) { for (const tr of loadingMazeTable.children) {
for (const td of tr.children) { for (const td of tr.children) {
td.className = "wall" td.className = "wall"
} }
} }
walls = Array(labyHeight).fill(true).map(row => Array(labyWidth).fill(true)) walls = Array(loadingMazeHeight).fill(true).map(row => Array(loadingMazeWidth).fill(true))
let x0 = Math.floor(labyWidth / 2) let x0 = Math.floor(loadingMazeWidth / 2)
let y0 = Math.floor(labyHeight / 2) let y0 = Math.floor(loadingMazeHeight / 2)
dig(x0, y0) dig(x0, y0)
yield* build(x0, y0) yield* build(x0, y0)
@ -78,8 +78,8 @@ loader.setPath("textures/")
loadMngr.onStart = function (url, itemsLoaded, itemsTotal) { loadMngr.onStart = function (url, itemsLoaded, itemsTotal) {
progress.innerText = "0" progress.innerText = "0"
let labyIterator = endlessLaby() let loadingMazeIterator = endlessLoadingMaze()
interval = window.setInterval(() => labyIterator.next(), 200) interval = window.setInterval(() => loadingMazeIterator.next(), 200)
} }
loadMngr.onProgress = function (url, itemsLoaded, itemsTotal) { loadMngr.onProgress = function (url, itemsLoaded, itemsTotal) {
progress.innerText = Math.floor(100 * itemsLoaded / itemsTotal) progress.innerText = Math.floor(100 * itemsLoaded / itemsTotal)

View File

@ -30,7 +30,7 @@ body {
} }
} }
#labyShadow { #loadingMazeShadow {
width: 230px; width: 230px;
height: 230px; height: 230px;
margin-left: auto; margin-left: auto;
@ -49,13 +49,13 @@ body {
} }
} }
#labyTable { #loadingMazeTable {
border-collapse: collapse; border-collapse: collapse;
animation: rotation 60s infinite; animation: rotation 60s infinite;
border: none; border: none;
} }
#labyTable td { #loadingMazeTable td {
width: 10px; width: 10px;
height: 10px; height: 10px;
transition: background-color 1s; transition: background-color 1s;