From e74950e005d89fe2fd8453a78d84f26e4e93dada Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 23 Aug 2014 14:11:38 +0200 Subject: Removed relying on arcade physics for overlap detection, added player respawn --- game/states/play.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'game/states/play.js') diff --git a/game/states/play.js b/game/states/play.js index 7ffcc3d..882882c 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -41,15 +41,17 @@ Play.prototype = { this.setupPlayerControls(); - this.game.physics.startSystem(Phaser.Physics.ARCADE); - this.playerAScoreText = this.game.add.bitmapText(-0.1, -0.4, 'spaced-scorefont-a','0',2); this.playerBScoreText = this.game.add.bitmapText(this.world.width/this.world.scale.x - 4.5, -0.4, 'spaced-scorefont-b','0',2); this.gameWon = false; }, update: function() { - this.game.physics.arcade.overlap(this.players, this.pills, this.playerPillCollision, null, this); + this.checkForPlayerPillCollisions(); + + if (Phaser.Rectangle.intersects(this.playerA.getBounds(), this.playerB.getBounds())) { + this.playerPlayerCollision(this.playerA, this.playerB); + } if (!this.gameWon && this.pills.total === 0) { this.gameWon = true; @@ -72,6 +74,21 @@ Play.prototype = { this.pollPlayerInput(); }, + checkForPlayerPillCollisions: function() { + var pillCollisions = []; + this.players.forEach(function(player) { + var playerBounds = player.getBounds(); + this.pills.forEach(function(pill) { + var pillBounds = pill.getBounds(); + if (Phaser.Rectangle.intersects(playerBounds, pillBounds)) { + pillCollisions.push({player:player, pill:pill}); + } + }, this); + }, this); + for (var i=0; i