Select Git revision
game.js 12.16 KiB
(() => {
// src/js/config.js
var GAME_TITLE = "Untitled JS13K23 Game.";
var WIDTH = 256;
var HEIGHT = 240;
var SCALE = 2 << 4;
// src/js/utils.js
var params = new URLSearchParams(location.search);
var convertTileToScreen = (x, y) => ({x: x * SCALE, y: y * SCALE});
var getParameter = (key) => key ? params.get(key) : 0;
var hash = window.location.hash.split("?")[0].slice(1);
// src/js/canvas.js
var Canvas = class {
constructor(id = "c", w = 128, h = 128) {
this.canvas = document.getElementById(id);
this.canvas.width = w;
this.canvas.height = h;
this.ctx = this.canvas.getContext("2d");
this.ctx.imageSmoothingEnabled = false;
this.ctx.textBaseline = "top";
this.width = this.canvas.width;
this.height = this.canvas.height;
this.cX = 0;
this.cY = 0;
}
fill(c = "black") {
this.ctx.fillStyle = c;
this.ctx.fillRect(0, 0, this.width, this.height);
}
drawImage(image, x, y, width = image.width, height = image.height) {
this.ctx.drawImage(image, x - this.cX, y - this.cY, width, height);
}
sliceImage(img, x, y, w, h, cropX, cropY, cropW, cropH, direction = 0) {
this.ctx.save();
this.ctx.translate(x + w / 2 - this.cX, y + h / 2 - this.cY);
this.ctx.rotate(direction);
this.ctx.drawImage(img, cropX, cropY, cropW, cropH, -w / 2, -h / 2, w, h);
this.ctx.restore();
}
drawText(text2, x, y, c = "white", size = 16, font = "monospace") {
this.ctx.fillStyle = c;
this.ctx.font = `${size}px ${font}`;
this.ctx.fillText(text2, x, y);
}
drawLine(x1, y1, x2, y2, c = "white", w = 1) {
this.ctx.strokeStyle = c;
this.ctx.lineWidth = w;
this.ctx.beginPath();
this.ctx.moveTo(x1 - this.cX, y1 - this.cY);
this.ctx.lineTo(x2 - this.cX, y2 - this.cY);
this.ctx.stroke();
}
};
// src/js/text.js
var TextRenderer = class {
constructor(canvas2, fontimg) {
this.fontimg = fontimg;
this.fontWidth = 7;
this.fontHeight = 7;
this.fontChars = "abcdefghijklmnopqrstuvwxyz1234567890.,!?:;)(~>";
this.canvas = canvas2;
}
drawLetter(letter, x, y, substituteOK = 1) {
let {canvas: canvas2, fontWidth, fontHeight} = this;
let index = this.fontChars.indexOf(letter.toLowerCase());
if (index == -1) {
if (!substituteOK)