Skip to content
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

Fixes #29: Add WASD and shift-speed-boost to the camera controls. #31

Open
wants to merge 1 commit 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
24 changes: 13 additions & 11 deletions environment/frontend_server/templates/demo/main_script.html
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,19 @@
const camera_speed = 400;
// Stop any previous movement from the last frame
player.body.setVelocity(0);
if (cursors.left.isDown) {
player.body.setVelocityX(-camera_speed);
}
if (cursors.right.isDown) {
player.body.setVelocityX(camera_speed);
}
if (cursors.up.isDown) {
player.body.setVelocityY(-camera_speed);
}
if (cursors.down.isDown) {
player.body.setVelocityY(camera_speed);
const speed_boost = cursors.shift.isDown ? 2 : 1;

if (cursors.left.isDown || keys.left.isDown) {
player.body.setVelocityX(-camera_speed * speed_boost);
}
if (cursors.right.isDown || keys.right.isDown) {
player.body.setVelocityX(camera_speed * speed_boost);
}
if (cursors.up.isDown || keys.up.isDown) {
player.body.setVelocityY(-camera_speed * speed_boost);
}
if (cursors.down.isDown || keys.down.isDown) {
player.body.setVelocityY(camera_speed * speed_boost);
}


Expand Down
25 changes: 14 additions & 11 deletions environment/frontend_server/templates/home/main_script.html
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
camera.startFollow(player);
camera.setBounds(0, 0, map.widthInPixels, map.heightInPixels);
cursors = this.input.keyboard.createCursorKeys();
keys = this.input.keyboard.addKeys({up:'W',left: 'A', down: 'S', right: 'D'});

// *** SET UP PERSONAS ***
// We start by creating the game sprite objects.
Expand Down Expand Up @@ -352,17 +353,19 @@
const camera_speed = 400;
// Stop any previous movement from the last frame
player.body.setVelocity(0);
if (cursors.left.isDown) {
player.body.setVelocityX(-camera_speed);
}
if (cursors.right.isDown) {
player.body.setVelocityX(camera_speed);
}
if (cursors.up.isDown) {
player.body.setVelocityY(-camera_speed);
}
if (cursors.down.isDown) {
player.body.setVelocityY(camera_speed);
const speed_boost = cursors.shift.isDown ? 2 : 1;

if (cursors.left.isDown || keys.left.isDown) {
player.body.setVelocityX(-camera_speed * speed_boost);
}
if (cursors.right.isDown || keys.right.isDown) {
player.body.setVelocityX(camera_speed * speed_boost);
}
if (cursors.up.isDown || keys.up.isDown) {
player.body.setVelocityY(-camera_speed * speed_boost);
}
if (cursors.down.isDown || keys.down.isDown) {
player.body.setVelocityY(camera_speed * speed_boost);
}

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