From 76c53168629511ec46124ed221044d210e4f87c6 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Fri, 18 Jul 2014 17:34:53 +0200 Subject: Started adding gamepad support --- game/states/play.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'game/states/play.js') diff --git a/game/states/play.js b/game/states/play.js index ca259b4..aed4f90 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -33,6 +33,7 @@ Play.prototype = { preload: function() { }, create: function() { + this.game.input.gamepad.start(); this.readLevelFile(); this.world.scale = {x:50, y:50}; @@ -121,6 +122,9 @@ Play.prototype = { right: Phaser.Keyboard.RIGHT }; + var padA = this.game.input.gamepad.pad1; + var padB = this.game.input.gamepad.pad2; + function addKeyCaptures(controls, keyboard) { for (var index in controls) { if (controls.hasOwnProperty(index)) { @@ -135,6 +139,10 @@ 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); 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); -- cgit v1.2.3