summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2014-07-19 11:58:25 +0200
committerJustin Worthe <justin.worthe@gmail.com>2014-07-19 11:58:25 +0200
commit10d101e5fee782f6370c93ac2e39ebc96054ea4b (patch)
tree4904a8da7aded89b3d588ac43c0d64d13dbd3f5b /game
parent76c53168629511ec46124ed221044d210e4f87c6 (diff)
Fixed animation issue on players
Diffstat (limited to 'game')
-rw-r--r--game/prefabs/player.js11
-rw-r--r--game/states/play.js18
-rw-r--r--game/states/preload.js6
3 files changed, 22 insertions, 13 deletions
diff --git a/game/prefabs/player.js b/game/prefabs/player.js
index 98179d9..95ea761 100644
--- a/game/prefabs/player.js
+++ b/game/prefabs/player.js
@@ -2,6 +2,9 @@
var Player = function(game, x, y, key, frame) {
Phaser.Sprite.call(this, game, x, y, key, frame);
+ this.animations.add('active', [0]);
+ this.animations.add('waiting', [1]);
+
this.baseKey = key;
this.moving = false;
this.scale = {x: 0.01, y: 0.01};
@@ -11,16 +14,16 @@ var Player = function(game, x, y, key, frame) {
this.score = 0;
this.isMyTurn = false;
+ this.animIsMyTurn = true;
};
Player.prototype = Object.create(Phaser.Sprite.prototype);
Player.prototype.constructor = Player;
Player.prototype.update = function() {
- var newKey = this.baseKey + (this.isMyTurn ? '' : '-dim');
- if (this.key !== newKey) {
- console.log('Setting sprite to ' + newKey);
- this.loadTexture(newKey);
+ if (this.isMyTurn !== this.animIsMyTurn) {
+ this.animIsMyTurn = this.isMyTurn;
+ this.play(this.animIsMyTurn ? 'active' : 'waiting');
}
};
diff --git a/game/states/play.js b/game/states/play.js
index aed4f90..1d13e0b 100644
--- a/game/states/play.js
+++ b/game/states/play.js
@@ -71,9 +71,9 @@ Play.prototype = {
}
},
readLevelFile: function() {
- this.walls = this.game.add.group();
this.pills = this.game.add.group();
this.players = this.game.add.group();
+ this.walls = this.game.add.group();
var levelText = this.game.cache.getText('level');
var splitRows = levelText.split('\n');
@@ -139,15 +139,23 @@ Play.prototype = {
this.game.input.keyboard.addKey(this.playerAControls.down).onDown.add(this.movePlayer.bind(this, this.playerA, 0, 1), this);
this.game.input.keyboard.addKey(this.playerAControls.left).onDown.add(this.movePlayer.bind(this, this.playerA, -1, 0), this);
this.game.input.keyboard.addKey(this.playerAControls.right).onDown.add(this.movePlayer.bind(this, this.playerA, 1, 0), this);
- padA.getButton(Phaser.Gamepad.XBOX360_DPAD_UP).onDown.add(this.movePlayer.bind(this, this.playerA, 0, -1), this);
- padA.getButton(Phaser.Gamepad.XBOX360_DPAD_DOWN).onDown.add(this.movePlayer.bind(this, this.playerA, 0, 1), this);
- padA.getButton(Phaser.Gamepad.XBOX360_DPAD_LEFT).onDown.add(this.movePlayer.bind(this, this.playerA, -1, 0), this);
- padA.getButton(Phaser.Gamepad.XBOX360_DPAD_RIGHT).onDown.add(this.movePlayer.bind(this, this.playerA, 1, 0), this);
+ if (padA.connected) {
+ padA.getButton(Phaser.Gamepad.XBOX360_DPAD_UP).onDown.add(this.movePlayer.bind(this, this.playerA, 0, -1), this);
+ padA.getButton(Phaser.Gamepad.XBOX360_DPAD_DOWN).onDown.add(this.movePlayer.bind(this, this.playerA, 0, 1), this);
+ padA.getButton(Phaser.Gamepad.XBOX360_DPAD_LEFT).onDown.add(this.movePlayer.bind(this, this.playerA, -1, 0), this);
+ padA.getButton(Phaser.Gamepad.XBOX360_DPAD_RIGHT).onDown.add(this.movePlayer.bind(this, this.playerA, 1, 0), this);
+ }
this.game.input.keyboard.addKey(this.playerBControls.up).onDown.add(this.movePlayer.bind(this, this.playerB, 0, -1), this);
this.game.input.keyboard.addKey(this.playerBControls.down).onDown.add(this.movePlayer.bind(this, this.playerB, 0, 1), this);
this.game.input.keyboard.addKey(this.playerBControls.left).onDown.add(this.movePlayer.bind(this, this.playerB, -1, 0), this);
this.game.input.keyboard.addKey(this.playerBControls.right).onDown.add(this.movePlayer.bind(this, this.playerB, 1, 0), this);
+ if (padB.connected) {
+ padB.getButton(Phaser.Gamepad.XBOX360_DPAD_UP).onDown.add(this.movePlayer.bind(this, this.playerB, 0, -1), this);
+ padB.getButton(Phaser.Gamepad.XBOX360_DPAD_DOWN).onDown.add(this.movePlayer.bind(this, this.playerB, 0, 1), this);
+ padB.getButton(Phaser.Gamepad.XBOX360_DPAD_LEFT).onDown.add(this.movePlayer.bind(this, this.playerB, -1, 0), this);
+ padB.getButton(Phaser.Gamepad.XBOX360_DPAD_RIGHT).onDown.add(this.movePlayer.bind(this, this.playerB, 1, 0), this);
+ }
},
movePlayer: function(player, deltaX, deltaY) {
var newX = player.x + deltaX;
diff --git a/game/states/preload.js b/game/states/preload.js
index 7d9b9d3..2ffc179 100644
--- a/game/states/preload.js
+++ b/game/states/preload.js
@@ -13,10 +13,8 @@ Preload.prototype = {
this.load.onLoadComplete.addOnce(this.onLoadComplete, this);
this.load.setPreloadSprite(this.asset);
this.load.image('wall', 'assets/images/wall.svg');
- this.load.image('player-a', 'assets/images/player-a.svg');
- this.load.image('player-a-dim', 'assets/images/player-a-dim.svg');
- this.load.image('player-b', 'assets/images/player-b.svg');
- this.load.image('player-b-dim', 'assets/images/player-b-dim.svg');
+ this.load.spritesheet('player-a', 'assets/images/player-a-spritesheet.svg', 100, 100);
+ this.load.spritesheet('player-b', 'assets/images/player-b-spritesheet.svg', 100, 100);
this.load.image('pill', 'assets/images/pill.svg');
this.load.image('bonus-pill', 'assets/images/bonus-pill.svg');