System.register([], function(exports_1) {
    var RitualManager, Circle, Field;
    return {
        setters:[],
        execute: function() {
            RitualManager = (function () {
                function RitualManager(game) {
                    var _this = this;
                    this.game = game;
                    this.rotation = 0;
                    this.totalTime = 0;
                    this.playerTime = 0;
                    this.update = function () {
                        _this.circle.update();
                        _this.circle.angle += _this.rotation;
                    };
                    this.rotate = function (clockWise) {
                        if (clockWise === void 0) { clockWise = true; }
                        _this.rotation = clockWise ? 0.45 : -0.45;
                    };
                    this.stopRotation = function () {
                        _this.rotation = 0;
                    };
                    this.setRotation = function (rotation) {
                        _this.rotation = rotation;
                    };
                    this.check = function (player) {
                        var delta = _this.game.time.elapsedMS;
                        _this.totalTime += delta;
                        var x = player.sprite.position.x + (player.sprite.width / 2);
                        var y = player.sprite.position.y + player.sprite.height;
                        var playerPosition = new Phaser.Point(x, y);
                        var playerField = _this.circle.fields[5];
                        var fieldX = playerField.x + _this.game.world.centerX;
                        var fieldY = playerField.y + _this.game.world.centerY;
                        var distance = playerPosition.distance(new Phaser.Point(playerField.x + _this.game.world.centerX, playerField.y + _this.game.world.centerY));
                        if (distance < playerField.radius + 10) {
                            _this.playerTime += delta;
                        }
                    };
                    this.checkIfWon = function () {
                        var style = { font: "40px Arial", fill: "#ececec", align: "center" };
                        var percent = 100 / _this.totalTime * _this.playerTime;
                        if (percent < 90) {
                            _this.game.time.events.add(2000, function () {
                                _this.game.state.start('gameOver');
                            });
                            _this.game.add.text(50, 100, "90%+ wins", style);
                        }
                        _this.game.add.text(50, 50, (percent >= 90 ? "Won: " : "Lost: ") + percent + "%", style);
                    };
                    this.circle = new Circle(this.game);
                }
                return RitualManager;
            })();
            exports_1("RitualManager", RitualManager);
            Circle = (function () {
                function Circle(game) {
                    var _this = this;
                    this.game = game;
                    this.angle = 0;
                    this.fields = [];
                    this.radius = 200;
                    this.getField = function (angle) {
                        var result = new Field();
                        result.angle = angle;
                        result.setPosition(_this.radius, 0);
                        return result;
                    };
                    this.updateFields = function () {
                        _this.fields.forEach(function (field, index) {
                            field.setPosition(_this.radius, _this.angle);
                            field.drawCircle();
                        });
                    };
                    this.update = function () {
                        _this.updateFields();
                    };
                    this.x = this.game.world.centerX;
                    this.y = this.game.world.centerY;
                    var alpha = 360 / 6;
                    for (var i = 0; i < 6; i++) {
                        this.fields.push(this.getField(i * alpha));
                        this.fields[i].groundCircle = this.game.add.graphics(this.game.world.centerX, this.game.world.centerY);
                    }
                }
                return Circle;
            })();
            exports_1("Circle", Circle);
            Field = (function () {
                function Field() {
                    var _this = this;
                    this.radius = 40;
                    this.setPosition = function (radius, angle) {
                        _this.x = radius * Math.cos(Phaser.Math.degToRad(_this.angle + angle));
                        _this.y = radius * Math.sin(Phaser.Math.degToRad(_this.angle + angle));
                    };
                    this.drawCircle = function () {
                        if (_this.groundCircle) {
                            _this.groundCircle.clear();
                            _this.groundCircle.alpha = 0.5;
                            _this.groundCircle.beginFill(0x00bff3);
                            _this.groundCircle.arc(_this.x, _this.y, _this.radius, 0, Phaser.Math.degToRad(360), false);
                            _this.groundCircle.endFill();
                        }
                    };
                }
                return Field;
            })();
            exports_1("Field", Field);
        }
    }
});
//# sourceMappingURL=RitualManager.js.map