import { Phaser } from 'phaser';
import { Spell } from './spell';

export class Wizard extends Phaser.Sprite { 
    constructor(game) {
        super(game, 400, 300, 'wizard');
        this.anchor.setTo(0.5, 0.5);    
        this.scale.setTo(0.65, 0.65);
        this.animations.add('right', [0,1,2]);        
        this.animations.add('left', [3,4,5]);
        
        this.game.physics.enable(this, Phaser.Physics.ARCADE);
        
        this.body.drag.set(100);
        this.body.maxVelocity.set(200);  
        this.body.collideWorldBounds = true; 
        
        this.spellTime = 0;
        
        this.spells = game.add.group();
        this.spells.enableBody = true;
        this.spells.physicsBodyType = Phaser.Physics.ARCADE;
        
        for(let i = 0; i < 3; i++) {
           let spell = new Spell(game, 0, 0);
           this.spells.add(spell); 
           spell.lifespan = 1;
        }
    }
    
    skate(cursors) {
        
        if (cursors.up.isDown) {
            this.body.velocity.y = -150;        
            this.animations.play('right', 4, true);
        } else {
            this.body.velocity.y = 0;
            this.animations.stop('right');
        }
        
        if (cursors.down.isDown) {            
            this.body.velocity.y = 150;     
            this.animations.play('left', 4, true);
        } else {
            this.body.velocity.y = 0;
            this.animations.stop('left');
        }

        if (cursors.left.isDown) {            
            this.body.velocity.x = -150;
            this.animations.play('left', 4, true);
        } else if (cursors.right.isDown) {            
            this.body.velocity.x = 150;
            this.animations.play('right', 4, true);
        } else {            
            this.body.velocity.x = 0;
        }        
    }
    
    castSpell() {
        if (this.game.time.now > this.spellTime) {
            let spell = this.spells.getFirstExists(false);
            
            if (spell) {                
                spell.casting();
                spell.reset(this.body.x + 32, this.body.y);
                spell.lifespan = 2000;
                spell.rotation = this.rotation;
                this.game.physics.arcade.velocityFromRotation(this.rotation, 100, spell.body.velocity);
                this.spellTime = this.game.time.now + 50;
            }
        }
    }
    
}
@@ -498,17 +498,17 @@
 ity.set(
-2
+5
 00);  %0A 
@@ -938,20 +938,16 @@
 rsors) %7B
-%0A   
      %0A  
@@ -1003,23 +1003,27 @@
 ody.
-velocity
+acceleration
 .y = -
-1
+2
 50; 
@@ -1033,177 +1033,211 @@
     
-%0A            this.animations.play('right', 4, true);%0A        %7D else %7B%0A            this.body.velocity.y = 0;%0A            this.animations.stop('right');%0A        %7D%0A        
+           %0A        %7D else if (cursors.down.isDown) %7B            %0A            this.body.acceleration.y = 250;           %0A        %7D else %7B%0A            this.body.acceleration.y = 0;%0A        %7D%0A%0A%3C%3C%3C%3C%3C%3C%3C HEAD
 %0A   
@@ -1245,36 +1245,36 @@
     if (cursors.
-down
+left
 .isDown) %7B      
@@ -1315,21 +1315,17 @@
 ity.
-y
+x
  = 
+-
 150;
-     
 %0A   
@@ -1391,100 +1391,95 @@
 lse 
-%7B%0A            this.body.velocity.y = 0;%0A            this.animations.stop('left');%0A        %7D%0A
+if (cursors.right.isDown) %7B            %0A            this.body.velocity.x = 150;%0A=======
 %0A   
@@ -1508,37 +1508,32 @@
 isDown) %7B       
-    
- 
 %0A            thi
@@ -1535,39 +1535,43 @@
   this.body.
-velocity
+acceleration
 .x = -
-1
+2
 50;%0A        
@@ -1657,34 +1657,32 @@
 own) %7B          
-  
 %0A            thi
@@ -1688,34 +1688,87 @@
 is.body.
-velocity
+acceleration
 .x = 
-1
+2
 50;%0A
+%3E%3E%3E%3E%3E%3E%3E c2b707e442865f6e2f23f2b13f2cedb3fca8348b%0A
         
@@ -1858,32 +1858,36 @@
   this.body.
-velocity
+acceleration
 .x = 0;%0A    

fix merge conflict