Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Dimensions {
- export class Hunter extends Phaser.Sprite {
- notFiring:Boolean = true;
- jumpEnd: Number = 0;
- constructor(game: Phaser.Game, x: number, y: number) {
- super(game, x, y, 'player', 0);
- this.anchor.setTo(0.5, 0);
- //Add some animations
- 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);
- 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);
- this.animations.add('hunter_idle', ["idle_001.png","idle_002.png"], 5, true);
- //Enable the physics body and set debugging to true
- this.game.physics.p2.enable(this,true);
- //Prevent the player from becoming a carnival attraction
- this.body.fixedRotation = true;
- //Add the player
- this.game.add.existing(this);
- }
- update() {
- //Reset the velocity and firing status
- this.body.velocity.x = 0;
- this.notFiring = true;
- //If it's down the player is firing
- if(this.game.input.keyboard.isDown(Phaser.Keyboard.F)){
- this.notFiring = false;
- this.animations.play("hunter_attack1");
- }
- //Handle movement
- if (this.game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
- this.body.velocity.x = -600;
- if(this.notFiring){
- this.animations.play('hunter_walk');
- }
- if(this.scale.x == -1){
- this.scale.x = 1;
- }
- }
- else if (this.game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
- this.body.velocity.x = 600;
- if(this.notFiring){
- this.animations.play('hunter_walk');
- }
- if (this.scale.x == 1) {
- this.scale.x = -1;
- }
- } else {
- if(this.notFiring){
- this.animations.play('hunter_idle');
- }
- }
- if(this.game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)){
- if(this.game.time.now > this.jumpEnd){
- this.body.velocity.y = -1200;
- this.jumpEnd = this.game.time.now + 850;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement