<commit_before>function init(){
    var gameData = [];
    var images = [
        'fork.svg',
        'dumpling.svg',
        ];
    var count = 0;
    var dataLoader = function(){
        if (++count >= images.length){
            gameStart(gameData);
        }
    }
    images.forEach(function(item){
        var datum = new Image();
        gameData.push(datum);
        datum.addEventListener('load', dataLoader);
        datum.src = item;
    });
}

function clsSprite(ctx, img, x, y){
    this.ctx = ctx;
    this.img = img;
    if (x && y) {
        this.x = x;
        this.y = y;
    }
    else {
        this.x = 0;
        this.y = 0;
    }
    this.draw = function(){
        this.ctx.drawImage(this.img, this.x, this.y);
    } 
    this.move = function(x, y){
        this.x = x;
        this.y = y;
    }
    this.collision = (x, y) => x > this.x && x < this.x + this.img.naturalWidth && y > this.y && y < this.y + this.img.naturalHeight;
}

function gameStart(gameData){
    var canvas = document.getElementById('main');
    canvas.width  = window.innerWidth;
    canvas.height = window.innerHeight;
    var ctx = canvas.getContext('2d');
    var dumplings = [];
    for (i = 0; i < 6; i++){
        dumplings.push(new clsSprite (ctx, gameData[1], 300 + i * 100, 300));
    }
    var fork = new clsSprite (ctx, gameData[0], 0, 0);
    fork.taken = false;
    canvas.addEventListener('click', function takeFork(ev){
        if (fork.collision(ev.clientX, ev.clientY))
        {
            fork.taken = true;
            canvas.style.cursor = 'none';
            canvas.removeEventListener('click', takeFork);
        }
    });
    canvas.addEventListener('mousemove', function(ev){
        if (fork.taken){
            fork.move(ev.clientX, ev.clientY);
        }
    });
    dumplings.forEach(function(d){d.draw()});
    fork.move(100, 100);
    fork.draw();
    var anim = function(){
        if (fork.taken){
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            dumplings.forEach(function(d){d.draw()});
            fork.draw();
        }
        window.requestAnimationFrame(anim);
    }
    anim();<commit_msg>added poking dumplings with fork<commit_after>function init(){
    var gameData = [];
    var images = [
        'fork.svg',
        'dumpling.svg',
        ];
    var count = 0;
    var dataLoader = function(){
        if (++count >= images.length){
            gameStart(gameData);
        }
    }
    // TODO for/in loop
    images.forEach(function(item){
        var datum = new Image();
        gameData.push(datum);
        datum.addEventListener('load', dataLoader);
        datum.src = item;
    });
}

function clsSprite(ctx, img, x, y){
    this.ctx = ctx;
    this.img = img;
    if (x && y) {
        this.x = x;
        this.y = y;
    }
    else {
        this.x = 0;
        this.y = 0;
    }
    this.draw = function(){
        this.ctx.drawImage(this.img, this.x, this.y);
    } 
    this.move = function(x, y){
        this.x = x;
        this.y = y;
    }
    this.collision = (x, y) => x > this.x && x < this.x + this.img.naturalWidth && y > this.y && y < this.y + this.img.naturalHeight;
}

function gameStart(gameData){
    var canvas = document.getElementById('main');
    canvas.width  = window.innerWidth;
    canvas.height = window.innerHeight;
    var ctx = canvas.getContext('2d');
    var dumplings = [];
    for (i = 0; i < 6; i++){
        dumplings.push(new clsSprite (ctx, gameData[1], 300 + i * 100, 300));
    }
    var fork = new clsSprite (ctx, gameData[0], 0, 0);
    fork.taken = false;
    canvas.addEventListener('click', function takeFork(ev){
        if (fork.collision(ev.clientX, ev.clientY))
        {
            fork.taken = true;
            canvas.style.cursor = 'none';
            canvas.addEventListener('mousemove', function(ev){
                // TODO fix high load here
                fork.move(ev.clientX, ev.clientY);
            });
            canvas.removeEventListener('click', takeFork);
            canvas.addEventListener('click', takeDumpling);
        }
    });
    function takeDumpling(ev){
        var dumpling;
        for (d in dumplings){
            dumpling = dumplings[d];
            if (dumpling.collision(ev.clientX, ev.clientY)){
                canvas.removeEventListener('click', takeDumpling);
                canvas.addEventListener('mousemove',
                        function moveDumpling(ev){
                            dumpling.move(ev.clientX, ev.clientY);
                        }
                );
                break;
            }
        }
    };
    dumplings.forEach(function(d){d.draw()});
    fork.move(100, 100);
    fork.draw();
    var anim = function(){
        if (fork.taken){
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            dumplings.forEach(function(d){d.draw()});
            fork.draw();
        }
        window.requestAnimationFrame(anim);
    }
    anim();
{'fraction_non_alphanumeric': 0.15001009489198466, 'fraction_numerical': 0.010902483343428226, 'mean_word_length': 1.8373424971363115, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4747017', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1558, 'n_words': 326}