summaryrefslogtreecommitdiff
path: root/game/states/play.js
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@entelect.co.za>2014-05-22 07:50:56 +0200
committerJustin Worthe <justin.worthe@entelect.co.za>2014-05-23 14:13:47 +0200
commitf58ea140ae6d6f0038e429ee47319ad3c9a74de1 (patch)
tree774f3a2c5f2c0cee5437bfb555c6476d7af23e6e /game/states/play.js
parent507541065c5e39e2259c5a1f300491f3e388c426 (diff)
Added turn mechanic to game
re #10
Diffstat (limited to 'game/states/play.js')
-rw-r--r--game/states/play.js15
1 files changed, 14 insertions, 1 deletions
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<this.players.children.length; ++i) {
+ this.players.children[i].isMyTurn = (i === this.playerTurn);
+ }
+ console.log("Player " + this.playerTurn + "'s turn");
}
};