From 8c0a371916effa25ac77dc8a3420b95bd8b7a173 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 23 Aug 2014 12:18:34 +0200 Subject: Changed turn changing to only happen at the end of a players movement --- game/prefabs/player.js | 8 +++++++- game/states/play.js | 3 +-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/game/prefabs/player.js b/game/prefabs/player.js index 344793b..40fce38 100644 --- a/game/prefabs/player.js +++ b/game/prefabs/player.js @@ -46,13 +46,19 @@ Player.prototype.update = function() { } }; -Player.prototype.move = function(newX, newY) { +Player.prototype.move = function(newX, newY, callback, callbackContext) { this.moving = true; var tween = this.game.add.tween(this).to({x: newX, y: newY}, 500); tween.onComplete.add(this.finishMovement, this); + tween.onComplete.add(callback, callbackContext); tween.start(); }; +Player.prototype.teleport = function(newX, newY) { + this.x = newX; + this.y = newY; +} + Player.prototype.finishMovement = function() { this.moving = false; }; diff --git a/game/states/play.js b/game/states/play.js index 1b59596..7ffcc3d 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -210,8 +210,7 @@ Play.prototype = { var newY = player.y + deltaY; if (!this.checkMap(newX, newY) && player.isMyTurn && !player.moving) { - player.move(newX, newY); - this.togglePlayerTurn(); + player.move(newX, newY, this.togglePlayerTurn, this); } }, playerPillCollision: function(player, pill) { -- cgit v1.2.3