diff options
author | Justin Worthe <justin.worthe@gmail.com> | 2014-09-24 17:20:56 +0200 |
---|---|---|
committer | Justin Worthe <justin.worthe@gmail.com> | 2014-09-24 17:20:56 +0200 |
commit | 17ebd1e3857d47ad5fd94e40283ecd468dd83739 (patch) | |
tree | 6e65cf51bc9411af4c2d77a274838cebd32df85c | |
parent | 1eabe62fcf61001a10b1965da0cf3a4ae741a25b (diff) |
Moved common game entity code into parent class
-rw-r--r-- | game/entities/bonusPill.js | 14 | ||||
-rw-r--r-- | game/entities/entityBase.js | 14 | ||||
-rw-r--r-- | game/entities/pill.js | 14 | ||||
-rw-r--r-- | game/entities/player.js | 12 | ||||
-rw-r--r-- | game/entities/poisonPill.js | 14 | ||||
-rw-r--r-- | game/entities/wall.js | 10 | ||||
-rw-r--r-- | game/states/play.js | 4 |
7 files changed, 40 insertions, 42 deletions
diff --git a/game/entities/bonusPill.js b/game/entities/bonusPill.js index dd8dfce..ee4d79b 100644 --- a/game/entities/bonusPill.js +++ b/game/entities/bonusPill.js @@ -1,18 +1,14 @@ '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}; +var EntityBase = require('../entities/entityBase'); + +var BonusPill = function(game, x, y) { + EntityBase.call(this, game, x, y, 'bonus-pill'); this.score = 10; }; -BonusPill.prototype = Object.create(Phaser.Sprite.prototype); +BonusPill.prototype = Object.create(EntityBase.prototype); BonusPill.prototype.constructor = BonusPill; -BonusPill.prototype.getBounds = function() { - return new Phaser.Rectangle(this.x, this.y, 0.2, 0.2); -}; - module.exports = BonusPill; diff --git a/game/entities/entityBase.js b/game/entities/entityBase.js new file mode 100644 index 0000000..1c70b92 --- /dev/null +++ b/game/entities/entityBase.js @@ -0,0 +1,14 @@ +'use strict'; + +var EntityBase = function(game, x, y, key) { + Phaser.Sprite.call(this, game, x, y, key); + this.scale = {x: 0.01, y: 0.01}; + this.anchor = {x: 0.5, y: 0.5}; +}; +EntityBase.prototype = Object.create(Phaser.Sprite.prototype); + +EntityBase.prototype.getBounds = function() { + return new Phaser.Rectangle(this.x, this.y, 0.5, 0.5); +}; + +module.exports = EntityBase;
\ No newline at end of file diff --git a/game/entities/pill.js b/game/entities/pill.js index 13054b0..af64a4c 100644 --- a/game/entities/pill.js +++ b/game/entities/pill.js @@ -1,18 +1,14 @@ 'use strict'; -var Pill = function(game, x, y, frame) { - Phaser.Sprite.call(this, game, x, y, 'pill', frame); - this.scale = {x: 0.01, y: 0.01}; - this.anchor = {x: 0.5, y: 0.5}; +var EntityBase = require('../entities/entityBase'); + +var Pill = function(game, x, y) { + EntityBase.call(this, game, x, y, 'pill'); this.score = 1; }; -Pill.prototype = Object.create(Phaser.Sprite.prototype); +Pill.prototype = Object.create(EntityBase.prototype); Pill.prototype.constructor = Pill; -Pill.prototype.getBounds = function() { - return new Phaser.Rectangle(this.x, this.y, 0.2, 0.2); -}; - module.exports = Pill; diff --git a/game/entities/player.js b/game/entities/player.js index c7f0b94..f8c7a8b 100644 --- a/game/entities/player.js +++ b/game/entities/player.js @@ -1,9 +1,11 @@ 'use strict'; -var Player = function(game, x, y, key, frame, soundKey) { +var EntityBase = require('../entities/entityBase'); + +var Player = function(game, x, y, key, soundKey) { var player = this; - Phaser.Sprite.call(this, game, x, y, key, frame); + EntityBase.call(this, game, x, y, key); this.animations.add('active', [0]); this.animations.add('waiting', [1]); this.animations.add('activePoison', [2]); @@ -47,7 +49,7 @@ var Player = function(game, x, y, key, frame, soundKey) { }; }; -Player.prototype = Object.create(Phaser.Sprite.prototype); +Player.prototype = Object.create(EntityBase.prototype); Player.prototype.constructor = Player; Player.prototype.update = function() { @@ -111,8 +113,4 @@ Player.prototype.finishMovement = function() { this.lastTween = null; }; -Player.prototype.getBounds = function() { - return new Phaser.Rectangle(this.x, this.y, 0.2, 0.2); -}; - module.exports = Player; diff --git a/game/entities/poisonPill.js b/game/entities/poisonPill.js index 408f77f..08b2952 100644 --- a/game/entities/poisonPill.js +++ b/game/entities/poisonPill.js @@ -1,18 +1,12 @@ 'use strict'; -var PoisonPill = function(game, x, y, frame) { - Phaser.Sprite.call(this, game, x, y, 'poison-pill', frame); - this.scale = {x: 0.01, y: 0.01}; - this.anchor = {x: 0.5, y: 0.5}; +var EntityBase = require('../entities/entityBase'); - this.score = 1; +var PoisonPill = function(game, x, y) { + EntityBase.call(this, game, x, y, 'poison-pill'); }; -PoisonPill.prototype = Object.create(Phaser.Sprite.prototype); +PoisonPill.prototype = Object.create(EntityBase.prototype); PoisonPill.prototype.constructor = PoisonPill; -PoisonPill.prototype.getBounds = function() { - return new Phaser.Rectangle(this.x, this.y, 0.2, 0.2); -}; - module.exports = PoisonPill; diff --git a/game/entities/wall.js b/game/entities/wall.js index c4eee79..8a6e45d 100644 --- a/game/entities/wall.js +++ b/game/entities/wall.js @@ -1,12 +1,12 @@ 'use strict'; -var Wall = function(game, x, y, frame) { - Phaser.Sprite.call(this, game, x, y, 'wall', frame); - this.scale = {x: 0.01, y: 0.01}; - this.anchor = {x: 0.5, y: 0.5}; +var EntityBase = require('../entities/entityBase'); + +var Wall = function(game, x, y) { + EntityBase.call(this, game, x, y, 'wall'); }; -Wall.prototype = Object.create(Phaser.Sprite.prototype); +Wall.prototype = Object.create(EntityBase.prototype); Wall.prototype.constructor = Wall; module.exports = Wall; diff --git a/game/states/play.js b/game/states/play.js index d872c71..cabe9cf 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -183,11 +183,11 @@ Play.prototype = { this.pills.add(new BonusPill(this.game, x, y)); break; case 'A': - this.playerA = new Player(this.game, x, y, 'player-a', 0, 'omSound'); + this.playerA = new Player(this.game, x, y, 'player-a', 'omSound'); this.players.add(this.playerA); break; case 'B': - this.playerB = new Player(this.game, x, y, 'player-b', 0, 'nomSound'); + this.playerB = new Player(this.game, x, y, 'player-b', 'nomSound'); this.players.add(this.playerB); break; case '|': |