From 1952708e9f746072446f99c8cb166c7888e7446e Mon Sep 17 00:00:00 2001 From: onezDerv Date: Sat, 14 Sep 2024 22:32:14 -0400 Subject: [PATCH] some fixes. --- assets/box.svg | 16 ++-- assets/collapseA.svg | 10 +-- assets/collapseB.svg | 22 ++--- assets/groundA.svg | 20 ++--- assets/groundB.svg | 16 ++-- assets/player.svg | 198 +++++++++++++++++++++---------------------- game.css | 27 ++++-- js/index.js | 43 +++++++--- js/motion.js | 4 +- 9 files changed, 195 insertions(+), 161 deletions(-) diff --git a/assets/box.svg b/assets/box.svg index 5c5559b..2d8b79d 100644 --- a/assets/box.svg +++ b/assets/box.svg @@ -2,12 +2,12 @@ diff --git a/assets/groundB.svg b/assets/groundB.svg index 3ef2dc7..9e70d54 100644 --- a/assets/groundB.svg +++ b/assets/groundB.svg @@ -2,12 +2,12 @@ + width="67.947899" + height="466.84476" + x="-193.45036" + y="-866.76935" + rx="81.78009" + ry="62.664776" + transform="matrix(0,1,-0.96983958,-0.24374409,0,0)" /> diff --git a/game.css b/game.css index 7d70b20..7ae5c43 100644 --- a/game.css +++ b/game.css @@ -1,9 +1,9 @@ .message { position: relative; - margin-bottom: -800px; - bottom: 800px; - width: 800px; - height: 800px; + margin-bottom: -1024px; + bottom: 1024px; + width: 1024px; + height: 1024px; display: flex; flex-direction: column; @@ -26,8 +26,21 @@ font-weight: bold; padding: 10px; } + #canvas { - width: 800px; - height: 800px; - image-rendering: pixelated + width: 768px; + height: 768px; + /*image-rendering: pixelated;*/ + background: rgb(63, 63, 71); +} + +section#main { + width: 1024px; +} + +@media (max-width: 780px) { + #canvas { + width: min(512px,90vw); + height: min(512px,90vw); + } } \ No newline at end of file diff --git a/js/index.js b/js/index.js index 6ea5722..a6ccd10 100644 --- a/js/index.js +++ b/js/index.js @@ -1,6 +1,6 @@ //const width = 2048; //const height = 2048; -const tileSize = 128; +const tileSize = 256; const chunkSize = 16; const assets = [ 'assets/groundA.svg', @@ -74,8 +74,8 @@ function Game(inSize, exp, cs) { this.dead = false; } -Game.prototype.placeBlock = function (block) { - let {camera} = this; +Game.prototype.placeBlock = function (block, get = false) { + let { camera, base, fac, exp, inSize } = this; let x = Math.round(camera[0] / tileSize); let y = Math.round(camera[1] / tileSize); @@ -84,9 +84,24 @@ Game.prototype.placeBlock = function (block) { let by = y % chunkSize; let id = getChunk(x, y); - let chunk = this.modChunks[id] = this.modChunks[id] || new Uint8Array(chunkSize * chunkSize); + if (get) { + let g = chunk[by * chunkSize + bx]; + if (g != 0) return g - 1; + + let isMask = toPoint(camera[0], camera[1], base, fac, exp, inSize); + + let assetI = (x - y % 2) == 0 ? 0 : 1; + + if (isMask < 0.5) return 5; + if (isMask < 0.501) return 4; + if (isMask < 0.51) return 3; + + + return assetI; + } + chunk[by * chunkSize + bx] = block + 1; } @@ -94,7 +109,9 @@ Game.prototype.player = function () { let { ctx, fac, base, exp, inSize, camera, cs, assets } = this; ctx.drawImage(assets[2], cs / 2 - tileSize / 1.8, cs / 2 - tileSize / 1.8, tileSize / 0.9, tileSize / 0.9); - if (toPoint(camera[0], camera[1], base, fac, exp, inSize) < 0.5) { + let isBlock = this.placeBlock(0, true); + + if (isBlock == 5) { this.dead = true; } @@ -111,7 +128,7 @@ Game.prototype.player = function () { let dim = Math.log(sum) / (Math.log(base.length) / 2); - document.querySelector('.ui-text').textContent = `Coordinates: ${cx},${cy}\nDimensionality: ${dim}` + document.querySelector('.ui-text').textContent = `X: ${cx}\nY: ${cy}\nDimensionality: ${dim}` } Game.prototype.main = function () { @@ -127,10 +144,12 @@ Game.prototype.main = function () { this.frames++; this.fac = 0.99999 ** frames; - for (let i = 0; i < (cs / tileSize) * (cs / tileSize); i++) { - let x = i % (cs / tileSize) + for (let i = 0; i < ((cs / tileSize + 2) * (cs / tileSize + 2)); i++) { + let x = i % (cs / tileSize + 2); + x--; x *= tileSize; - let y = Math.floor(i / (cs / tileSize)); + let y = Math.floor(i / ((cs / tileSize + 2))); + y--; y *= tileSize; x = x + Math.round((camera[0] - cs / 2) / tileSize) * tileSize; @@ -144,7 +163,7 @@ Game.prototype.main = function () { let chunk = this.modChunks[id]; let bx = Math.round(x / tileSize) % chunkSize; - let by = Math.round(y / tileSize)% chunkSize; + let by = Math.round(y / tileSize) % chunkSize; if (chunk && chunk[by * chunkSize + bx] != 0) { ctx.drawImage(this.assets[chunk[by * chunkSize + bx] - 1], x2, y2, tileSize, tileSize); @@ -213,7 +232,7 @@ Game.prototype.startGame = function () { var ctx = this.ctx = canvas.getContext("2d"); - ctx.imageSmoothingEnabled = false; + //ctx.imageSmoothingEnabled = true; for (let asset in assets) { this.assets[asset] = new Image(); @@ -231,6 +250,6 @@ Game.prototype.init = function () { that.startGame(); } -let game = new Game(8, 8, 20 * tileSize) +let game = new Game(8, 8, 16 * tileSize) game.init(); diff --git a/js/motion.js b/js/motion.js index 0209c93..fdb8c68 100644 --- a/js/motion.js +++ b/js/motion.js @@ -23,8 +23,8 @@ function move() { vel[0] *= 0.8; vel[1] *= 0.8; - game.camera[0] -= vel[0] * 0.9; - game.camera[1] -= vel[1] * 0.9; + game.camera[0] -= vel[0] * 1.8; + game.camera[1] -= vel[1] * 1.8; } setInterval(move, 10);