better assets
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
1948
assets/player.svg
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 68 KiB |
34
js/index.js
|
@ -1,15 +1,15 @@
|
|||
//const width = 2048;
|
||||
//const height = 2048;
|
||||
const tileSize = 128;
|
||||
// todo: make names better
|
||||
const chunkSize = 16;
|
||||
const assets = [
|
||||
'assets/ground1.svg',
|
||||
'assets/ground2.svg',
|
||||
'assets/groundA.svg',
|
||||
'assets/groundB.svg',
|
||||
'assets/player.svg',
|
||||
'assets/ground3.svg',
|
||||
'assets/ground4.svg',
|
||||
'assets/ground5.svg',
|
||||
'assets/ground6.svg'
|
||||
'assets/collapseA.svg',
|
||||
'assets/collapseB.svg',
|
||||
'assets/nothing.svg',
|
||||
'assets/box.svg'
|
||||
];
|
||||
|
||||
function getRGBA(data, i) {
|
||||
|
@ -50,8 +50,8 @@ function toPoint(x2, y2, base, fac, exp, inSize) {
|
|||
}
|
||||
|
||||
function getChunk(x, y) {
|
||||
let cx = Math.floor(x / 16);
|
||||
let cy = Math.floor(y / 16);
|
||||
let cx = Math.floor(x / chunkSize);
|
||||
let cy = Math.floor(y / chunkSize);
|
||||
|
||||
let id = cx + ',' + cy;
|
||||
|
||||
|
@ -80,14 +80,14 @@ Game.prototype.placeBlock = function (block) {
|
|||
let x = Math.round(camera[0] / tileSize);
|
||||
let y = Math.round(camera[1] / tileSize);
|
||||
|
||||
let bx = x % 16;
|
||||
let by = y % 16;
|
||||
let bx = x % chunkSize;
|
||||
let by = y % chunkSize;
|
||||
|
||||
let id = getChunk(x, y);
|
||||
|
||||
let chunk = this.modChunks[id] = this.modChunks[id] || new Uint8Array(16 * 16);
|
||||
let chunk = this.modChunks[id] = this.modChunks[id] || new Uint8Array(chunkSize * chunkSize);
|
||||
|
||||
chunk[by * 16 + bx] = block + 1;
|
||||
chunk[by * chunkSize + bx] = block + 1;
|
||||
}
|
||||
|
||||
Game.prototype.player = function () {
|
||||
|
@ -143,11 +143,11 @@ Game.prototype.main = function () {
|
|||
|
||||
let chunk = this.modChunks[id];
|
||||
|
||||
let bx = Math.round(x / tileSize) % 16;
|
||||
let by = Math.round(y / tileSize)% 16;
|
||||
let bx = Math.round(x / tileSize) % chunkSize;
|
||||
let by = Math.round(y / tileSize)% chunkSize;
|
||||
|
||||
if (chunk && chunk[by * 16 + bx] != 0) {
|
||||
ctx.drawImage(this.assets[chunk[by * 16 + bx] - 1], x2, y2, tileSize, tileSize);
|
||||
if (chunk && chunk[by * chunkSize + bx] != 0) {
|
||||
ctx.drawImage(this.assets[chunk[by * chunkSize + bx] - 1], x2, y2, tileSize, tileSize);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|