From a3a11ded6b2e1febf0416aaecfc393c7626ccdac Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Mon, 1 Sep 2014 07:46:58 +0200 Subject: Prevented player from moving into respawn area --- game/states/play.js | 70 +++++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 34 deletions(-) (limited to 'game/states/play.js') diff --git a/game/states/play.js b/game/states/play.js index 99d29a1..14d8335 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -9,28 +9,6 @@ var PoisonPill = require('../prefabs/poisonPill'); function Play() {} Play.prototype = { - addToMap: function(x, y) { - if (!this.map) { - this.map = []; - } - if (!this.map[x]) { - this.map[x] = []; - } - - this.map[x][y] = true; - }, - removeFromMap: function(x,y) { - if (!this.map || !this.map[x]) { - return; - } - this.map[x][y] = false; - }, - checkMap: function(x,y) { - if (!this.map || !this.map[x]) { - return false; - } - return this.map[x][y]; - }, preload: function() { }, create: function() { @@ -76,6 +54,29 @@ Play.prototype = { this.pollPlayerInput(); }, + addToMap: function(x, y) { + if (!this.map) { + this.map = []; + } + if (!this.map[x]) { + this.map[x] = []; + } + + this.map[x][y] = true; + }, + removeFromMap: function(x,y) { + if (!this.map || !this.map[x]) { + return; + } + this.map[x][y] = false; + }, + checkMap: function(x,y) { + if (!this.map || !this.map[x]) { + return false; + } + return this.map[x][y]; + }, + checkForPlayerPillCollisions: function() { var pillCollisions = []; this.players.forEach(function(player) { @@ -212,6 +213,9 @@ Play.prototype = { this.gameHeight = wall.y+1; } }, this); + this.respawnX = Math.ceil(this.gameWidth/2)-1; + this.respawnY = Math.ceil(this.gameHeight/2)-1; + this.updatePlayerTurn(0); }, @@ -272,14 +276,18 @@ Play.prototype = { return; } + if (Math.abs(newX-this.respawnX)<=1 && Math.abs(newY-this.respawnY)<=1 && ( + Math.abs(newX-this.respawnX)