Skip to content

Commit

Permalink
Fixed character offset and dynamic wall generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Chasmiccoder committed Feb 9, 2022
1 parent 810ec96 commit b1e9238
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion js/KeyPressListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ class KeyPressListener {
document.removeEventListener("keydown", this.keydownFunction);
document.removeEventListener("keyup", this.keyupFunction);
}
}
}
11 changes: 8 additions & 3 deletions js/Overworld.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ class Overworld {
constructor(config) {
this.element = config.element;
this.canvas = this.element.querySelector(".game-canvas");
this.canvas.height = window.innerHeight;
this.canvas.width = window.innerWidth;
// this.canvas.height = window.innerHeight;
// this.canvas.width = window.innerWidth;

// this.canvas.height = 1000; // TODO: Change this!
// this.canvas.width = 1500;

console.log(this.canvas.height, this.canvas.width);

this.context = this.canvas.getContext("2d");
this.map = null;
}

init() {
this.startMap(window.OverworldMaps.DemoRoom);


this.bindActionInput();
this.bindHeroPositionCheck();

Expand Down
8 changes: 4 additions & 4 deletions js/OverworldMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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.5) - cameraPerson.x, utils.withGrid(6) - cameraPerson.y);
context.drawImage(this.lowerImage, utils.withGrid(10.15) - cameraPerson.x, utils.withGrid(6.5) - cameraPerson.y); // fixing offset
}

drawUpperImage(context, cameraPerson) {
Expand Down Expand Up @@ -109,16 +109,16 @@ class OverworldMap {

window.OverworldMaps = {
DemoRoom: {
lowerSrc: "./images/official_assets/our_map_official.svg", // current best map is=
lowerSrc: "./images/official_assets/ourMap32.png", // current best map is=
// lowerSrc: "./images/ourMap16.png",
// lowerSrc: "./images/DemoLower.png",
upperSrc: "./images/DemoUpper.png",
gameObjects: {
hero: new Person({
isPlayerControlled: true,
src: "./images/brownGuy1.png",
x: utils.withGrid(20),
y: utils.withGrid(20)
x: utils.withGrid(30),
y: utils.withGrid(45)
}),

// myDrone: new Person({
Expand Down
8 changes: 4 additions & 4 deletions js/Person.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Person extends GameObject {
this.isPlayerControlled = config.isPlayerControlled || false;

this.directionUpdate = { // to alter speed, changed 1 to 2 here and (*)
"up": ["y", -1],
"down": ["y", 1],
"left": ["x", -1],
"right": ["x", 1]
"up": ["y", -2],
"down": ["y", 2],
"left": ["x", -2],
"right": ["x", 2]
}
}

Expand Down
3 changes: 2 additions & 1 deletion js/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const utils = {
withGrid(n) {
return n * 16;
// return n*16;
},

asGridCoord(x, y) {
Expand All @@ -10,7 +11,7 @@ const utils = {
nextPosition(initialX, initialY, direction) {
let x = initialX;
let y = initialY;
const size = 16;
const size = 32;
if(direction == "left") {
x -= size;
} else if(direction == "right") {
Expand Down
18 changes: 11 additions & 7 deletions styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ body {
overflow: hidden;
}

.game-container{
.game-container{
position: relative;
/* width: 352px; */
/* height: 198px; */
margin: 0 auto;
width: 352px;
height: 198px;
/* height: 550px; */
/* height: 100vh; */
/* width: 100vw; */
/* margin: 0 auto; */
margin: 0;
outline: 1px solid white;

/* transform: scale(3) translateY(50%); */
transform: scale(1.5) translateY(0%);
/* transform: scale(1) translate(50%); */
transform: scale(3) translateY(50%);
transform: scale(1.50) translateY(50%) translateX(90%);
/* transform: scale(1) translateY(30%) translateX(50%); */
/* transform:translateY(20%); */
}

Expand Down

0 comments on commit b1e9238

Please sign in to comment.