Skip to content

Commit

Permalink
Camera: Don't associate zoom in/out with wasd_controls
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanGrieb committed Nov 20, 2023
1 parent 7a94451 commit a6fce89
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
8 changes: 6 additions & 2 deletions client/src/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,14 @@ export class Game {
this.currentScene.redraw();
}
this.canvasContext.fillStyle = options.canvasColor ?? "white";
this.canvasContext.fillRect(0, 0, this.canvas.width, this.canvas.height);
this.canvasContext.fillRect(
0,
0,
this.canvas.width,
this.canvas.height
);
this.canvasContext.font = "12px Times new Roman";
this.canvasContext.imageSmoothingEnabled = false;

}, 300);
});

Expand Down
39 changes: 18 additions & 21 deletions client/src/scene/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ export class Camera {
this.locked = false;

const scene = Game.getCurrentScene();
if (options.wasd_controls) {
scene.on("keydown", (options) => {
if (this.keysHeld.includes(options.key) || this.locked) {
return;
}
scene.on("keydown", (options) => {
if (this.keysHeld.includes(options.key) || this.locked) {
return;
}

if (this.wasdControls) {
this.keysHeld.push(options.key);

if (options.key == "a" || options.key == "A") {
console.log("a");
scene.getCamera().addVel(5, 0);
}
if (options.key == "d" || options.key == "D") {
Expand All @@ -73,25 +72,23 @@ export class Camera {
if (options.key == "s" || options.key == "S") {
scene.getCamera().addVel(0, -5);
}
if (options.key == "=") {
scene
.getCamera()
.zoom(Game.getWidth() / 2, Game.getHeight() / 2, 1.2);
}
if (options.key == "-") {
scene
.getCamera()
.zoom(Game.getWidth() / 2, Game.getHeight() / 2, 0.8);
}
});
}

if (options.key == "=") {
scene.getCamera().zoom(Game.getWidth() / 2, Game.getHeight() / 2, 1.2);
}
if (options.key == "-") {
scene.getCamera().zoom(Game.getWidth() / 2, Game.getHeight() / 2, 0.8);
}
});

scene.on("keyup", (options) => {
scene.on("keyup", (options) => {
if (this.wasdControls) {
this.keysHeld = this.keysHeld.filter(
(element) => element !== options.key
); // Remove key from held lits

if (options.key == "a" || options.key == "A") {
console.log("no a ");
scene.getCamera().addVel(-5, 0);
}
if (options.key == "d" || options.key == "D") {
Expand All @@ -104,8 +101,8 @@ export class Camera {
if (options.key == "s" || options.key == "S") {
scene.getCamera().addVel(0, 5);
}
});
}
}
});

if (options.mouse_controls) {
scene.on("mousedown", (options) => {
Expand Down
2 changes: 1 addition & 1 deletion client/src/scene/type/InGameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class InGameScene extends Scene {
this.players = [];
if (this.firstLoad) {
const camera = new Camera({
wasd_controls: false,
wasd_controls: true,
mouse_controls: true,
//initial_position: [1, 1],
});
Expand Down

0 comments on commit a6fce89

Please sign in to comment.