summaryrefslogtreecommitdiff
path: root/game/prefabs/player.js
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2014-04-21 17:49:29 +0200
committerJustin Worthe <justin.worthe@gmail.com>2014-04-21 17:49:29 +0200
commita5ab29fd2d015f2db65d8062d2bb23222859b6d1 (patch)
tree4c53e3fcb2eb77126625a6c516bf77ebce3dcf6d /game/prefabs/player.js
parenta9ba8a68d61110cca347e2a4823b25880bc94923 (diff)
Added tracking of where walls are, to prevent moving through
closes #3
Diffstat (limited to 'game/prefabs/player.js')
-rw-r--r--game/prefabs/player.js41
1 files changed, 3 insertions, 38 deletions
diff --git a/game/prefabs/player.js b/game/prefabs/player.js
index 8e3ac3d..a195f94 100644
--- a/game/prefabs/player.js
+++ b/game/prefabs/player.js
@@ -1,21 +1,10 @@
'use strict';
-var Player = function(game, x, y, key, frame, controls) {
+var Player = function(game, x, y, key, frame) {
Phaser.Sprite.call(this, game, x, y, key, frame);
this.moving = false;
-
- this.game.input.keyboard.addKeyCapture([
- controls.up,
- controls.down,
- controls.left,
- controls.right
- ]);
-
- this.game.input.keyboard.addKey(controls.up).onDown.add(this.moveUp, this);
- this.game.input.keyboard.addKey(controls.down).onDown.add(this.moveDown, this);
- this.game.input.keyboard.addKey(controls.left).onDown.add(this.moveLeft, this);
- this.game.input.keyboard.addKey(controls.right).onDown.add(this.moveRight, this);
+ this.scale = {x: 0.01, y: 0.01};
};
Player.prototype = Object.create(Phaser.Sprite.prototype);
@@ -24,31 +13,11 @@ Player.prototype.constructor = Player;
Player.prototype.update = function() {
};
-Player.prototype.moveUp = function() {
- this.move(0, -100);
-};
-Player.prototype.moveDown = function() {
- this.move(0, 100);
-};
-Player.prototype.moveLeft = function() {
- this.move(-100, 0);
-};
-Player.prototype.moveRight = function() {
- this.move(100, 0);
-};
-
-Player.prototype.move = function(deltaX, deltaY) {
+Player.prototype.move = function(newX, newY) {
if (this.moving) {
return;
}
- var newX = this.x + deltaX;
- var newY = this.y + deltaY;
-
- if (!this.canMoveToNewLocation(newX, newY)) {
- return;
- }
-
this.moving = true;
var tween = this.game.add.tween(this).to({x: newX, y: newY}, 500);
tween.onComplete.add(this.finishMovement, this);
@@ -59,8 +28,4 @@ Player.prototype.finishMovement = function() {
this.moving = false;
};
-Player.prototype.canMoveToNewLocation = function(newX, newY) {
- return true;
-};
-
module.exports = Player;