reenabled diagonal movement

This commit is contained in:
kharhamel 2020-04-30 19:36:28 +02:00
parent 62d2498e34
commit dd0744387f
3 changed files with 20 additions and 25 deletions

View File

@ -1,4 +1,4 @@
const DEBUG_MODE: boolean = !!process.env.DEBUG_MODE || false; const DEBUG_MODE: boolean = process.env.DEBUG_MODE as any === true;
const API_URL = process.env.API_URL || "http://api.workadventure.localhost"; const API_URL = process.env.API_URL || "http://api.workadventure.localhost";
const ROOM = [process.env.ROOM || "THECODINGMACHINE"]; const ROOM = [process.env.ROOM || "THECODINGMACHINE"];
const RESOLUTION = 4; const RESOLUTION = 4;

View File

@ -22,18 +22,15 @@ export class PlayableCaracter extends Phaser.Physics.Arcade.Sprite {
this.setVelocity(x, y); this.setVelocity(x, y);
//todo improve animations to better account for diagonal movement //up or down animationss are prioritized over left and right
if (this.body.velocity.x > 0) { //moving right
this.play(PlayerAnimationNames.WalkRight, true);
}
if (this.body.velocity.x < 0) { //moving left
this.anims.playReverse(PlayerAnimationNames.WalkLeft, true);
}
if (this.body.velocity.y < 0) { //moving up if (this.body.velocity.y < 0) { //moving up
this.play(PlayerAnimationNames.WalkUp, true); this.play(PlayerAnimationNames.WalkUp, true);
} } else if (this.body.velocity.y > 0) { //moving down
if (this.body.velocity.y > 0) { //moving down
this.play(PlayerAnimationNames.WalkDown, true); this.play(PlayerAnimationNames.WalkDown, true);
} else if (this.body.velocity.x > 0) { //moving right
this.play(PlayerAnimationNames.WalkRight, true);
} else if (this.body.velocity.x < 0) { //moving left
this.anims.playReverse(PlayerAnimationNames.WalkLeft, true);
} }
if(this.bubble) { if(this.bubble) {

View File

@ -66,27 +66,25 @@ export class Player extends PlayableCaracter implements CurrentGamerInterface, G
let speedMultiplier = activeEvents.get(UserInputEvent.SpeedUp) ? 25 : 9; let speedMultiplier = activeEvents.get(UserInputEvent.SpeedUp) ? 25 : 9;
let moveAmount = speedMultiplier * delta; let moveAmount = speedMultiplier * delta;
let x = 0;
let y = 0;
if (activeEvents.get(UserInputEvent.MoveUp)) { if (activeEvents.get(UserInputEvent.MoveUp)) {
this.move(0, -moveAmount); y = - moveAmount;
haveMove = true;
direction = PlayerAnimationNames.WalkUp; direction = PlayerAnimationNames.WalkUp;
} } else if (activeEvents.get(UserInputEvent.MoveDown)) {
if (activeEvents.get(UserInputEvent.MoveLeft)) { y = moveAmount;
this.move(-moveAmount, 0);
haveMove = true;
direction = PlayerAnimationNames.WalkLeft;
}
if (activeEvents.get(UserInputEvent.MoveDown)) {
this.move(0, moveAmount);
haveMove = true;
direction = PlayerAnimationNames.WalkDown; direction = PlayerAnimationNames.WalkDown;
} }
if (activeEvents.get(UserInputEvent.MoveRight)) { if (activeEvents.get(UserInputEvent.MoveLeft)) {
this.move(moveAmount, 0); x = -moveAmount;
haveMove = true; direction = PlayerAnimationNames.WalkLeft;
} else if (activeEvents.get(UserInputEvent.MoveRight)) {
x = moveAmount;
direction = PlayerAnimationNames.WalkRight; direction = PlayerAnimationNames.WalkRight;
} }
if (!haveMove) { if (x !== 0 || y !== 0) {
this.move(x, y);
} else {
direction = PlayerAnimationNames.None; direction = PlayerAnimationNames.None;
this.stop(); this.stop();
} }