summaryrefslogtreecommitdiff
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
parent507541065c5e39e2259c5a1f300491f3e388c426 (diff)
Added turn mechanic to game
re #10
-rw-r--r--game/prefabs/player.js3
-rw-r--r--game/states/boot.js2
-rw-r--r--game/states/play.js15
3 files changed, 17 insertions, 3 deletions
diff --git a/game/prefabs/player.js b/game/prefabs/player.js
index b520947..0f6cb18 100644
--- a/game/prefabs/player.js
+++ b/game/prefabs/player.js
@@ -10,6 +10,7 @@ var Player = function(game, x, y, key, frame) {
this.game.physics.arcade.enableBody(this);
this.score = 0;
+ this.isMyTurn = false;
};
Player.prototype = Object.create(Phaser.Sprite.prototype);
@@ -19,7 +20,7 @@ Player.prototype.update = function() {
};
Player.prototype.move = function(newX, newY) {
- if (this.moving) {
+ if (this.moving || !this.isMyTurn) {
return;
}
diff --git a/game/states/boot.js b/game/states/boot.js
index 91cbb25..80b7d4b 100644
--- a/game/states/boot.js
+++ b/game/states/boot.js
@@ -5,7 +5,7 @@ function Boot() {
Boot.prototype = {
preload: function() {
- this.load.image('preloader', 'assets/preloader.gif');
+ this.load.image('preloader', 'assets/images/preloader.gif');
},
create: function() {
this.game.input.maxPointers = 1;
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");
}
};