<commit_before>var jumpaudio = new Audio('http://skole.vibedrive.dk/assets/audio/jump.wav');
var deathaudio = new Audio('http://skole.vibedrive.dk/assets/audio/deatheffect.mp3');

var canvas,
    ctx,
    width,
    height,

    fgpos = 0,
    frames = 0,
    score = 0,
    best = 0,

    currentstate,
    states = {
        Splash: 0, Game: 1, Score: 2
    },

    okbtn,

    bird = {

        x: 60,
        y: 0,
        frame: 0,
        animation: [0, 1, 2, 1],
        rotation: 0,
        velocity: 0,
        radius: 12,
        gravity: 0.25,
        _jump: 4.6,

        jump: function() {
            this.velocity = -this._jump;
        },

        update: function(){
            var n = currentstate === states.Splash ? 10 : 5;
            this.frame += frames % n === 0 ? 1 : 0;
            this.frame %= this.animation.length;

            if(currentstate === states.Splash) {
                this.y = height - 280 + 5*Math.cos(frames/10);
                this.rotation = 0;
            } else {
                this.velocity += this.gravity;
                this.y += this.velocity;

                if(this.y >= height - s_fg.height-10) {
                    this.y = height - s_fg.height-10;
                    if(currentstate === states.Game) {
                        deathaudio.play();
                        currentstate = states.Score;
                    }
                    this.velocity = this._jump;

                }

                if (this.velocity >= this._jump) {
                    this.frame = 1;
                    this.rotation = Math.min(Math.PI/2, this.rotation + 0.3); // GOING UP

                } else {
                    this.rotation = -0.3; // GOING DOWN

                }
            }
        },

        draw: function(ctx){

            ctx.save();
            ctx.translate(this.x, this.y);
            ctx.rotate(this.rotation);

            var n = this.animation[this.frame];
            s_bird[n].draw(ctx, -s_bird[n].width/2, -s_bird[n].height/2);
            ctx.restore();

        }



    },

    pipes = {

        _pipes: [],

        reset: function() {
            this._pipes = [];
        },

        update: function(){
            if(frames % 100 === 0) {
                var _y = height - (s_pipeSouth.height+s_fg.height+120+200*Math.random());
                this._pipes.push({
                    x: 500,
                    y: _y,
                    width: s_pipeSouth.width,
                    height: s_pipeSouth.height
                });
            }
            for(var i = 0, len = this._pipes.length; i < len; i++) {
                var p = this._pipes[i];

                if(i === 0) {

                    score += p.x === bird.x ? 1 : 0;

                    var cx = Math.min(Math.max(bird.x, p.x), p.x+p.width);
                    var cy1 = Math.min(Math.max(bird.y, p.y), p.y+p.height);
                    var cy2 = Math.min(Math.max(bird.y, p.y+p.height+80), p.y+2*p.height+80);

                    var dx = bird.x - cx;
                    var dy1 = bird.y - cy1;
                    var dy2 = bird.y - cy2;

                    var d1 = dx*dx + dy1*dy1;
                    var d2 = dx*dx + dy2*dy2;

                    var r = bird.radius*bird.radius;

                    if(r > d1 || r > d2) {
                        currentstate = states.Score;
                    }
                }

                p.x -= 2;
                if(p.x < -50) {
                    this._pipes.splice(i, 1);
                    i--;
                    len--;
                }
            }
        },

        draw: function(){
            for(var i = 0, len = this._pipes.length; i < len; i++) {
                var p = this._pipes[i];
                s_pipeSouth.draw(ctx, p.x, p.y);
                s_pipeNorth.draw(ctx, p.x, p.y+80+p.height);
            }
        }



    };

