Reorganized code: created Player class
authorMegaBrutal <code+git@megabrutal.com>
Wed, 22 Mar 2017 20:30:22 +0000 (21:30 +0100)
committerMegaBrutal <code+git@megabrutal.com>
Wed, 22 Mar 2017 20:30:22 +0000 (21:30 +0100)
modified:   shapeshift.js

shapeshift.js

index 44d42fd..37481aa 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();