var __extends = this.__extends || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
var MazeInstruments;
(function (MazeInstruments) {
    var Instruments = (function (_super) {
        __extends(Instruments, _super);
        function Instruments(game, name, x, y, json) {
            _super.call(this, game, name, x, y, json);
            this.koniec = false;
            this.fail = false;
            this.ready = false;
        }
        Instruments.prototype.init = function (json) {
            _super.prototype.init.call(this, json);
            this.Elements = json.GameData;
        };
        Instruments.prototype.preload = function () {
            _super.prototype.preload.call(this);
            this.game.load.onLoadComplete.addOnce(this.create, this);
            this.loadGraphics();
            this.game.load.start();
            this.map = this.Elements.Tilemap[0].layers[0].data;
            this.game.load.spritesheet('player', 'Graphics/Games/MW_G_II_10 /MW_g_II_10 _gracz.png', 29, 29, 4);
        };
        Instruments.prototype.loadGraphics = function () {
            for (var i = 0; i < this.Elements.Graphics.length; i++)
                this.game.load.image(this.Elements.Graphics[i].key, this.Elements.Graphics[i].src);
            this.cursors = this.game.input.keyboard.createCursorKeys();
        };
        Instruments.prototype.create = function () {
            if (this.json.isStandalone) {
                _super.prototype.create.call(this);
            }
            this.game.physics.startSystem(Phaser.Physics.ARCADE);
            this.wall = this.game.add.group();
            this.addChild(this.wall);
            this.player = this.game.add.sprite(560, 64, 'player');
            this.player.animations.add('walk', [0, 1, 2, 3], 0, false);
            this.addChild(this.player);
            this.przewodnik = this.game.add.sprite(1150, 255, 'przewodnik');
            this.przewodnik.inputEnabled = true;
            this.przewodnik.events.onInputDown.add(function () {
                this.przewodnik.visible = false;
                if (this.koniec == false)
                    this.ready = true;
                if (this.koniec == true && this.fail == true)
                    this.resetStage();
            }, this);
            this.addChild(this.przewodnik);
            this.dymek = this.game.add.sprite(-700, -200, 'dymek');
            this.przewodnik.addChild(this.dymek);
            this.polecenie = this.game.add.text(150, 200, "Nie pozwól na marnowanie \nwody w Twojej firmie,\nzawsze zakręcaj kran.", { font: "32px Arial", fill: "#000000", wordWrap: true, wordWrapWidth: this.dymek.width, align: "center" });
            this.dymek.addChild(this.polecenie);
            this.game.physics.enable([this.player], Phaser.Physics.ARCADE);
            var idx = 0;
            for (var i = 0; i < 21; i++)
                for (var j = 0; j < 21; j++) {
                    if (this.map[idx++] == 1)
                        var spr = this.game.add.sprite(500 + (j * 32), (i * 32), 'blok');
                    this.game.physics.enable(spr, Phaser.Physics.ARCADE);
                    this.addChild(spr);
                    this.wall.add(spr);
                }
            this.wall.setAll('body.immovable', true);
        };
        Instruments.prototype.resetStage = function () {
            this.player.x = 560;
            this.player.y = 64;
            this.koniec = false;
            this.fail = false;
        };
        Instruments.prototype.update = function () {
            if (this.ready) {
                this.player.body.velocity.x = 0;
                this.player.body.velocity.y = 0;
                if (this.game.physics.arcade.collide(this.player, this.kran)) {
                }
                this.game.physics.arcade.collide(this.player, this.wall);
                this.player.body.velocity.x = 0;
                this.player.body.velocity.y = 0;
                if (this.cursors.left.isDown) {
                    this.player.body.velocity.x = -200;
                    if (this.player.body.moves != false)
                        this.player.animations.frame = 3;
                }
                if (this.cursors.right.isDown) {
                    this.player.body.velocity.x = 200;
                    if (this.player.body.moves != false)
                        this.player.animations.frame = 2;
                }
                if (this.cursors.up.isDown) {
                    this.player.body.velocity.y = -200;
                    if (this.player.body.moves != false)
                        this.player.animations.frame = 1;
                }
                if (this.cursors.down.isDown) {
                    this.player.body.velocity.y = 200;
                    if (this.player.body.moves != false)
                        this.player.animations.frame = 0;
                }
            }
        };
        return Instruments;
    })(Base.BasicGroup);
    MazeInstruments.Instruments = Instruments;
})(MazeInstruments || (MazeInstruments = {}));
//# sourceMappingURL=MazeInstruments.js.map