42 lines
891 B
JavaScript
42 lines
891 B
JavaScript
import { Texture } from "./texture.js";
|
|
|
|
/** @type {HTMLCanvasElement} */
|
|
const htmlCanvas = document.querySelector("#game");
|
|
const ctx = htmlCanvas.getContext("2d");
|
|
ctx.imageSmoothingEnabled = false;
|
|
|
|
export const width = htmlCanvas.width;
|
|
export const height = htmlCanvas.height;
|
|
|
|
/**
|
|
* Clear canvas with a color.
|
|
* @param {string} color
|
|
*/
|
|
export function clear(color) {
|
|
ctx.fillStyle = color;
|
|
ctx.fillRect(0, 0, width, height);
|
|
}
|
|
|
|
/**
|
|
* Draw a filled rectangle.
|
|
* @param {number} x
|
|
* @param {number} y
|
|
* @param {number} width
|
|
* @param {number} height
|
|
* @param {string} color
|
|
*/
|
|
export function fillRect(x, y, width, height, color) {
|
|
ctx.fillStyle = color;
|
|
ctx.fillRect(x, y, width, height);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {Texture} texture
|
|
* @param {number} x
|
|
* @param {number} y
|
|
*/
|
|
export function putTexture(texture, x, y) {
|
|
texture.draw(ctx, x, y);
|
|
}
|