summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@entelect.co.za>2014-05-14 12:30:04 +0200
committerJustin Worthe <justin.worthe@entelect.co.za>2014-05-14 12:30:04 +0200
commitd0d4f4318cae17e65c738c595550b5e5a0904e05 (patch)
tree882f2fd9bdb0a1ddf46fa77bba50bd24092f5a40 /game
parent98e5b9470fdc102765a289078b3967e3d94fcae0 (diff)
Added scoring on colliding with pills
closes #4
Diffstat (limited to 'game')
-rw-r--r--game/prefabs/pill.js5
-rw-r--r--game/prefabs/player.js4
-rw-r--r--game/states/play.js27
3 files changed, 32 insertions, 4 deletions
diff --git a/game/prefabs/pill.js b/game/prefabs/pill.js
index 2df13f2..50c0277 100644
--- a/game/prefabs/pill.js
+++ b/game/prefabs/pill.js
@@ -4,17 +4,14 @@ 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};
- // initialize your prefab here
+ this.game.physics.arcade.enableBody(this);
};
Pill.prototype = Object.create(Phaser.Sprite.prototype);
Pill.prototype.constructor = Pill;
Pill.prototype.update = function() {
-
- // write your prefab's specific update code here
-
};
module.exports = Pill;
diff --git a/game/prefabs/player.js b/game/prefabs/player.js
index 1336003..b520947 100644
--- a/game/prefabs/player.js
+++ b/game/prefabs/player.js
@@ -6,6 +6,10 @@ var Player = function(game, x, y, key, frame) {
this.moving = false;
this.scale = {x: 0.01, y: 0.01};
this.anchor = {x: 0.5, y: 0.5};
+
+ this.game.physics.arcade.enableBody(this);
+
+ this.score = 0;
};
Player.prototype = Object.create(Phaser.Sprite.prototype);
diff --git a/game/states/play.js b/game/states/play.js
index 2d73701..ea92480 100644
--- a/game/states/play.js
+++ b/game/states/play.js
@@ -42,8 +42,11 @@ Play.prototype = {
this.playerA = new Player(this.game, 1, 2, 'player-a', 0);
this.game.add.existing(this.playerA);
this.addPlayerControls();
+
+ this.game.physics.startSystem(Phaser.Physics.ARCADE);
},
update: function() {
+ this.game.physics.arcade.overlap(this.playerA, this.pills, this.playerPillCollision, null, this);
},
createWalls: function() {
this.walls = this.game.add.group();
@@ -90,6 +93,24 @@ Play.prototype = {
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));
},
addPlayerControls: function() {
var controls = {
@@ -117,6 +138,12 @@ Play.prototype = {
if (!this.checkMap(newX, newY)) {
player.move(newX, newY);
}
+ },
+ playerPillCollision: function(player, pill) {
+ player.score++;
+ pill.destroy();
+
+ console.log(this.playerA.score);
}
};