more fun functions

This commit is contained in:
Chris Wanstrath 2025-09-28 19:20:06 -07:00
parent 09267bcd12
commit f5fb571823

View File

@ -6,7 +6,10 @@ export class GameContext {
width = 960 width = 960
height = 540 height = 540
clear() { clear(color?: string) {
if (color)
this.rectfill(0, 0, this.ctx.canvas.width, this.ctx.canvas.height, color)
else
this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height) this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height)
} }
@ -31,6 +34,27 @@ export class GameContext {
c.restore() c.restore()
} }
centerTextX(msg: string, y: number, color = "black", size = 16, font = "C64ProMono") {
const c = this.ctx
c.save()
c.fillStyle = color
c.font = `${size}px ${font}`
c.textBaseline = "middle"
c.textAlign = "center"
c.fillText(msg, this.width / 2, y)
c.restore()
}
centerTextY(msg: string, x: number, color = "black", size = 16, font = "C64ProMono") {
const c = this.ctx
c.save()
c.fillStyle = color
c.font = `${size}px ${font}`
c.textBaseline = "middle"
c.textAlign = "center"
c.fillText(msg, x, this.height / 2)
c.restore()
}
circ(x: number, y: number, r: number, color = "black") { circ(x: number, y: number, r: number, color = "black") {
const c = this.ctx const c = this.ctx