From c508e9ef283a4069ea1af923ca1a241d2c954a1e Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sun, 21 Sep 2014 10:31:48 +0200 Subject: Renamed prefab folder --- game/entities/bonusPill.js | 18 +++++++ game/entities/hud.js | 50 +++++++++++++++++++ game/entities/pill.js | 18 +++++++ game/entities/player.js | 118 ++++++++++++++++++++++++++++++++++++++++++++ game/entities/poisonPill.js | 18 +++++++ game/entities/wall.js | 12 +++++ game/prefabs/bonusPill.js | 18 ------- game/prefabs/hud.js | 50 ------------------- game/prefabs/pill.js | 18 ------- game/prefabs/player.js | 118 -------------------------------------------- game/prefabs/poisonPill.js | 18 ------- game/prefabs/wall.js | 12 ----- game/states/play.js | 14 +++--- 13 files changed, 240 insertions(+), 242 deletions(-) create mode 100644 game/entities/bonusPill.js create mode 100644 game/entities/hud.js create mode 100644 game/entities/pill.js create mode 100644 game/entities/player.js create mode 100644 game/entities/poisonPill.js create mode 100644 game/entities/wall.js delete mode 100644 game/prefabs/bonusPill.js delete mode 100644 game/prefabs/hud.js delete mode 100644 game/prefabs/pill.js delete mode 100644 game/prefabs/player.js delete mode 100644 game/prefabs/poisonPill.js delete mode 100644 game/prefabs/wall.js (limited to 'game') diff --git a/game/entities/bonusPill.js b/game/entities/bonusPill.js new file mode 100644 index 0000000..dd8dfce --- /dev/null +++ b/game/entities/bonusPill.js @@ -0,0 +1,18 @@ +'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.score = 10; +}; + +BonusPill.prototype = Object.create(Phaser.Sprite.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/hud.js b/game/entities/hud.js new file mode 100644 index 0000000..a7b39a0 --- /dev/null +++ b/game/entities/hud.js @@ -0,0 +1,50 @@ +'use strict'; + +var Hud = function(game, player, x, y, scorefontKey, keyboardSpriteKey) { + Phaser.Group.call(this, game); + this.x = x; + this.y = y; + this.player = player; + this.scale = {x: 0.02, y: 0.02}; + + + this.background = new Phaser.Sprite(this.game, 0, 0, 'hud-bg'); + this.add(this.background); + this.scoreText = new Phaser.BitmapText(this.game, 172, 10, scorefontKey, '0', 100); + this.add(this.scoreText); + + this.poisonIndicator = new Phaser.Sprite(this.game, 200, 150, 'poison-pill'); + //this.poisonIndicator.scale = {0.1, 0.1}; + this.poisonIndicator.anchor = {x:0.5, y:0.5}; + this.add(this.poisonIndicator); + + this.controllerDiagram = new Phaser.Sprite(this.game, 0, 300, 'controller-diagram'); + this.controllerDiagram.scale = {x: 0.5, y: 0.5}; + this.add(this.controllerDiagram); + + this.keyboardControls = new Phaser.Sprite(this.game, 0, 600, keyboardSpriteKey); + this.keyboardControls.scale = {x: 0.5, y: 0.5}; + this.add(this.keyboardControls); + + this.currentScore = 0; +}; + +Hud.prototype = Object.create(Phaser.Group.prototype); +Hud.prototype.constructor = Hud; + +Hud.prototype.update = function() { + if (this.currentScore !== this.player.score) { + this.currentScore = this.player.score; + this.scoreText.setText(this.player.score+''); + + var numberOfDigits = Math.floor(Math.log(this.currentScore)/Math.log(10))+1; + this.scoreText.x = 200 - numberOfDigits*30; + } + + if (this.poisonIndicator && !this.player.hasPoisonPill) { + this.poisonIndicator.destroy(); + this.poisonIndicator = null; + } +}; + +module.exports = Hud; diff --git a/game/entities/pill.js b/game/entities/pill.js new file mode 100644 index 0000000..13054b0 --- /dev/null +++ b/game/entities/pill.js @@ -0,0 +1,18 @@ +'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}; + + this.score = 1; +}; + +Pill.prototype = Object.create(Phaser.Sprite.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 new file mode 100644 index 0000000..c7f0b94 --- /dev/null +++ b/game/entities/player.js @@ -0,0 +1,118 @@ +'use strict'; + +var Player = function(game, x, y, key, frame, soundKey) { + var player = this; + + Phaser.Sprite.call(this, game, x, y, key, frame); + this.animations.add('active', [0]); + this.animations.add('waiting', [1]); + this.animations.add('activePoison', [2]); + this.animations.add('waitingPoison', [3]); + + this.baseKey = key; + this.moving = false; + this.scale = {x: 0.01, y: 0.01}; + this.anchor = {x: 0.5, y: 0.5}; + + this.score = 0; + this.maxScore = 1; + this.isMyTurn = false; + this.canBeEaten = true; + + this.currentAnimation = { + isMyTurn: true, + poisonPillActive: false + } + + this.hasPoisonPill = true; + this.poisonPillActive = false; + this.gamepadPoisonLastPressed = Number.NEGATIVE_INFINITY; + this.lastTween = null; + + this.scoreSound = game.sound.add(soundKey); + this.respawnSound = game.sound.add('owSound'); + + + //BEWARE! HORRIBLE HACK AHEAD! + //Intercepts the call to get a new buffer so that we can set the playbackRate. + var audioContext = this.scoreSound.context; + var childContext = Object.create(audioContext); + this.scoreSound.context = childContext; + + childContext.createBufferSource = function() { + var source = audioContext.createBufferSource(); + var scoreFraction = player.score / player.maxScore; + source.playbackRate.value = 0.75 + scoreFraction*6; + return source; + }; +}; + +Player.prototype = Object.create(Phaser.Sprite.prototype); +Player.prototype.constructor = Player; + +Player.prototype.update = function() { + if (this.isMyTurn !== this.currentAnimation.isMyTurn || this.poisonPillActive !== this.currentAnimation.poisonPillActive) { + this.currentAnimation.isMyTurn = this.isMyTurn; + this.currentAnimation.poisonPillActive = this.poisonPillActive; + + var animation; + if (!this.currentAnimation.isMyTurn) { + if (!this.currentAnimation.poisonPillActive) { + animation = 'waiting'; + } + else { + animation = 'waitingPoison' + } + } + else { + if (!this.currentAnimation.poisonPillActive) { + animation = 'active'; + } + else { + animation = 'activePoison' + } + } + this.play(animation); + } +}; + +Player.prototype.move = function(newX, newY, callback, callbackContext) { + this.moving = true; + + var tween = this.game.add.tween(this).to({x: newX, y: newY}, 500); + tween.onComplete.add(callback, callbackContext); + tween.onComplete.add(this.finishMovement, this); + + this.lastTween = tween; + + tween.start(); +}; + +Player.prototype.multistepMove = function(moveX, moveY, teleportX, teleportY, finalX, finalY, callback, callbackContext) { + this.moving = true; + + var firstTween = this.game.add.tween(this).to({x: moveX, y: moveY}, 500); + + firstTween.onComplete.add(function() { + this.teleport(teleportX, teleportY); + this.move(finalX, finalY, callback, callbackContext); + }, this); + + firstTween.start(); +} + +Player.prototype.teleport = function(newX, newY) { + this.x = newX; + this.y = newY; +} + +Player.prototype.finishMovement = function() { + this.moving = false; + 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 new file mode 100644 index 0000000..408f77f --- /dev/null +++ b/game/entities/poisonPill.js @@ -0,0 +1,18 @@ +'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}; + + this.score = 1; +}; + +PoisonPill.prototype = Object.create(Phaser.Sprite.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 new file mode 100644 index 0000000..c4eee79 --- /dev/null +++ b/game/entities/wall.js @@ -0,0 +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}; +}; + +Wall.prototype = Object.create(Phaser.Sprite.prototype); +Wall.prototype.constructor = Wall; + +module.exports = Wall; diff --git a/game/prefabs/bonusPill.js b/game/prefabs/bonusPill.js deleted file mode 100644 index dd8dfce..0000000 --- a/game/prefabs/bonusPill.js +++ /dev/null @@ -1,18 +0,0 @@ -'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.score = 10; -}; - -BonusPill.prototype = Object.create(Phaser.Sprite.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/prefabs/hud.js b/game/prefabs/hud.js deleted file mode 100644 index a7b39a0..0000000 --- a/game/prefabs/hud.js +++ /dev/null @@ -1,50 +0,0 @@ -'use strict'; - -var Hud = function(game, player, x, y, scorefontKey, keyboardSpriteKey) { - Phaser.Group.call(this, game); - this.x = x; - this.y = y; - this.player = player; - this.scale = {x: 0.02, y: 0.02}; - - - this.background = new Phaser.Sprite(this.game, 0, 0, 'hud-bg'); - this.add(this.background); - this.scoreText = new Phaser.BitmapText(this.game, 172, 10, scorefontKey, '0', 100); - this.add(this.scoreText); - - this.poisonIndicator = new Phaser.Sprite(this.game, 200, 150, 'poison-pill'); - //this.poisonIndicator.scale = {0.1, 0.1}; - this.poisonIndicator.anchor = {x:0.5, y:0.5}; - this.add(this.poisonIndicator); - - this.controllerDiagram = new Phaser.Sprite(this.game, 0, 300, 'controller-diagram'); - this.controllerDiagram.scale = {x: 0.5, y: 0.5}; - this.add(this.controllerDiagram); - - this.keyboardControls = new Phaser.Sprite(this.game, 0, 600, keyboardSpriteKey); - this.keyboardControls.scale = {x: 0.5, y: 0.5}; - this.add(this.keyboardControls); - - this.currentScore = 0; -}; - -Hud.prototype = Object.create(Phaser.Group.prototype); -Hud.prototype.constructor = Hud; - -Hud.prototype.update = function() { - if (this.currentScore !== this.player.score) { - this.currentScore = this.player.score; - this.scoreText.setText(this.player.score+''); - - var numberOfDigits = Math.floor(Math.log(this.currentScore)/Math.log(10))+1; - this.scoreText.x = 200 - numberOfDigits*30; - } - - if (this.poisonIndicator && !this.player.hasPoisonPill) { - this.poisonIndicator.destroy(); - this.poisonIndicator = null; - } -}; - -module.exports = Hud; diff --git a/game/prefabs/pill.js b/game/prefabs/pill.js deleted file mode 100644 index 13054b0..0000000 --- a/game/prefabs/pill.js +++ /dev/null @@ -1,18 +0,0 @@ -'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}; - - this.score = 1; -}; - -Pill.prototype = Object.create(Phaser.Sprite.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/prefabs/player.js b/game/prefabs/player.js deleted file mode 100644 index c7f0b94..0000000 --- a/game/prefabs/player.js +++ /dev/null @@ -1,118 +0,0 @@ -'use strict'; - -var Player = function(game, x, y, key, frame, soundKey) { - var player = this; - - Phaser.Sprite.call(this, game, x, y, key, frame); - this.animations.add('active', [0]); - this.animations.add('waiting', [1]); - this.animations.add('activePoison', [2]); - this.animations.add('waitingPoison', [3]); - - this.baseKey = key; - this.moving = false; - this.scale = {x: 0.01, y: 0.01}; - this.anchor = {x: 0.5, y: 0.5}; - - this.score = 0; - this.maxScore = 1; - this.isMyTurn = false; - this.canBeEaten = true; - - this.currentAnimation = { - isMyTurn: true, - poisonPillActive: false - } - - this.hasPoisonPill = true; - this.poisonPillActive = false; - this.gamepadPoisonLastPressed = Number.NEGATIVE_INFINITY; - this.lastTween = null; - - this.scoreSound = game.sound.add(soundKey); - this.respawnSound = game.sound.add('owSound'); - - - //BEWARE! HORRIBLE HACK AHEAD! - //Intercepts the call to get a new buffer so that we can set the playbackRate. - var audioContext = this.scoreSound.context; - var childContext = Object.create(audioContext); - this.scoreSound.context = childContext; - - childContext.createBufferSource = function() { - var source = audioContext.createBufferSource(); - var scoreFraction = player.score / player.maxScore; - source.playbackRate.value = 0.75 + scoreFraction*6; - return source; - }; -}; - -Player.prototype = Object.create(Phaser.Sprite.prototype); -Player.prototype.constructor = Player; - -Player.prototype.update = function() { - if (this.isMyTurn !== this.currentAnimation.isMyTurn || this.poisonPillActive !== this.currentAnimation.poisonPillActive) { - this.currentAnimation.isMyTurn = this.isMyTurn; - this.currentAnimation.poisonPillActive = this.poisonPillActive; - - var animation; - if (!this.currentAnimation.isMyTurn) { - if (!this.currentAnimation.poisonPillActive) { - animation = 'waiting'; - } - else { - animation = 'waitingPoison' - } - } - else { - if (!this.currentAnimation.poisonPillActive) { - animation = 'active'; - } - else { - animation = 'activePoison' - } - } - this.play(animation); - } -}; - -Player.prototype.move = function(newX, newY, callback, callbackContext) { - this.moving = true; - - var tween = this.game.add.tween(this).to({x: newX, y: newY}, 500); - tween.onComplete.add(callback, callbackContext); - tween.onComplete.add(this.finishMovement, this); - - this.lastTween = tween; - - tween.start(); -}; - -Player.prototype.multistepMove = function(moveX, moveY, teleportX, teleportY, finalX, finalY, callback, callbackContext) { - this.moving = true; - - var firstTween = this.game.add.tween(this).to({x: moveX, y: moveY}, 500); - - firstTween.onComplete.add(function() { - this.teleport(teleportX, teleportY); - this.move(finalX, finalY, callback, callbackContext); - }, this); - - firstTween.start(); -} - -Player.prototype.teleport = function(newX, newY) { - this.x = newX; - this.y = newY; -} - -Player.prototype.finishMovement = function() { - this.moving = false; - 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/prefabs/poisonPill.js b/game/prefabs/poisonPill.js deleted file mode 100644 index 408f77f..0000000 --- a/game/prefabs/poisonPill.js +++ /dev/null @@ -1,18 +0,0 @@ -'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}; - - this.score = 1; -}; - -PoisonPill.prototype = Object.create(Phaser.Sprite.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/prefabs/wall.js b/game/prefabs/wall.js deleted file mode 100644 index c4eee79..0000000 --- a/game/prefabs/wall.js +++ /dev/null @@ -1,12 +0,0 @@ -'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}; -}; - -Wall.prototype = Object.create(Phaser.Sprite.prototype); -Wall.prototype.constructor = Wall; - -module.exports = Wall; diff --git a/game/states/play.js b/game/states/play.js index 5151438..d872c71 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -1,17 +1,15 @@ 'use strict'; -var Player = require('../prefabs/player'); -var Pill = require('../prefabs/pill'); -var BonusPill = require('../prefabs/bonusPill'); -var Wall = require('../prefabs/wall'); -var PoisonPill = require('../prefabs/poisonPill'); -var Hud = require('../prefabs/hud'); +var Player = require('../entities/player'); +var Pill = require('../entities/pill'); +var BonusPill = require('../entities/bonusPill'); +var Wall = require('../entities/wall'); +var PoisonPill = require('../entities/poisonPill'); +var Hud = require('../entities/hud'); function Play() {} Play.prototype = { - preload: function() { - }, create: function() { this.readLevelFile(); -- cgit v1.2.3