Select Git revision
game.js 9.16 KiB
import { WIDTH, HEIGHT, GAME_TITLE, SCALE } from "./config.js";
import { Canvas } from "./canvas.js";
import { TextRenderer } from "./text.js";
import { Room, Object } from "./objects.js";
import { whichKeyDown } from "./keyboard.js";
import { convertTileToScreen, getParameter, hash } from "./utils.js";
let assets = {
images: {
splash: "../img/splash1.webp",
font: "../img/hampsterfont.webp",
tiles: "../img/t.webp",
selector: "../img/selector.webp",
},
spritesheets: {
player: [
{x: 0}, // looking up
{x: 16}, // looking right
{x: 32}, // looking down
{x: 48} // looking left
]
}
}
const tileTypes = {
1: 1, // floor
2: 2, // wall
}
let running = 1;
let currentFrame = 0;
let targetFrames = 60;
let lastFrameTime = performance.now();
let debug = getParameter("debug") || 0;
let rooms = [];
let debugStatuses = [];
let canvas = new Canvas("c", WIDTH, HEIGHT);
let text;
let pressedLastFrame = [];
canvas.fill("#222034");
let splash = new Image();
splash.src = assets.images.splash;
splash.onload = () => {
canvas.drawImage(splash, canvas.width / 2 - splash.width / 2, canvas.height / 2 - splash.height / 2);
let font = new Image();
font.src = assets.images.font;
font.onload = () => {
console.log("font loaded")
text = new TextRenderer(canvas, font);
window.onerror = (e) => {
running = 0;
text.throwPanic(e);
}
}
}
// Entity class is here becuase otherwise every entity would need the canvas passed into it
class Entity extends Object {
constructor(x=0, y=0, spritesheet=null, sprite=null) {
super();
this.x = x;
this.y = y;
this.sprite = sprite;