2022-06-21 14:46:34 +00:00
|
|
|
import {game} from "/scripts/game/game.js"
|
|
|
|
|
2022-06-23 05:44:57 +00:00
|
|
|
export const tileArray = loadSprites('/img/mine.png', game.tileSize);
|
|
|
|
var counter = 0;
|
2022-06-19 21:54:34 +00:00
|
|
|
|
2022-06-23 05:44:57 +00:00
|
|
|
export function loadSprites(path, tileSize) {
|
|
|
|
|
|
|
|
let tiles = [];
|
|
|
|
let spriteJank = document.createElement("canvas");
|
|
|
|
spriteJank.id = `spriteJank${counter}`
|
|
|
|
spriteJank.style = "display: none;"
|
|
|
|
spriteJank.width = tileSize;
|
|
|
|
spriteJank.height = tileSize;
|
|
|
|
document.body.appendChild(spriteJank);
|
|
|
|
let ctxj = spriteJank.getContext('2d');
|
|
|
|
let spriteSheet = new Image();
|
|
|
|
|
|
|
|
spriteSheet.src = path
|
2022-06-19 21:54:34 +00:00
|
|
|
spriteSheet.onload = function() {
|
|
|
|
|
2022-06-23 05:44:57 +00:00
|
|
|
|
|
|
|
for (let y = 0; y < spriteSheet.height/tileSize; y++) {
|
|
|
|
for (let x = 0; x < spriteSheet.width/tileSize; x++) {
|
2022-06-21 14:46:34 +00:00
|
|
|
ctxj.drawImage(spriteSheet, -x*tileSize,-y*tileSize)
|
2022-06-19 21:54:34 +00:00
|
|
|
var tmp = new Image();
|
|
|
|
tmp.src = spriteJank.toDataURL();
|
2022-06-21 14:46:34 +00:00
|
|
|
ctxj.clearRect(0, 0, tileSize, tileSize);
|
2022-06-19 21:54:34 +00:00
|
|
|
tiles.push(tmp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spriteJank.remove();
|
2022-06-23 05:44:57 +00:00
|
|
|
|
2022-06-19 21:54:34 +00:00
|
|
|
return tiles;
|
|
|
|
}
|
2022-06-23 05:44:57 +00:00
|
|
|
export const menuArray = loadSprites('/img/modes.png', 32)
|