From 74f9bd77dbf63f06f860f5332f655b7404b0221b Mon Sep 17 00:00:00 2001 From: chasmiccoder Date: Wed, 9 Feb 2022 22:52:16 +0530 Subject: [PATCH] fixed camera control --- js/Overworld.js | 1 - js/OverworldMap.js | 9 +++++---- js/Sprite.js | 4 ++-- js/utils.js | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/js/Overworld.js b/js/Overworld.js index 772ad80..1b7f045 100644 --- a/js/Overworld.js +++ b/js/Overworld.js @@ -5,7 +5,6 @@ class Overworld { this.canvas.height = window.innerHeight; this.canvas.width = window.innerWidth; - // this.gameContainer = this.element.querySelector(".game-container"); // this.gameContainer.style.width = window.innerWidth; // this.gameContainer.style.height = window.innerHeight; diff --git a/js/OverworldMap.js b/js/OverworldMap.js index 5184dd0..7462948 100644 --- a/js/OverworldMap.js +++ b/js/OverworldMap.js @@ -20,11 +20,12 @@ class OverworldMap { drawLowerImage(context, cameraPerson) { // context.drawImage(this.lowerImage, utils.withGrid(10.5) - cameraPerson.x, utils.withGrid(6) - cameraPerson.y); - context.drawImage(this.lowerImage, utils.withGrid(10.33) - cameraPerson.x, utils.withGrid(6.5) - cameraPerson.y); // fixing offset + // context.drawImage(this.lowerImage, utils.withGrid(10.33) - cameraPerson.x, utils.withGrid(6.5) - cameraPerson.y); // fixing offset + context.drawImage(this.lowerImage, utils.withGrid(10.40) - cameraPerson.x, utils.withGrid(6.7) - cameraPerson.y); } drawUpperImage(context, cameraPerson) { - context.drawImage(this.upperImage, utils.withGrid(10.5) - cameraPerson.x, utils.withGrid(6) - cameraPerson.y); + context.drawImage(this.upperImage, utils.withGrid(10.40) - cameraPerson.x, utils.withGrid(6.7) - cameraPerson.y); } isSpaceTaken(currentX, currentY, direction) { @@ -117,8 +118,8 @@ window.OverworldMaps = { hero: new Person({ isPlayerControlled: true, src: "./images/brownGuy1.png", - x: utils.withGrid(30), - y: utils.withGrid(45) + x: utils.withGrid(18), + y: utils.withGrid(25) }), // myDrone: new Person({ diff --git a/js/Sprite.js b/js/Sprite.js index 6e58b32..2889e80 100644 --- a/js/Sprite.js +++ b/js/Sprite.js @@ -73,8 +73,8 @@ class Sprite { } draw(context, cameraPerson) { - const x = this.gameObject.x - 8 + utils.withGrid(10.5) - cameraPerson.x; - const y = this.gameObject.y - 18 + utils.withGrid(6) - cameraPerson.y; + const x = this.gameObject.x - 8 + utils.withGrid(10.5) - cameraPerson.x + utils.withGrid(9); + const y = this.gameObject.y - 18 + utils.withGrid(6) - cameraPerson.y + utils.withGrid(3); this.isShadowLoaded && context.drawImage(this.shadow, x, y); diff --git a/js/utils.js b/js/utils.js index 70197eb..6561408 100644 --- a/js/utils.js +++ b/js/utils.js @@ -1,11 +1,11 @@ const utils = { withGrid(n) { - return n * 16; + return n * 32; // return n*16; }, asGridCoord(x, y) { - return `${x*16},${y*16}`; + return `${x*32},${y*32}`; }, nextPosition(initialX, initialY, direction) {