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/prefabs/player.js | 3 +++ game/prefabs/poisonPill.js | 18 ++++++++++++++++++ game/states/play.js | 40 ++++++++++++++++++++++++++++++++++++++-- game/states/preload.js | 1 + todo.md | 3 ++- 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 game/prefabs/poisonPill.js diff --git a/game/prefabs/player.js b/game/prefabs/player.js index a4d1b57..fb63707 100644 --- a/game/prefabs/player.js +++ b/game/prefabs/player.js @@ -17,6 +17,9 @@ var Player = function(game, x, y, key, frame, soundKey) { this.isMyTurn = false; this.animIsMyTurn = true; + this.hasPoisonPill = true; + this.poisonPillActive = false; + this.scoreSound = game.sound.add(soundKey); diff --git a/game/prefabs/poisonPill.js b/game/prefabs/poisonPill.js new file mode 100644 index 0000000..408f77f --- /dev/null +++ b/game/prefabs/poisonPill.js @@ -0,0 +1,18 @@ +'use strict'; + +var PoisonPill = function(game, x, y, frame) { + Phaser.Sprite.call(this, game, x, y, 'poison-pill', frame); + this.scale = {x: 0.01, y: 0.01}; + this.anchor = {x: 0.5, y: 0.5}; + + this.score = 1; +}; + +PoisonPill.prototype = Object.create(Phaser.Sprite.prototype); +PoisonPill.prototype.constructor = PoisonPill; + +PoisonPill.prototype.getBounds = function() { + return new Phaser.Rectangle(this.x, this.y, 0.2, 0.2); +}; + +module.exports = PoisonPill; 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