From 7707c49924962ebce6bb9cf1b614328c98af0f40 Mon Sep 17 00:00:00 2001 From: Hadrien Date: Mon, 20 May 2024 16:40:35 +0200 Subject: [PATCH] add zoom on W and X --- .../templates/home/main_script.html | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/environment/frontend_server/templates/home/main_script.html b/environment/frontend_server/templates/home/main_script.html index 19c1dcf9f0..fe0cdbc760 100644 --- a/environment/frontend_server/templates/home/main_script.html +++ b/environment/frontend_server/templates/home/main_script.html @@ -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 @@ -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 *** @@ -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) { @@ -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 ***