Skip to content

Added zooming via q/e keys for the demo and replays #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion environment/frontend_server/templates/demo/main_script.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
// will be used in it.
const game = new Phaser.Game(config);
let cursors;
let camera;
let player;

// Persona related variables. This should have the name of the persona as its
Expand All @@ -86,6 +87,11 @@
// <movement_speed> determines how fast we move at each upate cylce.
let movement_speed = {{play_speed}};


// Define min and max zoom levels
let minZoom = 0.25;
let maxZoom = 3;

// Variables for storing movements that are sent from the backend server.
let execute_count_max = tile_width/movement_speed;
let execute_count = execute_count_max;
Expand Down Expand Up @@ -255,11 +261,21 @@
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);
cursors = this.input.keyboard.createCursorKeys();

// Zooming
// Define keys for zooming in and out
zoomInKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q);
zoomOutKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.E);

// Set initial zoom level
camera.setZoom(1);



// *** SET UP PERSONAS ***
// We start by creating the game sprite objects.
for (let i=0; i<Object.keys(spawn_tile_loc).length; i++) {
Expand Down Expand Up @@ -367,6 +383,20 @@
player.body.setVelocityY(camera_speed);
}

// ** ZOOM CAMERA **

// Check for zoom in key press
if (zoomInKey.isDown) {
let newZoom = camera.zoom + 0.01;
camera.setZoom(Phaser.Math.Clamp(newZoom, minZoom, maxZoom));
}

// Check for zoom out key press
if (zoomOutKey.isDown) {
let newZoom = camera.zoom - 0.01;
camera.setZoom(Phaser.Math.Clamp(newZoom, minZoom, maxZoom));
}


let curr_focused_persona = document.getElementById("temp_focus").textContent;
if (curr_focused_persona != "") {
Expand Down
29 changes: 27 additions & 2 deletions environment/frontend_server/templates/home/main_script.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
// will be used in it.
const game = new Phaser.Game(config);
let cursors;
let camera;
let player;
let showDebug = false;

Expand Down Expand Up @@ -107,6 +108,10 @@
// <movement_speed> determines how fast we move at each upate cylce.
let movement_speed = 32;

// Define min and max zoom levels
let minZoom = 0.25;
let maxZoom = 3;

// <timer_max> determines how frequently our update function will query the
// frontend server. If it's higher, we wait longer cycles.
let timer_max = 0;
Expand Down Expand Up @@ -271,12 +276,19 @@
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);
cursors = this.input.keyboard.createCursorKeys();

// *** SET UP PERSONAS ***
// Zooming
// Define keys for zooming in and out
zoomInKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q);
zoomOutKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.E);

camera.setZoom(1)

// *** SET UP PERSONAS ***
// We start by creating the game sprite objects.
for (let i=0; i<Object.keys(spawn_tile_loc).length; i++) {
let persona_name = Object.keys(spawn_tile_loc)[i];
Expand Down Expand Up @@ -365,6 +377,19 @@
player.body.setVelocityY(camera_speed);
}

// ** ZOOM CAMERA **

// Check for zoom in key press
if (zoomInKey.isDown) {
let newZoom = camera.zoom + 0.01;
camera.setZoom(Phaser.Math.Clamp(newZoom, minZoom, maxZoom));
}

// Check for zoom out key press
if (zoomOutKey.isDown) {
let newZoom = camera.zoom - 0.01;
camera.setZoom(Phaser.Math.Clamp(newZoom, minZoom, maxZoom));
}
// console.log("phase: " + phase + ", step: " + step);
// *** MOVE PERSONAS ***
// Moving personas take place in three distinct phases: "process," "update,"
Expand Down