diff --git a/index.html b/index.html index 480ffeb..40b8c64 100644 --- a/index.html +++ b/index.html @@ -21,7 +21,9 @@ - +
diff --git a/main.js b/main.js index 28acb61..2f09295 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,6 @@ +const SNES_WIDTH = 256; +const SNES_HEIGHT = 224; + const Orientation = { UP: 'up', DOWN: 'down', @@ -309,9 +312,10 @@ class Resources { } class Player { + // TODO: stop hard-coding player bounding box. constructor() { - this.x = (256 - 26) / 2; - this.y = (224 - 36) / 2; + this.x = (SNES_WIDTH - 26) / 2; + this.y = (SNES_HEIGHT - 36) / 2; this.orientation = Orientation.DOWN; } @@ -326,8 +330,8 @@ class Player { moveRight() { this.orientation = Orientation.RIGHT; this.x += 2; - if (this.x > 256 - 21) { - this.x = 256 - 21; + if (this.x > SNES_WIDTH - 21) { + this.x = SNES_WIDTH - 21; } } @@ -342,8 +346,8 @@ class Player { moveDown() { this.orientation = Orientation.DOWN; this.y += 2; - if (this.y > 224 - 36) { - this.y = 224 - 36; + if (this.y > SNES_HEIGHT - 36) { + this.y = SNES_HEIGHT - 36; } } } @@ -479,20 +483,16 @@ function loop(world, gfx) { } function setCanvasScale(scale) { - const snesWidth = 256; - const snesHeight = 224; const canvas = document.getElementById('canvas'); - canvas.style.width = '' + snesWidth * scale + 'px'; - canvas.style.height = '' + snesHeight * scale + 'px'; - debug('set scale to ' + scale + 'x'); + canvas.style.width = '' + SNES_WIDTH * scale + 'px'; + canvas.style.height = '' + SNES_HEIGHT * scale + 'px'; canvas.style.display = ''; + debug('set scale to ' + scale + 'x'); } function setAutoCanvasScale() { - const snesWidth = 256; - const snesHeight = 224; - const widthAspect = Math.floor(window.innerWidth / snesWidth); - const heightAspect = Math.floor(window.innerHeight / snesHeight); + const widthAspect = Math.floor(window.innerWidth / SNES_WIDTH); + const heightAspect = Math.floor(window.innerHeight / SNES_HEIGHT); const scale = Math.min(widthAspect, heightAspect) setCanvasScale(scale); }