Advertisement
Guest User

Untitled

a guest
Jul 17th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Dimensions {
  2.  
  3.     export class Hunter extends Phaser.Sprite {
  4.  
  5.         notFiring:Boolean = true;
  6.         jumpEnd: Number = 0;
  7.  
  8.  
  9.         constructor(game: Phaser.Game, x: number, y: number) {
  10.  
  11.             super(game, x, y, 'player', 0);
  12.  
  13.             this.anchor.setTo(0.5, 0);
  14.  
  15.             //Add some animations
  16.             this.animations.add('hunter_walk', ["walk_001.png","walk_002.png","walk_003.png","walk_004.png","walk_005.png","walk_006.png"], 10, true);
  17.             this.animations.add('hunter_attack1', ["attack1_007.png","attack1_006.png","attack1_005.png","attack1_004.png","attack1_003.png","attack1_002.png","attack1_001.png"], 7, false);
  18.             this.animations.add('hunter_idle', ["idle_001.png","idle_002.png"], 5, true);
  19.  
  20.             //Enable the physics body and set debugging to true
  21.             this.game.physics.p2.enable(this,true);
  22.  
  23.             //Prevent the player from becoming a carnival attraction
  24.             this.body.fixedRotation = true;
  25.  
  26.             //Add the player
  27.             this.game.add.existing(this);
  28.  
  29.         }
  30.  
  31.         update() {
  32.  
  33.             //Reset the velocity and firing status
  34.             this.body.velocity.x = 0;
  35.             this.notFiring = true;
  36.  
  37.             //If it's down the player is firing
  38.             if(this.game.input.keyboard.isDown(Phaser.Keyboard.F)){
  39.                 this.notFiring = false;
  40.                 this.animations.play("hunter_attack1");
  41.             }
  42.  
  43.             //Handle movement
  44.             if (this.game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
  45.  
  46.                 this.body.velocity.x = -600;
  47.                 if(this.notFiring){
  48.                     this.animations.play('hunter_walk');
  49.                 }
  50.  
  51.                 if(this.scale.x == -1){
  52.                     this.scale.x = 1;
  53.                 }
  54.  
  55.  
  56.             }
  57.             else if (this.game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
  58.  
  59.                 this.body.velocity.x = 600;
  60.  
  61.                 if(this.notFiring){
  62.                     this.animations.play('hunter_walk');
  63.                 }
  64.  
  65.                 if (this.scale.x == 1) {
  66.                     this.scale.x = -1;
  67.                 }
  68.             } else {
  69.                 if(this.notFiring){
  70.                     this.animations.play('hunter_idle');
  71.                 }
  72.             }
  73.  
  74.              if(this.game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)){
  75.                 if(this.game.time.now > this.jumpEnd){
  76.                         this.body.velocity.y = -1200;
  77.                         this.jumpEnd = this.game.time.now + 850;
  78.                 }
  79.             }
  80.  
  81.  
  82.  
  83.         }
  84.  
  85.     }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement