From 920eccd0fe8a8acc6ff03f4333a400a9782f6d1a Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Thu, 17 Jul 2014 19:23:25 +0200 Subject: Added bonus pill and bumped phaser version --- game/prefabs/bonusPill.js | 15 +++++++++++++++ game/prefabs/pill.js | 4 +--- game/states/play.js | 10 +++++++--- game/states/preload.js | 1 + 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 game/prefabs/bonusPill.js (limited to 'game') diff --git a/game/prefabs/bonusPill.js b/game/prefabs/bonusPill.js new file mode 100644 index 0000000..1b7ae56 --- /dev/null +++ b/game/prefabs/bonusPill.js @@ -0,0 +1,15 @@ +'use strict'; + +var BonusPill = function(game, x, y, frame) { + Phaser.Sprite.call(this, game, x, y, 'bonus-pill', frame); + this.scale = {x: 0.01, y: 0.01}; + this.anchor = {x: 0.5, y: 0.5}; + + this.game.physics.arcade.enableBody(this); + this.score = 10; +}; + +BonusPill.prototype = Object.create(Phaser.Sprite.prototype); +BonusPill.prototype.constructor = BonusPill; + +module.exports = BonusPill; diff --git a/game/prefabs/pill.js b/game/prefabs/pill.js index 50c0277..29bf7a2 100644 --- a/game/prefabs/pill.js +++ b/game/prefabs/pill.js @@ -6,12 +6,10 @@ var Pill = function(game, x, y, frame) { this.anchor = {x: 0.5, y: 0.5}; this.game.physics.arcade.enableBody(this); + this.score = 1; }; Pill.prototype = Object.create(Phaser.Sprite.prototype); Pill.prototype.constructor = Pill; -Pill.prototype.update = function() { -}; - module.exports = Pill; diff --git a/game/states/play.js b/game/states/play.js index a2d7edf..ca259b4 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -1,8 +1,9 @@ 'use strict'; -var Wall = require('../prefabs/wall'); var Player = require('../prefabs/player'); var Pill = require('../prefabs/pill'); +var BonusPill = require('../prefabs/bonusPill'); +var Wall = require('../prefabs/wall'); function Play() {} @@ -86,6 +87,9 @@ Play.prototype = { case '.': this.pills.add(new Pill(this.game, x, y)); break; + case '*': + this.pills.add(new BonusPill(this.game, x, y)); + break; case 'A': this.playerA = new Player(this.game, x, y, 'player-a', 0); this.players.add(this.playerA); @@ -109,7 +113,7 @@ Play.prototype = { left: Phaser.Keyboard.A, down: Phaser.Keyboard.S, right: Phaser.Keyboard.D - } + }; this.playerBControls = { up: Phaser.Keyboard.UP, left: Phaser.Keyboard.LEFT, @@ -147,7 +151,7 @@ Play.prototype = { } }, playerPillCollision: function(player, pill) { - player.score++; + player.score += pill.score; pill.destroy(); this.playerAScoreText.setText(this.playerA.score+''); diff --git a/game/states/preload.js b/game/states/preload.js index 6b81a8a..7d9b9d3 100644 --- a/game/states/preload.js +++ b/game/states/preload.js @@ -18,6 +18,7 @@ Preload.prototype = { this.load.image('player-b', 'assets/images/player-b.svg'); this.load.image('player-b-dim', 'assets/images/player-b-dim.svg'); this.load.image('pill', 'assets/images/pill.svg'); + this.load.image('bonus-pill', 'assets/images/bonus-pill.svg'); 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'); -- cgit v1.2.3