function onpress(evt) {

    switch (currentstate) {
        case states.Splash:<commit_msg>Tilføjet audio til kollision med tubes<commit_after>var jumpaudio = new Audio('http://skole.vibedrive.dk/assets/audio/jump.wav');
var deathaudio = new Audio('http://skole.vibedrive.dk/assets/audio/deatheffect.mp3');

var canvas,
    ctx,
    width,
    height,

    fgpos = 0,
    frames = 0,
    score = 0,
    best = 0,

    currentstate,
    states = {
        Splash: 0, Game: 1, Score: 2
    },

    okbtn,

    bird = {

        x: 60,
        y: 0,
        frame: 0,
        animation: [0, 1, 2, 1],
        rotation: 0,
        velocity: 0,
        radius: 12,
        gravity: 0.25,
        _jump: 4.6,

        jump: function() {
            this.velocity = -this._jump;
        },

        update: function(){
            var n = currentstate === states.Splash ? 10 : 5;
            this.frame += frames % n === 0 ? 1 : 0;
            this.frame %= this.animation.length;

            if(currentstate === states.Splash) {
                this.y = height - 280 + 5*Math.cos(frames/10);
                this.rotation = 0;
            } else {
                this.velocity += this.gravity;
                this.y += this.velocity;

                if(this.y >= height - s_fg.height-10) {
                    this.y = height - s_fg.height-10;
                    if(currentstate === states.Game) {
                        deathaudio.play();
                        currentstate = states.Score;
                    }
                    this.velocity = this._jump;

                }

                if (this.velocity >= this._jump) {
                    this.frame = 1;
                    this.rotation = Math.min(Math.PI/2, this.rotation + 0.3); // GOING UP

                } else {
                    this.rotation = -0.3; // GOING DOWN

                }
            }
        },

        draw: function(ctx){

            ctx.save();
            ctx.translate(this.x, this.y);
            ctx.rotate(this.rotation);

            var n = this.animation[this.frame];
            s_bird[n].draw(ctx, -s_bird[n].width/2, -s_bird[n].height/2);
            ctx.restore();

        }



    },

    pipes = {

        _pipes: [],

        reset: function() {
            this._pipes = [];
        },

        update: function(){
            if(frames % 100 === 0) {
                var _y = height - (s_pipeSouth.height+s_fg.height+120+200*Math.random());
                this._pipes.push({
                    x: 500,
                    y: _y,
                    width: s_pipeSouth.width,
                    height: s_pipeSouth.height
                });
            }
            for(var i = 0, len = this._pipes.length; i < len; i++) {
                var p = this._pipes[i];

                if(i === 0) {

                    score += p.x === bird.x ? 1 : 0;

                    var cx = Math.min(Math.max(bird.x, p.x), p.x+p.width);
                    var cy1 = Math.min(Math.max(bird.y, p.y), p.y+p.height);
                    var cy2 = Math.min(Math.max(bird.y, p.y+p.height+80), p.y+2*p.height+80);

                    var dx = bird.x - cx;
                    var dy1 = bird.y - cy1;
                    var dy2 = bird.y - cy2;

                    var d1 = dx*dx + dy1*dy1;
                    var d2 = dx*dx + dy2*dy2;

                    var r = bird.radius*bird.radius;

                    if(r > d1 || r > d2) {
                        currentstate = states.Score;
                        deathaudio.play();
                    }
                }

                p.x -= 2;
                if(p.x < -50) {
                    this._pipes.splice(i, 1);
                    i--;
                    len--;
                }
            }
        },

        draw: function(){
            for(var i = 0, len = this._pipes.length; i < len; i++) {
                var p = this._pipes[i];
                s_pipeSouth.draw(ctx, p.x, p.y);
                s_pipeNorth.draw(ctx, p.x, p.y+80+p.height);
            }
        }



    };

function onpress(evt) {

    switch (currentstate) {
        case states.Splash:
{'fraction_non_alphanumeric': 0.1347305389221557, 'fraction_numerical': 0.023203592814371257, 'mean_word_length': 1.014321608040201, 'pattern_counts': {'":': 0, '<': 9, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6084068', 'n_tokens_mistral': 2705, 'n_tokens_neox': 2374, 'n_words': 495}