From 25adfc618e77db9a5ee3b98ce0dab0be832efed0 Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Tue, 24 Dec 2024 17:58:20 +0100 Subject: hello kitty base done --- src/engine/screen.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/engine/screen.js') diff --git a/src/engine/screen.js b/src/engine/screen.js index 2d32b62..173e285 100644 --- a/src/engine/screen.js +++ b/src/engine/screen.js @@ -20,12 +20,14 @@ export class Screen { this.div = document.createElement("div") this.div.id = "screen" this.div.style.backgroundColor = "black" + this.div.style.zIndex = -11 /* create background image */ this.background = document.createElement("img") this.background.className = "background" this.background.src = `${BACKGROUND.DEFAULT}` this.background.style.visibility = "hidden" + this.background.style.zIndex = -10 this.div.appendChild(this.background) /* create relative div to append children */ @@ -77,11 +79,20 @@ export class Screen { draw(span, position, size, /* rotation = 0 */) { span.style.width = `${size.x * this.scale}px` span.style.height = `${size.y * this.scale}px` - span.style.top = `${(position.y - size.x / 2) * this.scale}px` - span.style.left = `${(position.x - size.y / 2) * this.scale}px` + span.style.top = `${(position.y - size.y / 2) * this.scale}px` + span.style.left = `${(position.x - size.x / 2) * this.scale}px` } setBackground(img) { this.background.src = img } showBackground() { this.background.visibility = "visible" } hideBackground() { this.background.visibility = "hidden" } + + isOffLimits(position, size) { + return ( + position.x + size.x < 0 || + position.y + size.y < 0 || + position.x - size.x > this.viewport.x || + position.y - size.y > this.viewport.y + ) + } } -- cgit v1.2.3