diff options
author | Justin Worthe <justin.worthe@entelect.co.za> | 2014-07-17 14:19:32 +0200 |
---|---|---|
committer | Justin Worthe <justin.worthe@entelect.co.za> | 2014-07-17 14:19:32 +0200 |
commit | 95cecb4933b7b991308c91abcc99a5281c479765 (patch) | |
tree | 9b796f4f60d4f1817a3ee7b6ad25fcc4e50fdfa4 | |
parent | 6e5bdbe7f8a2a0de71c498a69d9c2ceabb89504c (diff) |
Added reading levels from a file
-rw-r--r-- | config.json | 4 | ||||
-rw-r--r-- | css/styles.css | 2 | ||||
-rw-r--r-- | game/main.js | 2 | ||||
-rw-r--r-- | game/states/play.js | 101 | ||||
-rw-r--r-- | 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<splitRows.length; x++) { + for (var y=0; y<splitRows[x].length; y++) { + switch(splitRows[x][y]) { + case '#': + this.walls.add(new Wall(this.game, x, y)); + break; + case '.': + this.pills.add(new Pill(this.game, x, y)); + break; + case 'A': + this.playerA = new Player(this.game, x, y, 'player-a', 0); + this.players.add(this.playerA); + break; + case 'B': + this.playerB = new Player(this.game, x, y, 'player-b', 0); + this.players.add(this.playerB); + break; + } + } + } this.walls.forEach(function(wall) { this.addToMap(wall.x, wall.y); }, this); - }, - createPills: function() { - this.pills = this.game.add.group(); - - this.pills.add(new Pill(this.game, 1,1)); - this.pills.add(new Pill(this.game, 2,1)); - this.pills.add(new Pill(this.game, 3,1)); - this.pills.add(new Pill(this.game, 4,1)); - this.pills.add(new Pill(this.game, 5,1)); - this.pills.add(new Pill(this.game, 6,1)); - - this.pills.add(new Pill(this.game, 3,2)); - this.pills.add(new Pill(this.game, 4,2)); - - this.pills.add(new Pill(this.game, 3,3)); - this.pills.add(new Pill(this.game, 4,3)); - - this.pills.add(new Pill(this.game, 1,4)); - this.pills.add(new Pill(this.game, 2,4)); - this.pills.add(new Pill(this.game, 3,4)); - this.pills.add(new Pill(this.game, 4,4)); - this.pills.add(new Pill(this.game, 5,4)); - this.pills.add(new Pill(this.game, 6,4)); - }, - createPlayers: function() { - this.players = this.game.add.group(); - - this.playerA = new Player(this.game, 1, 2, 'player-a', 0); - this.playerB = new Player(this.game, 6, 2, 'player-b', 0); - this.players.add(this.playerA); - this.players.add(this.playerB); - this.updatePlayerTurn(0); }, addPlayerControls: function() { diff --git a/game/states/preload.js b/game/states/preload.js index 8709258..6b81a8a 100644 --- a/game/states/preload.js +++ b/game/states/preload.js @@ -21,6 +21,8 @@ Preload.prototype = { this.load.bitmapFont('spaced-scorefont', 'assets/fonts/scorefont.png', 'assets/fonts/scorefont.fnt', undefined, 10); this.load.bitmapFont('scorefont', 'assets/fonts/scorefont.png', 'assets/fonts/scorefont.fnt'); + + this.load.text('level', 'assets/levels/maze.lvl'); }, create: function() { this.asset.cropEnabled = false; |