From f58ea140ae6d6f0038e429ee47319ad3c9a74de1 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Thu, 22 May 2014 07:50:56 +0200 Subject: Added turn mechanic to game re #10 --- game/states/play.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'game/states/play.js') diff --git a/game/states/play.js b/game/states/play.js index 84237a6..96188e5 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -135,6 +135,8 @@ Play.prototype = { this.playerB = new Player(this.game, 6, 2, 'player-b', 0); this.players.add(this.playerA); this.players.add(this.playerB); + + this.updatePlayerTurn(0); }, addPlayerControls: function() { var playerAControls = { @@ -174,8 +176,9 @@ Play.prototype = { var newX = player.x + deltaX; var newY = player.y + deltaY; - if (!this.checkMap(newX, newY)) { + if (!this.checkMap(newX, newY) && player.isMyTurn) { player.move(newX, newY); + this.togglePlayerTurn(); } }, playerPillCollision: function(player, pill) { @@ -184,6 +187,16 @@ Play.prototype = { this.playerAScoreText.setText(this.playerA.score+''); this.playerBScoreText.setText(this.playerB.score+''); + }, + togglePlayerTurn: function() { + this.updatePlayerTurn((this.playerTurn+1)%this.players.length); + }, + updatePlayerTurn: function(newPlayerTurn) { + this.playerTurn = newPlayerTurn; + for (var i=0; i