<commit_before>define(['phaser', 'const', 'config'], function(Phaser, Const, Config) {
    var state = new Phaser.State();
    var player;
    var collisionLayer;
    var pickupsLayer;
    var cursors;
    var speed = Config.playerSpeed;
    var currentTile;
    var direction = Phaser.DOWN;
    var threshold = 3;
    state.create = function() {
        state.game.stage.backgroundColor = 0xFFFFFF;
        var map = state.add.tilemap('test');
        map.addTilesetImage('test-tiles', 'tiles');
        collisionLayer = map.createLayer('collision');
        map.setCollision(1, true, collisionLayer);
        pickupsLayer = map.createLayer('pickups');
        player = state.add.sprite(Const.TILE_SIZE * 1.5,
            Const.TILE_SIZE * 1.5, 'badman');
        state.physics.arcade.enable(player);
        player.anchor.set(0.5); // removing this causes weird placement...

        cursors = state.input.keyboard.createCursorKeys();
        currentTile = new Phaser.Point();
    };
    state.update = function() {
        // allow reversing direction any time
        if (cursors.up.isDown && direction === Phaser.DOWN) direction = Phaser.UP;
        if (cursors.down.isDown && direction === Phaser.UP) direction = Phaser.DOWN;
        if (cursors.left.isDown && direction === Phaser.RIGHT) direction = Phaser.LEFT;
        if (cursors.right.isDown && direction === Phaser.LEFT) direction = Phaser.RIGHT;
        // allow turning if at intersection...
        if (state.math.fuzzyEqual(player.x, currentTile.x + Const.TILE_SIZE / 2, threshold) &&
            state.math.fuzzyEqual(player.y, currentTile.y + Const.TILE_SIZE / 2, threshold)) {
            // ...and target tile is open
            // this is just a horrible proof-of-concept
            var newDirection = null;
            if (cursors.up.isDown) newDirection = Phaser.UP;
            if (cursors.down.isDown) newDirection = Phaser.DOWN;
            if (cursors.left.isDown) newDirection = Phaser.LEFT;
            if (cursors.right.isDown) newDirection = Phaser.RIGHT;
            // if player turned, rectify position to currentTile
            var turned = false;
            if (direction === Phaser.UP && (newDirection === Phaser.LEFT || newDirection === Phaser.RIGHT)) turned = true;
            if (direction === Phaser.DOWN && (newDirection === Phaser.LEFT || newDirection === Phaser.RIGHT)) turned = true;
            if (direction === Phaser.LEFT && (newDirection === Phaser.UP || newDirection === Phaser.DOWN)) turned = true;
            if (direction === Phaser.RIGHT && (newDirection === Phaser.UP || newDirection === Phaser.DOWN)) turned = true;
            if (turned) {
                player.x = currentTile.x + Const.TILE_SIZE / 2;
                player.y = currentTile.y + Const.TILE_SIZE / 2;
                player.body.reset(player.x, player.y);
            }
            if (newDirection)
                direction = newDirection;
        }
        // move player in correct direction
        player.body.velocity.set(0);
        switch (direction) {
            case Phaser.UP:
                player.body.velocity.y = -speed;
                break;
            case Phaser.DOWN:
                player.body.velocity.y = speed;<commit_msg>Prevent turning into walls.<commit_after>define(['phaser', 'const', 'config'], function(Phaser, Const, Config) {
    var state = new Phaser.State();
    var player;
    var map;
    var collisionLayer;
    var pickupsLayer;
    var cursors;
    var speed = Config.playerSpeed;
    var currentTile;
    var direction = Phaser.DOWN;
    var threshold = 3;
    state.create = function() {
        state.game.stage.backgroundColor = 0xFFFFFF;
        map = state.add.tilemap('test');
        map.addTilesetImage('test-tiles', 'tiles');
        collisionLayer = map.createLayer('collision');
        map.setCollision(1, true, collisionLayer);
        pickupsLayer = map.createLayer('pickups');
        player = state.add.sprite(Const.TILE_SIZE * 1.5,
            Const.TILE_SIZE * 1.5, 'badman');
        state.physics.arcade.enable(player);
        player.anchor.set(0.5); // removing this causes weird placement...

        cursors = state.input.keyboard.createCursorKeys();
        currentTile = new Phaser.Point();
    };
    state.update = function() {
        // allow reversing direction any time
        if (cursors.up.isDown && direction === Phaser.DOWN) direction = Phaser.UP;
        if (cursors.down.isDown && direction === Phaser.UP) direction = Phaser.DOWN;
        if (cursors.left.isDown && direction === Phaser.RIGHT) direction = Phaser.LEFT;
        if (cursors.right.isDown && direction === Phaser.LEFT) direction = Phaser.RIGHT;
        // allow turning if at intersection...
        if (state.math.fuzzyEqual(player.x, currentTile.x + Const.TILE_SIZE / 2, threshold) &&
            state.math.fuzzyEqual(player.y, currentTile.y + Const.TILE_SIZE / 2, threshold)) {
            // ...and target tile is open
            if (cursors.up.isDown && map.getTileAbove(map.getLayerIndex('collision'), currentTile.x / 32, currentTile.y / 32).isInteresting(true)) return;
            if (cursors.down.isDown && map.getTileBelow(map.getLayerIndex('collision'), currentTile.x / 32, currentTile.y / 32).isInteresting(true)) return;
            if (cursors.left.isDown && map.getTileLeft(map.getLayerIndex('collision'), currentTile.x / 32, currentTile.y / 32).isInteresting(true)) return;
            if (cursors.right.isDown && map.getTileRight(map.getLayerIndex('collision'), currentTile.x / 32, currentTile.y / 32).isInteresting(true)) return;
            // this is just a horrible proof-of-concept
            var newDirection = null;
            if (cursors.up.isDown) newDirection = Phaser.UP;
            if (cursors.down.isDown) newDirection = Phaser.DOWN;
            if (cursors.left.isDown) newDirection = Phaser.LEFT;
            if (cursors.right.isDown) newDirection = Phaser.RIGHT;
            // if player turned, rectify position to currentTile
            var turned = false;
            if (direction === Phaser.UP && (newDirection === Phaser.LEFT || newDirection === Phaser.RIGHT)) turned = true;
            if (direction === Phaser.DOWN && (newDirection === Phaser.LEFT || newDirection === Phaser.RIGHT)) turned = true;
            if (direction === Phaser.LEFT && (newDirection === Phaser.UP || newDirection === Phaser.DOWN)) turned = true;
            if (direction === Phaser.RIGHT && (newDirection === Phaser.UP || newDirection === Phaser.DOWN)) turned = true;
            if (turned) {
                player.x = currentTile.x + Const.TILE_SIZE / 2;
                player.y = currentTile.y + Const.TILE_SIZE / 2;
                player.body.reset(player.x, player.y);
            }
            if (newDirection)
                direction = newDirection;
        }
        // move player in correct direction
        player.body.velocity.set(0);
        switch (direction) {
            case Phaser.UP:
                player.body.velocity.y = -speed;
                break;
            case Phaser.DOWN:
                player.body.velocity.y = speed;
{'fraction_non_alphanumeric': 0.13014757554462403, 'fraction_numerical': 0.0061841180604357, 'mean_word_length': 2.285318559556787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2310737', 'n_tokens_mistral': 2089, 'n_tokens_neox': 1995, 'n_words': 473}