diff options
author | Justin Worthe <justin.worthe@gmail.com> | 2014-08-27 08:12:55 +0200 |
---|---|---|
committer | Justin Worthe <justin.worthe@gmail.com> | 2014-08-27 08:12:55 +0200 |
commit | 8d9e59e1d3addfcbeab2a00796e5e2da3ff0a608 (patch) | |
tree | 98ef0cf23fe11a1cf0609896cbf87fa1409d902f /game | |
parent | d188dc926f956a856f391889bfa135de08ba4027 (diff) |
Added visual indication of player ready to place poison pill
Diffstat (limited to 'game')
-rw-r--r-- | game/prefabs/player.js | 33 | ||||
-rw-r--r-- | game/states/play.js | 7 |
2 files changed, 33 insertions, 7 deletions
diff --git a/game/prefabs/player.js b/game/prefabs/player.js index e1cdc60..f0a6b65 100644 --- a/game/prefabs/player.js +++ b/game/prefabs/player.js @@ -6,6 +6,8 @@ var Player = function(game, x, y, key, frame, soundKey) { Phaser.Sprite.call(this, game, x, y, key, frame); this.animations.add('active', [0]); this.animations.add('waiting', [1]); + this.animations.add('activePoison', [2]); + this.animations.add('waitingPoison', [3]); this.baseKey = key; this.moving = false; @@ -15,7 +17,11 @@ var Player = function(game, x, y, key, frame, soundKey) { this.score = 0; this.maxScore = 1; this.isMyTurn = false; - this.animIsMyTurn = true; + + this.currentAnimation = { + isMyTurn: true, + poisonPillActive: false + } this.hasPoisonPill = true; this.poisonPillActive = false; @@ -42,9 +48,28 @@ Player.prototype = Object.create(Phaser.Sprite.prototype); Player.prototype.constructor = Player; Player.prototype.update = function() { - if (this.isMyTurn !== this.animIsMyTurn) { - this.animIsMyTurn = this.isMyTurn; - this.play(this.animIsMyTurn ? 'active' : 'waiting'); + if (this.isMyTurn !== this.currentAnimation.isMyTurn || this.poisonPillActive !== this.currentAnimation.poisonPillActive) { + this.currentAnimation.isMyTurn = this.isMyTurn; + this.currentAnimation.poisonPillActive = this.poisonPillActive; + + var animation; + if (!this.currentAnimation.isMyTurn) { + if (!this.currentAnimation.poisonPillActive) { + animation = 'waiting'; + } + else { + animation = 'waitingPoison' + } + } + else { + if (!this.currentAnimation.poisonPillActive) { + animation = 'active'; + } + else { + animation = 'activePoison' + } + } + this.play(animation); } }; diff --git a/game/states/play.js b/game/states/play.js index ec0ddae..15304d5 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -262,6 +262,9 @@ Play.prototype = { var newX = player.x + deltaX; var newY = player.y + deltaY; var placePoisonPill = player.hasPoisonPill && player.poisonPillActive; + if (this.checkMap(newX, newY) || !player.isMyTurn || player.moving) { + return; + } var posionPillX = player.x; var posionPillY = player.y; @@ -269,9 +272,7 @@ Play.prototype = { player.hasPoisonPill = false; } - if (this.checkMap(newX, newY) || !player.isMyTurn || player.moving) { - return; - } + var intermediateX = newX; var teleportX = newX; |