From 717e98c4159e9abd2165c490241a7d7b2caf1626 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sun, 24 Aug 2014 10:22:26 +0200 Subject: Added required state for poison pills --- game/states/play.js | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'game/states/play.js') diff --git a/game/states/play.js b/game/states/play.js index b79ea32..5461c1b 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -4,6 +4,7 @@ var Player = require('../prefabs/player'); var Pill = require('../prefabs/pill'); var BonusPill = require('../prefabs/bonusPill'); var Wall = require('../prefabs/wall'); +var PoisonPill = require('../prefabs/poisonPill'); function Play() {} @@ -48,6 +49,7 @@ Play.prototype = { }, update: function() { this.checkForPlayerPillCollisions(); + this.checkForPlayerPoisonPillCollisions(); if (Phaser.Rectangle.intersects(this.playerA.getBounds(), this.playerB.getBounds())) { this.playerPlayerCollision(this.playerA, this.playerB); @@ -89,6 +91,21 @@ Play.prototype = { this.playerPillCollision(pillCollisions[i].player, pillCollisions[i].pill); } }, + checkForPlayerPoisonPillCollisions: function() { + var pillCollisions = []; + this.players.forEach(function(player) { + var playerBounds = player.getBounds(); + this.poisonPills.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