Reorganized code: created Player class
[shapeshift.git] / shapeshift.js
index 44d42fda5f84286c9d04b0ce43e8beb141435604..37481aaab41c2f94088815ffebe602a3e738b873 100644 (file)
             }
         }, 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);
             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();