'use strict'; var Player = require('../prefabs/player'); var Pill = require('../prefabs/pill'); var BonusPill = require('../prefabs/bonusPill'); var Wall = require('../prefabs/wall'); 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() { this.readLevelFile(); this.world.scale = {x:50, y:50}; this.world.bounds = {x: -25, y:-25, width: this.game.width, height: this.game.height}; this.world.camera.setBoundsToWorld(); this.addPlayerControls(); this.game.physics.startSystem(Phaser.Physics.ARCADE); this.playerAScoreText = this.game.add.bitmapText(-0.1, -0.4, 'spaced-scorefont','0',1); this.playerBScoreText = this.game.add.bitmapText(this.world.width/this.world.scale.x - 2.1, -0.4, 'spaced-scorefont','0',1); this.gameWon = false; }, update: function() { this.game.physics.arcade.overlap(this.players, this.pills, this.playerPillCollision, null, this); if (!this.gameWon && this.pills.total === 0) { this.gameWon = true; if (this.playerA.score > this.playerB.score) { this.setVictoryText("PLAYER A WINS"); } else if (this.playerA.score < this.playerB.score) { this.setVictoryText("PLAYER B WINS"); } else { this.setVictoryText("DRAW"); } var self = this; setTimeout(function() { self.game.state.start('play'); }, 5000); } this.pollAnalogSticks() }, pollAnalogSticks: function() { if (this.game.input.gamepad.pad1.connected) { this.pollAnalogStickForPlayer(this.game.input.gamepad.pad1, this.playerA); } if (this.game.input.gamepad.pad2.connected) { this.pollAnalogStickForPlayer(this.game.input.gamepad.pad2, this.playerB); } }, pollAnalogStickForPlayer: function(pad, player) { if (pad.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X) < -0.2) { this.movePlayer(player, -1, 0); } if (pad.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X) > 0.2) { this.movePlayer(player, 1, 0); } if (pad.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_Y) < -0.2) { this.movePlayer(player, 0, -1); } if (pad.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_Y) > 0.2) { this.movePlayer(player, 0, 1); } }, readLevelFile: function() { this.pills = this.game.add.group(); this.players = this.game.add.group(); this.walls = this.game.add.group(); var levelText = this.game.cache.getText('level'); var splitRows = levelText.split('\n'); for (var x=0; x