System.register(["../input/Pad", "../entities/Player", "../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, Sequence_1;
    var Game, State, ActTwo;
    return {
        setters:[
            function (Pad_1_1) {
                Pad_1 = Pad_1_1;
            },
            function (Player_1_1) {
                Player_1 = Player_1_1;
            },
            function (Sequence_1_1) {
                Sequence_1 = Sequence_1_1;
            }],
        execute: function() {
            State = Phaser.State;
            ActTwo = (function (_super) {
                __extends(ActTwo, _super);
                function ActTwo() {
                    _super.apply(this, arguments);
                }
                ActTwo.prototype.preload = function () {
                    this.game.load.atlasJSONHash('enemy', 'assets/animations/robe/robe.png', 'assets/animations/robe/robe.json');
                    this.game.load.atlasJSONHash('player_robe', 'assets/animations/player_robe/player_robe.png', 'assets/animations/player_robe/player_robe.json');
                    this.game.load.image('table_bg', 'assets/images/table_bg.png');
                    this.game.load.image('amulet_small', 'assets/images/amulet_small.png');
                    this.game.load.audio('amulet_music', 'assets/music/amulet.ogg');
                    this.game.load.audio('amulet_use', 'assets/sounds/amulet_use.ogg');
                    this.game.load.image('dialog_1', 'assets/dialogs/scene_2_0.png');
                    this.game.load.image('dialog_2', 'assets/dialogs/scene_2_1.png');
                };
                ActTwo.prototype.create = function () {
                    var _this = this;
                    this.game.stage.backgroundColor = '#fff';
                    this.game.add.sprite(0, 0, 'table_bg');
                    this.amulet = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, 'amulet_small');
                    this.amulet.position.add(-60, -100);
                    this.music = this.game.add.audio('amulet_music', 1, true);
                    this.music.play();
                    var amuletUseSound = this.game.add.audio('amulet_use');
                    this.game.input.gamepad.start();
                    this.pad = new Pad_1.Pad(this.game.input.gamepad.pad1);
                    var robe = this.game.add.sprite(0, 180, 'enemy', '05.png');
                    var player_robe = this.game.add.sprite(0, 180, 'player_robe', '05.png');
                    player_robe.visible = false;
                    this.player = new Player_1.Player(robe, this.pad);
                    this.player.setupRobeAnimations(robe);
                    this.player.sprite.position.setTo(0, this.game.world.height / 2);
                    this.player.sprite.scale.setTo(2.5, 2.5);
                    this.dialog1 = this.game.add.sprite(0, this.game.world.height, 'dialog_1');
                    this.dialog1.anchor.setTo(0, 1);
                    this.dialog1.visible = false;
                    this.dialog2 = this.game.add.sprite(0, this.game.world.height, 'dialog_2');
                    this.dialog2.anchor.setTo(0, 1);
                    this.dialog2.visible = false;
                    var alreadyPickedUp = false;
                    this.pad.onThree = function () {
                        if (!alreadyPickedUp) {
                            var amuletPosition = new Phaser.Point(_this.amulet.x, _this.amulet.y);
                            amuletPosition.x += _this.amulet.width / 2;
                            amuletPosition.y += _this.amulet.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 = amuletPosition.distance(playerPositionFeet);
                            if (distance < 100) {
                                alreadyPickedUp = true;
                                var sequence = new Sequence_1.Sequence(_this.game);
                                sequence.chain(0, function () {
                                    _this.dialog1.visible = true;
                                }).then(function () {
                                    return sequence.chain(4000, function () {
                                        _this.dialog1.visible = false;
                                        _this.dialog2.visible = true;
                                    });
                                }).then(function () {
                                    return sequence.chain(4000, function () {
                                        _this.dialog2.visible = false;
                                    });
                                });
                                _this.amulet.visible = false;
                                robe.visible = false;
                                player_robe.visible = true;
                                var previousPosition = new Phaser.Point(_this.player.sprite.position.x, _this.player.sprite.y);
                                _this.player.sprite = player_robe;
                                _this.player.setupPlayerRobeAnimations(player_robe);
                                _this.player.sprite.scale.setTo(2.5, 2.5);
                                _this.player.sprite.position.setTo(previousPosition.x, previousPosition.y);
                                _this.player.sprite.play('down');
                                _this.player.sprite.animations.stop();
                                _this.music.fadeTo(500, 0);
                                amuletUseSound.volume = 0;
                                amuletUseSound.play();
                                amuletUseSound.fadeTo(500, 1);
                                _this.game.time.events.add(8000, function () {
                                    _this.game.state.start('ritual');
                                });
                            }
                        }
                    };
                };
                ActTwo.prototype.shutdown = function () {
                    this.music.stop();
                };
                ActTwo.prototype.update = function () {
                    this.pad.update();
                };
                return ActTwo;
            })(State);
            exports_1("ActTwo", ActTwo);
        }
    }
});
//# sourceMappingURL=ActTwo.js.map