From 95cecb4933b7b991308c91abcc99a5281c479765 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Thu, 17 Jul 2014 14:19:32 +0200 Subject: Added reading levels from a file --- config.json | 4 +- css/styles.css | 2 +- game/main.js | 2 +- game/states/play.js | 101 +++++++++++++++---------------------------------- game/states/preload.js | 2 + 5 files changed, 36 insertions(+), 75 deletions(-) diff --git a/config.json b/config.json index 4700cd6..0ac8700 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { "projectName": "Interactive Pacbot", - "gameWidth": "800", - "gameHeight": "600" + "gameWidth": "1100", + "gameHeight": "950" } \ No newline at end of file diff --git a/css/styles.css b/css/styles.css index 6537b1e..e5b870b 100644 --- a/css/styles.css +++ b/css/styles.css @@ -3,7 +3,7 @@ body { } #interactive-pacbot { - width: 800px; + width: 1100px; margin-left: auto; margin-right: auto; cursor: pointer; diff --git a/game/main.js b/game/main.js index 0f5208f..e2812da 100644 --- a/game/main.js +++ b/game/main.js @@ -2,7 +2,7 @@ //global variables window.onload = function () { - var game = new Phaser.Game(800, 600, Phaser.AUTO, 'interactive-pacbot'); + var game = new Phaser.Game(1100, 950, Phaser.AUTO, 'interactive-pacbot'); // Game States game.state.add('boot', require('./states/boot')); diff --git a/game/states/play.js b/game/states/play.js index e3009a5..a2d7edf 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -32,12 +32,10 @@ Play.prototype = { preload: function() { }, create: function() { - this.createWalls(); - this.createPills(); - this.createPlayers(); + this.readLevelFile(); - this.world.scale = {x:100, y:100}; - this.world.bounds = {x: -50, y:-50, width: this.game.width, height: this.game.height}; + 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(); @@ -70,78 +68,39 @@ Play.prototype = { }, 5000); } }, - createWalls: function() { + readLevelFile: function() { this.walls = this.game.add.group(); + this.pills = this.game.add.group(); + this.players = this.game.add.group(); - this.walls.add(new Wall(this.game, 0,0)); - this.walls.add(new Wall(this.game, 1,0)); - this.walls.add(new Wall(this.game, 2,0)); - this.walls.add(new Wall(this.game, 3,0)); - this.walls.add(new Wall(this.game, 4,0)); - this.walls.add(new Wall(this.game, 5,0)); - this.walls.add(new Wall(this.game, 6,0)); - this.walls.add(new Wall(this.game, 7,0)); - - this.walls.add(new Wall(this.game, 0,1)); - this.walls.add(new Wall(this.game, 7,1)); - - this.walls.add(new Wall(this.game, 0,2)); - this.walls.add(new Wall(this.game, 2,2)); - this.walls.add(new Wall(this.game, 5,2)); - this.walls.add(new Wall(this.game, 7,2)); - - this.walls.add(new Wall(this.game, 0,3)); - this.walls.add(new Wall(this.game, 2,3)); - this.walls.add(new Wall(this.game, 5,3)); - this.walls.add(new Wall(this.game, 7,3)); - - this.walls.add(new Wall(this.game, 0,4)); - this.walls.add(new Wall(this.game, 7,4)); - - this.walls.add(new Wall(this.game, 0,5)); - this.walls.add(new Wall(this.game, 1,5)); - this.walls.add(new Wall(this.game, 2,5)); - this.walls.add(new Wall(this.game, 3,5)); - this.walls.add(new Wall(this.game, 4,5)); - this.walls.add(new Wall(this.game, 5,5)); - this.walls.add(new Wall(this.game, 6,5)); - this.walls.add(new Wall(this.game, 7,5)); + var levelText = this.game.cache.getText('level'); + var splitRows = levelText.split('\n'); + + + for (var x=0; x