some fixes.

This commit is contained in:
biglyderv 2024-09-14 22:32:14 -04:00
parent e03321351d
commit 1952708e9f
No known key found for this signature in database
GPG key ID: 33AC87E9ACE66954
9 changed files with 195 additions and 161 deletions

View file

@ -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();