From dca5c89e801b197f5b724394deddbda523ceb304 Mon Sep 17 00:00:00 2001 From: MegaBrutal Date: Wed, 22 Mar 2017 21:30:22 +0100 Subject: [PATCH] Reorganized code: created Player class modified: shapeshift.js --- shapeshift.js | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/shapeshift.js b/shapeshift.js index 44d42fd..37481aa 100644 --- a/shapeshift.js +++ b/shapeshift.js @@ -63,6 +63,26 @@ } }, false); + class Player extends Phaser.Sprite { + constructor(x, y, sprite) { + super(game, x, y, sprite); + this.anchor.setTo(.4,.5); + this.scale.x = 0.5; + this.scale.y = this.scale.x; + this.pushed = 0; + this.shape = SHAPE_GIRL; + this.learnedBird = false; + } + + enablePhysics() { + game.physics.arcade.enable(this); + this.body.bounce.y = 0.2; + this.body.bounce.x = 0.2; + this.body.gravity.y = 300; + this.body.collideWorldBounds = true; + } + } + class Guard extends Phaser.Sprite { constructor(x, y, sprite, dialogues) { //var guard = game.add.sprite(x, y, sprite); @@ -114,18 +134,10 @@ ground.body.immovable = true; - player = game.add.sprite(64, game.world.height - 200, 'player_girl'); - player.anchor.setTo(.4,.5); - player.scale.x = 0.5; - player.scale.y = player.scale.x; - game.physics.arcade.enable(player); - player.body.bounce.y = 0.2; - player.body.bounce.x = 0.2; - player.body.gravity.y = 300; - player.body.collideWorldBounds = true; - player.pushed = 0; - player.shape = SHAPE_GIRL; - player.learnedBird = false; + //player = game.add.sprite(64, game.world.height - 200, 'player_girl'); + player = new Player(64, game.world.height - 200, 'player_girl'); + player.enablePhysics(); + game.add.existing(player); game.camera.follow(player); guards = game.add.group(); -- 2.34.1