summaryrefslogtreecommitdiff
path: root/game/states
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/states
parent76c53168629511ec46124ed221044d210e4f87c6 (diff)
Fixed animation issue on players
Diffstat (limited to 'game/states')
-rw-r--r--game/states/play.js18
-rw-r--r--game/states/preload.js6
2 files changed, 15 insertions, 9 deletions
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');