<commit_before>var Game = function() {
    return function(size) {

        var that      = this;
        var lastSpin  = unixTime();
        var lastSpawn = unixTime();
        var TITLE_SCREEN = 0;
        var GAME = 1;
        var END_SCREEN = 2;
        var stateBus     = new Bacon.Bus;
        var currentState = stateBus.toProperty(TITLE_SCREEN);

        var renderer = null;
        var physics  = null;
        var context  = null;

        gameWidth = size;
        gameHeight = size;
        var stage    = null;
        var container = null;
        var titleStage = null;
        var titleContainer = null;

        var endStage = null;
        var endContainer = null;
        var score = 0;

        function canvasSize() {
            var $window = $(window);
            return Math.min($window.width(), $window.height()) / Math.sqrt(2);
        }

        this.setupCanvas = function() {
            renderer = PIXI.autoDetectRenderer(canvasSize(), canvasSize());
            $("#container").append("<canvas id='sup' width='" + canvasSize() + "' height='" + canvasSize() + "'></canvas>");

            context = document.getElementById("sup").getContext("2d");
            $("#sup").css({
                "z-index":100000,
                "position":"absolute"
            });
            $('#container').append(renderer.view);
            $("#container").css({
                "top": ($(window).height()-canvasSize())/2,
                "left": ($(window).width()-canvasSize())/2
            });
        };

        this.setupGame = function() {
            physics = new Physics(context, gameWidth, gameHeight, function() {
                stateBus.push(END_SCREEN);
                that.rotation = 0;
                setTimeout(function() {
                    $("#container").resetRotate();
                }, 300);
            }, function(timeRemaining) {
                $("#time").css({"width":(timeRemaining*10) + "px"});
            });
            currentState.changes()
                        .filter(function(x) { return x == GAME; })
                        .onValue(function() {
                physics.startClock();
            });
            pixiSetup();
            soundSetup();
            var inputs = Input.key('title_to_game');
            inputs.filter(currentState.map(function(x) { return x === TITLE_SCREEN; }))
                  .onValue(function() { stateBus.push(GAME); });
            inputs.filter(currentState.map(function(x) { return x === END_SCREEN; }))
                  .onValue(function() { location.reload(); });
        };

        var stepTitle = function() {
            that.draw_title_screen();
        };

        var stepGame = function() {
            that.update();
            that.render();
        };

        var stepEnd = function() {
            that.draw_end_screen();
        };

        var stepFunction = currentState.map(function(s) {
            switch (s) {
                case TITLE_SCREEN: return stepTitle;
                case GAME: return stepGame;
                case END_SCREEN: return stepEnd;
            }
        });

        var stepBus = new Bacon.Bus();

        stepFunction.sampledBy(stepBus).onValue(function (callback) {
            callback();
        });

        this.step = function() {
            score += 7;
            requestAnimFrame(that.step);
            stepBus.push();
        };

        this.draw_title_screen = function() {
            titleContainer.scale.x = canvasSize()/gameWidth;
            titleContainer.scale.y = canvasSize()/gameWidth;
            renderer.render(titleStage);
        };

        this.draw_end_screen = function() {
            endContainer.scale.x = canvasSize()/gameWidth;
            endContainer.scale.y = canvasSize()/gameWidth;
            renderer.render(endStage);
            $("#sup").hide();
        };

        this.update = function() {
            value = Constants.k('target_cheeses');
            $("#removed").text("Score: " + score);
            if (physics.boxesRemoved >= value) {
                stateBus.push(END_SCREEN);
            }
            spinIfNecessary();
            physics.update(function() {
                lastSpin = unixTime();
                spawnBlocks();
            });
            $("#container").rotate(physics.getRotation());
        };

        function spinIfNecessary() {
            value = Constants.k('spin_interval');
            if (unixTime() - lastSpin > value) {
                spin();
            }
        }

        function spawnBlocks() {
            blocksToSpawn = Constants.k('blocks_to_spawn');
            blockSpawnDelayMs = Constants.k('block_spawn_delay_ms');
            if (Constants.k('debug_noSpawnBlocks'))
                return;
            lastSpawn = unixTime();
            var block_count = 0;
            var timer = setInterval(function() {
                physics.newBlock("block", container);
                block_count++;
                if (block_count == blocksToSpawn) {
                    clearInterval(timer);
                }
            }, blockSpawnDelayMs);
        }

        function spin() {
            lastSpin = unixTime();
            min = Constants.k('minimum_rotation');
            max = Constants.k('maximum_rotation');
            if (Constants.k('debug_noSpin'))
                return;
            var direction = Math.ceil(Math.random());
            if (direction == 0) {
                direction = -1;
            }

            var range = max - min;
            var angle = min + Math.random() * range;
            physics.setTargetRotation(angle + physics.getRotation());
        }

        this.render = function() {
            physics.draw(canvasSize()/gameWidth);
            container.scale.x = canvasSize()/gameWidth;
            container.scale.y = canvasSize()/gameWidth;
            renderer.render(stage);
        };

        function rotateCanvas(rotation) {
        }

        function pixiSetup() {
            preload();
            lastSpin = unixTime();
            lastSpawn = unixTime();<commit_msg>Spin increase timer.<commit_after>var Game = function() {
    return function(size) {

        var that      = this;
        var lastSpin  = unixTime();
        var lastSpawn = unixTime();
        var TITLE_SCREEN = 0;
        var GAME = 1;
        var END_SCREEN = 2;
        var stateBus     = new Bacon.Bus;
        var currentState = stateBus.toProperty(TITLE_SCREEN);

        var renderer = null;
        var physics  = null;
        var context  = null;
        var periods  = 1;

        setInterval(function() {
            periods++;
            console.log("new period");
        }, Constants.k("spin_increase_period"));

        gameWidth = size;
        gameHeight = size;
        var stage    = null;
        var container = null;
        var titleStage = null;
        var titleContainer = null;

        var endStage = null;
        var endContainer = null;
        var score = 0;

        function canvasSize() {
            var $window = $(window);
            return Math.min($window.width(), $window.height()) / Math.sqrt(2);
        }

        this.setupCanvas = function() {
            renderer = PIXI.autoDetectRenderer(canvasSize(), canvasSize());
            $("#container").append("<canvas id='sup' width='" + canvasSize() + "' height='" + canvasSize() + "'></canvas>");

            context = document.getElementById("sup").getContext("2d");
            $("#sup").css({
                "z-index":100000,
                "position":"absolute"
            });
            $('#container').append(renderer.view);
            $("#container").css({
                "top": ($(window).height()-canvasSize())/2,
                "left": ($(window).width()-canvasSize())/2
            });
        };

        this.setupGame = function() {
            physics = new Physics(context, gameWidth, gameHeight, function() {
                stateBus.push(END_SCREEN);
                that.rotation = 0;
                setTimeout(function() {
                    $("#container").resetRotate();
                }, 300);
            }, function(timeRemaining) {
                $("#time").css({"width":(timeRemaining*10) + "px"});
            });
            currentState.changes()
                        .filter(function(x) { return x == GAME; })
                        .onValue(function() {
                physics.startClock();
            });
            pixiSetup();
            soundSetup();
            var inputs = Input.key('title_to_game');
            inputs.filter(currentState.map(function(x) { return x === TITLE_SCREEN; }))
                  .onValue(function() { stateBus.push(GAME); });
            inputs.filter(currentState.map(function(x) { return x === END_SCREEN; }))
                  .onValue(function() { location.reload(); });
        };

        var stepTitle = function() {
            that.draw_title_screen();
        };

        var stepGame = function() {
            that.update();
            that.render();
        };

        var stepEnd = function() {
            that.draw_end_screen();
        };

        var stepFunction = currentState.map(function(s) {
            switch (s) {
                case TITLE_SCREEN: return stepTitle;
                case GAME: return stepGame;
                case END_SCREEN: return stepEnd;
            }
        });

        var stepBus = new Bacon.Bus();

        stepFunction.sampledBy(stepBus).onValue(function (callback) {
            callback();
        });

        this.step = function() {
            score += 7;
            requestAnimFrame(that.step);
            stepBus.push();
        };

        this.draw_title_screen = function() {
            titleContainer.scale.x = canvasSize()/gameWidth;
            titleContainer.scale.y = canvasSize()/gameWidth;
            renderer.render(titleStage);
        };

        this.draw_end_screen = function() {
            endContainer.scale.x = canvasSize()/gameWidth;
            endContainer.scale.y = canvasSize()/gameWidth;
            renderer.render(endStage);
            $("#sup").hide();
        };

        this.update = function() {
            value = Constants.k('target_cheeses');
            $("#removed").text("Score: " + score);
            if (physics.boxesRemoved >= value) {
                stateBus.push(END_SCREEN);
            }
            spinIfNecessary();
            physics.update(function() {
                lastSpin = unixTime();
                spawnBlocks();
            });
            $("#container").rotate(physics.getRotation());
        };

        function spinIfNecessary() {
            value = Constants.k('spin_interval');
            if (unixTime() - lastSpin > value) {
                spin(periods);
            }
        }

        function spawnBlocks() {
            blocksToSpawn = Constants.k('blocks_to_spawn');
            blockSpawnDelayMs = Constants.k('block_spawn_delay_ms');
            if (Constants.k('debug_noSpawnBlocks'))
                return;
            lastSpawn = unixTime();
            var block_count = 0;
            var timer = setInterval(function() {
                physics.newBlock("block", container);
                block_count++;
                if (block_count == blocksToSpawn) {
                    clearInterval(timer);
                }
            }, blockSpawnDelayMs);
        }

        function spin(periods) {
            lastSpin = unixTime();
            min = Constants.k('minimum_rotation');
            max = Constants.k('maximum_rotation');
            if (Constants.k('debug_noSpin'))
                return;
            var direction = Math.ceil(Math.random());
            if (direction == 0) {
                direction = -1;
            }

            var range = max - min;
            var angle = (periods * Constants.k("spin_increase")) * (min + Math.random() * range);
            physics.setTargetRotation(angle + physics.getRotation());
        }

        this.render = function() {
            physics.draw(canvasSize()/gameWidth);
            container.scale.x = canvasSize()/gameWidth;
            container.scale.y = canvasSize()/gameWidth;
            renderer.render(stage);
        };

        function rotateCanvas(rotation) {
        }

        function pixiSetup() {
            preload();
            lastSpin = unixTime();
            lastSpawn = unixTime();
{'fraction_non_alphanumeric': 0.13246313753927969, 'fraction_numerical': 0.003948110547095319, 'mean_word_length': 1.5330612244897959, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '148042', 'n_tokens_mistral': 3360, 'n_tokens_neox': 3237, 'n_words': 595}