Skip to content

Commit

Permalink
Controls fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kosinaz committed Nov 19, 2017
1 parent 59c69fe commit d27bb87
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ game.currentLevel = 0;
/**
* Store the last unlocked level.
*/
game.progress = 1;
game.progress = 1;
26 changes: 22 additions & 4 deletions src/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ var playState = {

create: function () {

/**
* Set controls.
*/
this.keyW = game.input.keyboard.addKey(Phaser.Keyboard.W);
this.keyS = game.input.keyboard.addKey(Phaser.Keyboard.S);
this.keyA = game.input.keyboard.addKey(Phaser.Keyboard.A);
this.keyD = game.input.keyboard.addKey(Phaser.Keyboard.D);
this.keyUp = game.input.keyboard.addKey(Phaser.Keyboard.UP);
this.keyDown = game.input.keyboard.addKey(Phaser.Keyboard.DOWN);
this.keyLeft = game.input.keyboard.addKey(Phaser.Keyboard.LEFT);
this.keyRight = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);

/**
* Load the map data.
*/
Expand Down Expand Up @@ -192,28 +204,30 @@ var playState = {
/**
* Set the movement buttons.
*/
if (game.input.keyboard.isDown(Phaser.KeyCode.UP)) {


if (this.keyW.isDown || this.keyUp.isDown) {

/**
* Set the move up button.
*/
game.player.move(0, -1, 54);

} else if (game.input.keyboard.isDown(Phaser.KeyCode.DOWN)) {
} else if (this.keyS.isDown || this.keyDown.isDown) {

/**
* Set the move down button.
*/
game.player.move(0, 1, 52);

} else if (game.input.keyboard.isDown(Phaser.KeyCode.LEFT)) {
} else if (this.keyA.isDown || this.keyLeft.isDown) {

/**
* Set the move left button.
*/
game.player.move(-1, 0, 55);

} else if (game.input.keyboard.isDown(Phaser.KeyCode.RIGHT)) {
} else if (this.keyD.isDown || this.keyRight.isDown) {

/**
* Set the move right button.
Expand Down Expand Up @@ -251,5 +265,9 @@ var playState = {
* Return to the menu.
*/
game.state.start('menu');
},

moveUp: function () {
game.player.move(0, -1, 54);
}
}

0 comments on commit d27bb87

Please sign in to comment.