System.register(["../input/Pad", "../entities/Player", "../entities/Robe", "./ActOneHammerTime", "../manager/Sequence"], function(exports_1) {
    var __extends = (this && this.__extends) || function (d, b) {
        for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
    var Pad_1, Player_1, Robe_1, ActOneHammerTime_1, Sequence_1;
    var State, Game, ActOne;
    return {
        setters:[
            function (Pad_1_1) {
                Pad_1 = Pad_1_1;
            },
            function (Player_1_1) {
                Player_1 = Player_1_1;
            },
            function (Robe_1_1) {
                Robe_1 = Robe_1_1;
            },
            function (ActOneHammerTime_1_1) {
                ActOneHammerTime_1 = ActOneHammerTime_1_1;
            },
            function (Sequence_1_1) {
                Sequence_1 = Sequence_1_1;
            }],
        execute: function() {
            State = Phaser.State;
            ActOne = (function (_super) {
                __extends(ActOne, _super);
                function ActOne() {
                    _super.apply(this, arguments);
                }
                ActOne.prototype.preload = function () {
                    this.game.load.atlasJSONHash('player', 'assets/animations/player/player.png', 'assets/animations/player/player.json');
                    this.game.load.atlasJSONHash('enemy', 'assets/animations/robe/robe.png', 'assets/animations/robe/robe.json');
                    this.game.load.atlasJSONHash('torch', 'assets/animations/torch/torch.png', 'assets/animations/torch/torch.json');
                    this.game.load.image('cave', 'assets/images/cave_entrance.png');
                    this.game.load.image('background', 'assets/images/scene_01.png');
                    this.game.load.image('background_collision', 'assets/images/scene_01_collision.png');
                    this.game.load.audio('sneak_music', 'assets/music/sneak.ogg');
                    this.game.load.image('dialog_1', 'assets/dialogs/scene_1_0.png');
                    this.game.load.image('dialog_2', 'assets/dialogs/scene_1_1.png');
                };
                ;
                ActOne.prototype.create = function () {
                    var _this = this;
                    this.game.input.gamepad.start();
                    this.pad = new Pad_1.Pad(this.game.input.gamepad.pad1);
                    this.music = this.game.add.audio('sneak_music');
                    this.music.play();
                    this.background = this.game.add.sprite(0, 0, 'background');
                    this.background_collision = this.game.add.sprite(0, 25, 'background_collision');
                    this.background_collision.visible = false;
                    this.torch_1 = this.game.add.sprite(205, 50, 'torch');
                    this.torch_2 = this.game.add.sprite(505, 50, 'torch');
                    this.torch_1.animations.add('idle_flame_1', ['1.png', '2.png'], 2, true, false);
                    this.torch_2.animations.add('idle_flame_2', ['2.png', '1.png'], 2, true, false);
                    this.enemy = new Robe_1.Robe(this.game.add.sprite(480, 200, 'enemy', '03.png'));
                    this.cave = this.game.add.sprite(310, 108, 'cave');
                    this.cave.scale.setTo(0.4, 0.4);
                    this.player = new Player_1.Player(this.game.add.sprite(100, 500, 'player', '01.png'), this.pad);
                    this.player.sprite.play('down');
                    this.player.sprite.animations.stop();
                    this.torch_1.scale.setTo(2.5, 2.5);
                    this.torch_2.scale.setTo(2.5, 2.5);
                    this.torch_1.play('idle_flame_1');
                    this.torch_2.play('idle_flame_2');
                    this.pad.onRightHold = function () {
                        _this.player.sprite.body.velocity.x = 200;
                    };
                    this.pad.onLeftHold = function () {
                        _this.player.sprite.body.velocity.x = -200;
                    };
                    this.pad.onUpHold = function () {
                        _this.player.sprite.body.velocity.y = -200;
                    };
                    this.pad.onDownHold = function () {
                        _this.player.sprite.body.velocity.y = 200;
                    };
                    this.pad.onThree = function () {
                        var enemyPositionFeet = new Phaser.Point(_this.enemy.sprite.x, _this.enemy.sprite.y);
                        enemyPositionFeet.x += _this.enemy.sprite.width / 2;
                        enemyPositionFeet.y += _this.enemy.sprite.height;
                        var playerPositionFeet = new Phaser.Point(_this.player.sprite.position.x, _this.player.sprite.position.y);
                        playerPositionFeet.x += _this.player.sprite.width / 2;
                        playerPositionFeet.y += _this.player.sprite.height;
                        var distance = enemyPositionFeet.distance(playerPositionFeet);
                        if (distance < 50) {
                            _this.game.state.add('actHammer', new ActOneHammerTime_1.ActOneHammerTime(), false);
                            _this.game.state.start('actHammer');
                        }
                    };
                    this.game.physics.enable(this.player.sprite, Phaser.Physics.ARCADE);
                    this.game.physics.enable(this.enemy.sprite, Phaser.Physics.ARCADE);
                    this.game.physics.enable(this.cave, Phaser.Physics.ARCADE);
                    this.game.physics.enable(this.background_collision, Phaser.Physics.ARCADE);
                    this.game.physics.startSystem(Phaser.Physics.ARCADE);
                    this.background_collision.body.immovable = true;
                    this.enemy.sprite.body.immovable = true;
                    this.cave.body.immovable = true;
                    this.cave.body.setSize(200, 50, 25, 65);
                    this.enemy.sprite.body.setSize(20, 20, 5, 5);
                    this.player.sprite.body.collideWorldBounds = true;
                    this.dialog1 = this.game.add.sprite(0, this.game.world.height, 'dialog_1');
                    this.dialog1.anchor.setTo(0, 1);
                    this.dialog2 = this.game.add.sprite(0, this.game.world.height, 'dialog_2');
                    this.dialog2.anchor.setTo(0, 1);
                    this.dialog2.visible = false;
                    var sequence = new Sequence_1.Sequence(this.game);
                    sequence.chain(5000, function () {
                        _this.dialog1.visible = false;
                    }).then(function () {
                        return sequence.chain(0, function () {
                            _this.dialog2.visible = true;
                        });
                    }).then(function () {
                        return sequence.chain(4000, function () {
                            _this.dialog2.visible = false;
                        });
                    });
                };
                ;
                ActOne.prototype.shutdown = function () {
                    this.music.stop();
                };
                ActOne.prototype.update = function () {
                    this.player.sprite.body.velocity.x = 0;
                    this.player.sprite.body.velocity.y = 0;
                    this.pad.update();
                    this.game.physics.arcade.collide(this.player.sprite, this.background_collision);
                };
                ;
                return ActOne;
            })(State);
            exports_1("ActOne", ActOne);
        }
    }
});
//# sourceMappingURL=ActOne.js.map