Skip to content

Commit

Permalink
fixed camera control
Browse files Browse the repository at this point in the history
  • Loading branch information
Chasmiccoder committed Feb 9, 2022
1 parent 1253104 commit 74f9bd7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
1 change: 0 additions & 1 deletion js/Overworld.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions js/OverworldMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions js/Sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions js/utils.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit 74f9bd7

Please sign in to comment.