Skip to content

Commit

Permalink
run mode added
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanous committed Dec 25, 2014
1 parent a6634b6 commit e20d58b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
32 changes: 31 additions & 1 deletion js/Classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ var PhaserMMORPG = PhaserMMORPG || {};

PhaserMMORPG.settings = {
player : {
walkSpeed : 150
walkSpeed : 150,
runSpeed : 300
},


keyboard : {
runKey : Phaser.Keyboard.SHIFT
}

};
Expand Down Expand Up @@ -101,6 +107,30 @@ PhaserMMORPG.Avatar.prototype.walkRight = function () {
this.update('right');
}

PhaserMMORPG.Avatar.prototype.runUp = function () {
this.player.body.velocity.y -= PhaserMMORPG.settings.player.runSpeed;
this.playAnimation('up', 20);
this.update('up');
}

PhaserMMORPG.Avatar.prototype.runDown = function () {
this.player.body.velocity.y += PhaserMMORPG.settings.player.runSpeed;
this.playAnimation('down', 20);
this.update('down');
}

PhaserMMORPG.Avatar.prototype.runLeft = function () {
this.player.body.velocity.x -= PhaserMMORPG.settings.player.runSpeed;
this.playAnimation('left', 20);
this.update('left');
}

PhaserMMORPG.Avatar.prototype.runRight = function () {
this.player.body.velocity.x += PhaserMMORPG.settings.player.runSpeed;
this.playAnimation('right', 20);
this.update('right');
}

PhaserMMORPG.Avatar.prototype.stopVelocity = function () {
this.player.body.velocity.y = 0;
this.player.body.velocity.x = 0;
Expand Down
25 changes: 11 additions & 14 deletions js/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ PhaserMMORPG.Game.prototype = {
//the camera will follow the player in the world
this.game.camera.follow(this.player.player);

//move player with cursor keys
//set up cursor keys
this.cursors = this.game.input.keyboard.createCursorKeys();
this.escapeKey = this.game.input.keyboard.addKey(Phaser.Keyboard.ESC);
this.cursors.runKey = this.game.input.keyboard.addKey(PhaserMMORPG.settings.keyboard.runKey);


//listen to key releases
this.game.input.keyboard.addCallbacks(null, null, this.onKeyUpCallback);
Expand Down Expand Up @@ -107,21 +108,17 @@ PhaserMMORPG.Game.prototype = {
this.player.stopVelocity();

if(this.cursors.up.isDown) {
this.player.walkUp();
}
else if(this.cursors.down.isDown) {
this.player.walkDown();
}
if(this.cursors.left.isDown) {
this.player.walkLeft();
this.cursors.runKey.isDown? this.player.runUp() : this.player.walkUp();
} else if (this.cursors.down.isDown) {
this.cursors.runKey.isDown? this.player.runDown() : this.player.walkDown();
}
else if(this.cursors.right.isDown) {
this.player.walkRight();

if (this.cursors.left.isDown) {
this.cursors.runKey.isDown? this.player.runLeft() : this.player.walkLeft();
} else if(this.cursors.right.isDown) {
this.cursors.runKey.isDown? this.player.runRight() : this.player.walkRight();
}

if (this.escapeKey.isDown) {
//this.state.start('MainMenu');
}

},

Expand Down

0 comments on commit e20d58b

Please sign in to comment.