Skip to content

Commit

Permalink
add zoom on W and X
Browse files Browse the repository at this point in the history
  • Loading branch information
ketsapiwiq committed May 20, 2024
1 parent 3121ec6 commit 7707c49
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion environment/frontend_server/templates/home/main_script.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@
// will be used in it.
const game = new Phaser.Game(config);
let cursors;
let camera;
let player;
let plus;
let minus;
let showDebug = false;

// Persona related variables. This should have the name of the persona as its
Expand Down Expand Up @@ -271,9 +274,11 @@
setOffset(0, 0);
player.setDepth(-1);
// Setting up the camera.
const camera = this.cameras.main;
camera = this.cameras.main;
camera.startFollow(player);
camera.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
plus = this.input.keyboard.addKey("W");
minus = this.input.keyboard.addKey("X");
cursors = this.input.keyboard.createCursorKeys();

// *** SET UP PERSONAS ***
Expand Down Expand Up @@ -350,6 +355,8 @@
// function. We set the movement speed of the camera and wire up the keys to
// map to the actual movement.
const camera_speed = 400;
const camera_zoom_speed = 0.1;
const camera_zoom_min = 0.2;
// Stop any previous movement from the last frame
player.body.setVelocity(0);
if (cursors.left.isDown) {
Expand All @@ -364,6 +371,14 @@
if (cursors.down.isDown) {
player.body.setVelocityY(camera_speed);
}
if (plus.isDown) {
camera.setZoom(camera.zoom + camera_zoom_speed);
}
if (minus.isDown) {
if (camera.zoom > camera_zoom_min){
camera.setZoom(camera.zoom - camera_zoom_speed);
}
}

// console.log("phase: " + phase + ", step: " + step);
// *** MOVE PERSONAS ***
Expand Down

0 comments on commit 7707c49

Please sign in to comment.