<commit_before>function draw(){
    if(game_running){
        frames += 1;

        /*if new obstacle should be added this frame, add one*/
        if(frames%frames_per_obstacle === 0){
            i = random_number(30) + 40;
            obstacles.splice(
                0,
                0,
                [
                    width + i,
                    y + (random_number(500) - 250),
                    i,
                    random_number(30) + 40
                ]
            )
        }

        /*if obstacle frequency increase should happen this frame, do it*/
        if(settings[4] > 0 && frames_per_obstacle > 1 && frames%settings[4] === 0){
            /*obstacle frequency increase*/
            frames_per_obstacle -= 1
        }

        /*if the player has activated jetpack, increase y speed and add smoke*/
        if(key_jetpack){
            player_speed += settings[2];/*jetpack power*/
            smoke.splice(
                0,
                0,
                [-20,player_y - 10]
            )

        /*else apply gravity*/
        }else{
            player_speed -= settings[1]/*gravity*/
        }

        player_y += player_speed
    }

    if(settings[8]){/*clear?*/
        buffer.clearRect(
            0,
            0,
            width,
            height
        )
    }

    /*draw corridor over grey background*/
    buffer.fillStyle = '#000';
    buffer.fillRect(
        0,
        y - 250,
        width,
        500
    );

    /*draw player body*/
    buffer.fillStyle = '#fff';
    buffer.fillRect(
        x,
        y - player_y - 25,
        25,
        50
    );

    /*draw jetpack*/
    buffer.fillStyle = '#aaa';
    buffer.fillRect(
        x - 25,
        y - player_y - 15,
        25,
        20
    );

    /*draw activated jetpack fire*/
    if(game_running && key_jetpack){
        buffer.fillStyle = '#f00';
        buffer.fillRect(
            x - 22,
            y - player_y + 5,
            18,
            10
        )
    }

    /*check if player is outside of game boundaries*/
    if(player_y + 25 > 250 || player_y - 25 < -250){
        game_running = 0;
        update_best()
    }

    i = obstacles.length - 1;
    if(i >= 0){
        j = y - player_y;

        do{
            /*delete obstacles that are past left side of screen*/
            if(obstacles[i][0] < 0){
                obstacles.splice(i,1)
            }else if(game_running){
                /*move obstacles left*/
                obstacles[i][0] -= 10;

                /*check for player collision with obstacle*/
                if(obstacles[i][0] >= x - 25 - obstacles[i][2] / 2 &&
                   obstacles[i][0] <= x + 25 + obstacles[i][2] / 2 &&
                   obstacles[i][1] >= j - 25 - obstacles[i][3] / 2 &&
                   obstacles[i][1] <= j + 25 + obstacles[i][3] / 2){
                    game_running = 0;
                    update_best()
                }
            }
        }while(i--);

        /*draw obstacles*/
        i = obstacles.length - 1;
        if(i >= 0){
            buffer.fillStyle = '#555';
            do{
                buffer.fillRect(
                    obstacles[i][0] - obstacles[i][2] / 2,
                    obstacles[i][1] - obstacles[i][3] / 2,
                    obstacles[i][2],
                    obstacles[i][3]
                )
            }while(i--)
        }
    }

    i = smoke.length-1;
    if(i >= 0){
        /*delete smoke trails past left side of screen, else move left*/
        do{
            if(smoke[i][0] < -x){
                smoke.splice(i,1)
            }else if(game_running){
                smoke[i][0] -= 10
            }
        }while(i--);

        /*draw smoke trails behind the player*/
        i = smoke.length - 1;
        if(i >= 0){
            buffer.fillStyle = '#777';
            do{
                buffer.fillRect(
                    x + smoke[i][0],
                    y - smoke[i][1],
                    10,
                    10
                )
            }while(i--)
        }
    }

    /*setup text display*/
    buffer.font = '23pt sans-serif';
    buffer.textAlign = 'center';
    buffer.textBaseline = 'top';
    buffer.fillStyle = '#afa';

    /*if game is over, display game over messages*/
    if(!game_running){
        if(!played_explosion_sound){
            if(settings[5] > 0){/*audio volume*/
                /*play explode sound*/
            }
            played_explosion_sound = 1
        }
        i = y / 2;
        if(frames > best_display){
            buffer.fillText(
                'NEW BEST SCORE!',
                x,
                i - 60
            )
        }
        buffer.fillText(
            'You crashed... ☹',
            x,
            i
        );
        buffer.fillText(
            settings[7] + '=Restart',/*restart key*/
            x,
            i + 60
        );
        buffer.fillText(
            'ESC=Main Menu',
            x,
            i+120
        )<commit_msg>improved obstacle/smoke handling<commit_after>function draw(){
    if(game_running){
        frames += 1;

        /*if new obstacle should be added this frame, add one*/
        if(frames % frames_per_obstacle === 0){
            i = random_number(30) + 40;
            obstacles.splice(
                0,
                0,
                [
                    x + i,
                    random_number(500) - 250,
                    i,
                    random_number(30) + 40
                ]
            )
        }

        /*if obstacle frequency increase should happen this frame, do it*/
        if(settings[4] > 0 && frames_per_obstacle > 1 && frames % settings[4] === 0){
            /*obstacle frequency increase*/
            frames_per_obstacle -= 1
        }

        /*if the player has activated jetpack, increase y speed and add smoke*/
        if(key_jetpack){
            player_speed += settings[2];/*jetpack power*/
            smoke.splice(
                0,
                0,
                [
                    -20,
                    player_y - 10
                ]
            )

        /*else apply gravity*/
        }else{
            player_speed -= settings[1]/*gravity*/
        }

        player_y += player_speed
    }

    if(settings[8]){/*clear?*/
        buffer.clearRect(
            0,
            0,
            width,
            height
        )
    }

    /*draw corridor over grey background*/
    buffer.fillStyle = '#000';
    buffer.fillRect(
        0,
        y - 250,
        width,
        500
    );

    /*draw player body*/
    buffer.fillStyle = '#fff';
    buffer.fillRect(
        x,
        y - player_y - 25,
        25,
        50
    );

    /*draw jetpack*/
    buffer.fillStyle = '#aaa';
    buffer.fillRect(
        x - 25,
        y - player_y - 15,
        25,
        20
    );

    /*draw activated jetpack fire*/
    if(game_running && key_jetpack){
        buffer.fillStyle = '#f00';
        buffer.fillRect(
            x - 22,
            y - player_y + 5,
            18,
            10
        )
    }

    /*check if player is outside of game boundaries*/
    if(player_y + 25 > 250 || player_y - 25 < -250){
        game_running = 0;
        update_best()
    }

    i = obstacles.length - 1;
    if(i >= 0){
        if(game_running){
            do{
                /*delete obstacles that are past left side of screen*/
                if(obstacles[i][0] < -x){
                    obstacles.splice(i,1)
                }else{
                    /*move obstacles left*/
                    obstacles[i][0] -= 10;

                    /*check for player collision with obstacle*/
                    if(obstacles[i][0] >= -25 - obstacles[i][2] / 2 &&
                       obstacles[i][0] <=  25 + obstacles[i][2] / 2 &&
                       obstacles[i][1] >= -player_y - 25 - obstacles[i][3] / 2 &&
                       obstacles[i][1] <= -player_y + 25 + obstacles[i][3] / 2){
                        game_running = 0;
                        update_best()
                    }
                }
            }while(i--);

            /*get new amount of obstacles, some may have been spliced*/
            i = obstacles.length - 1
        }

        /*draw obstacles*/
        if(i >= 0){
            buffer.fillStyle = '#555';
            do{
                buffer.fillRect(
                    x + obstacles[i][0] - obstacles[i][2] / 2,
                    y + obstacles[i][1] - obstacles[i][3] / 2,
                    obstacles[i][2],
                    obstacles[i][3]
                )
            }while(i--)
        }
    }

    i = smoke.length-1;
    if(i >= 0){
        if(game_running){
            /*delete smoke trails past left side of screen, else move left*/
            do{
                if(smoke[i][0] < -x){
                    smoke.splice(i,1)
                }else if(game_running){
                    smoke[i][0] -= 10
                }
            }while(i--);

            /*get new amount of smoke, some may have been spliced*/
            i = smoke.length - 1
        }

        /*draw smoke trails behind the player*/
        if(i >= 0){
            buffer.fillStyle = '#777';
            do{
                buffer.fillRect(
                    x + smoke[i][0],
                    y - smoke[i][1],
                    10,
                    10
                )
            }while(i--)
        }
    }

    /*setup text display*/
    buffer.font = '23pt sans-serif';
    buffer.textAlign = 'center';
    buffer.textBaseline = 'top';
    buffer.fillStyle = '#afa';

    /*if game is over, display game over messages*/
    if(!game_running){
        if(!played_explosion_sound){
            if(settings[5] > 0){/*audio volume*/
                /*play explode sound*/
            }
            played_explosion_sound = 1
        }

        i = y / 2;
        if(frames > best_display){
            buffer.fillText(
                'NEW BEST SCORE!',
                x,
                i - 60
            )
        }
        buffer.fillText(
            'You crashed... ☹',
            x,
            i
        );
        buffer.fillText(
            settings[7] + '=Restart',/*restart key*/
            x,
            i + 60
        );
        buffer.fillText(
            'ESC=Main Menu',
            x,
            i+120
        )
{'fraction_non_alphanumeric': 0.12150164060992086, 'fraction_numerical': 0.029434472109631345, 'mean_word_length': 1.019290724863601, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, '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': '2161764', 'n_tokens_mistral': 3245, 'n_tokens_neox': 2907, 'n_words': 704}