The developer has not uploaded a game yet...

//Hard Mode level. I promise, it's BEATABLE!!!

frameRate(40);

textAlign(CENTER, CENTER);

var s = 20;

var scroll = 0;

var pos = [s, s];

var velY = 0;

var grav = 9.81;

var speed = 5;

var jumping = false;

var jumpTimer = 0;

var fade = 255;

var fadeSpeed = 0;

var won = false;

var char =[['11111',

            '10001',

            '10101',

            '10001',

            '11111'],

            [[255, 0, 255]]];

var level = [

'111111111111111111111111111111',

'100150002200000000000001000001',

'110150022000011111111001001101',

'110112220000100000001001100101',

'133331200002000001001001200101',

'144441000010000010001001001101',

'102001001200000200010011002101',

'100001000000001000200021100101',

'120021110000010001000211200101',

'110011200000200010000221001101',

'133333121212000200000211002101',

'144444100100001000000221100101',

'133333100000010001111111200101',

'122100000000200021000001001101',

'122210000001000021001101002101',

'122220000010000021000101100101',

'122222000010000021100101200101',

'152222200110000021001001001101',

'111112222213333330014440000151',

'111111111111111111111111111111',

];

            

var mapEnds = [0, 0];

var obs = []; 

var keys = [];

var keyPressed = function(){

    keys[keyCode] = true;

    if (keys[32]){

        println('[');

        for (var i in level){

            println("'"+level[i]+"',\n");

        }

        println('];');

    }

};

var keyReleased = function(){keys[keyCode] = false;};

String.prototype.replaceAt=function(index, character){

    return this.substr(0, index) + character + this.substr(index+character.length);

};

var setObs = function(lvl){

    var t = lvl;

    mapEnds = [0, t[0].length*s-400];

    obs = [];

    var skip = 0;

    for (var y = 0; y<t.length; y++){

        for (var x = 0; x<t[y].length; x++){

            if (t[y][x]!=='0'){

                if (skip){

                    skip--;

                    continue;

                }

                var w = 0;

                while (t[y][x+w]===t[y][x]){

                    w++;

                }

                skip = w-1;

                obs.push([floor(t[y][x]),[x*s,y*s,w*s,s]]);

            }

        }

        skip = 0;

    }

};

var wall = function(x, y, w){

    if (dist(pos[0]+s/2, pos[1]+s/2, x+w/2, y)<w/2+s){

        //vertical collision

        if (pos[0]+s>x+speed&&pos[0]+speed<x+w){

            if (pos[1]+s>y&&pos[1]<y){

                pos[1] = y-s;

                velY = 0;

                jumping = false;

                jumpTimer = 5;

            } else if (pos[1]<y+s&&pos[1]+s/2>y+s){

                pos[1] = y+s;

                velY = 0;

            }

        }

        //horizontal collision

        if (pos[1]+s>y+velY&&pos[1]<y+s-1){

            if (pos[0]+s>x&&pos[0]<x){

                pos[0] = x-s;

            } else if (pos[0]<x+w&&pos[0]+s>x+w){

                pos[0] = x+w;

            }

        }

    }

}; 

var collide = function(x, y, w){

    if (dist(pos[0]+s/2, pos[1]+s/2, x+w/2, y)<w/2+5){

        if (pos[0]+s>x&&pos[0]<x+w&&pos[1]+s>y+abs(velY*2)&&pos[1]<y+s){

            return true;

        }

    }

};

var spikePatch = function(x, y, w){

    noStroke();

    var end = x+w;

    while(x<end){

        x+=s;

        triangle(x-s, y+s, x, y+s, x-s/2, y);

    }

    x-=w;

    if (collide(x, y, w)){

        fadeSpeed = -10;

    }

    //stroke(255, 255, 255, fade);

    //fill(255, 255, 255, 0);

    //rect(x, y, w, s);

};

var block = function(x, y, w){

    rect(x, y, w, s);

    wall(x, y, w, s);

};

var goal = function(x, y, w){

    rect(x, y, w, s);

    if (fade===255&&collide(x, y, w)){

        fadeSpeed = -10;

        won = true;

    }

};

var enemy1 = function(x, y, w){

    noStroke();

    var enemyX = x+sin(frameCount*120*(1/w))*((w-s)/2)+w/2;

    ellipse(enemyX, y+s/2, s, s);

    if (dist(enemyX, y+s/2, pos[0]+s/2, pos[1]+s/2)<s*0.9){

        fadeSpeed = -10;

    }

    stroke(255, 0, 255, fade);

    fill(255, 255, 255, 0);

    rect(x, y, w, s);

    noStroke();

};

var enemy2 = function(x, y, w){

    noStroke();

    var enemyX = x+sin(frameCount*120*(1/w)+180)*((w-s)/2)+w/2;

    ellipse(enemyX, y+s/2, s, s);

    if (dist(enemyX, y+s/2, pos[0]+s/2, pos[1]+s/2)<s*0.9){

        fadeSpeed = -10;

    }

    stroke(255, 0, 255, fade);

    fill(255, 255, 255, 0);

    rect(x, y, w, s);

    noStroke();

};

var funcsForObs = [block,spikePatch,enemy1,enemy2,goal];

var rainbowColor = function(i){

    return color(i%255, 255, 255, max(fade, 1));

};

var doObs = function(){

    noStroke();

    colorMode(HSB);

    for (var i = 0; i < obs.length; i++){

        var ob = obs[i][1];

        var x = ob[0]-scroll;

        if (x+ob[2]>0&&x<400){

            var obT = obs[i][0];

            fill(rainbowColor(ob[1]+obT*225+frameCount));

            funcsForObs[obT-1](x, ob[1], ob[2]);

        }

    }

    //colorMode(RGB);

};

var drawChar = function(){

    noStroke();

    var res = s/char[0].length;

    for (var i = 0; i<char[0].length; i++){

        for (var j = 0; j<char[0][i].length; j++){

            var num = round(char[0][i][j]);

            if (num){

                var col = char[1][num-1];

                fill(col[0], col[1], col[2], fade);

                rect(j*res+pos[0], i*res+pos[1], res, res);

            }

        }

    }

    //stroke(255, 255, 255, fade);

};

var moveChar = function(){

    if (keyIsPressed){

        if (keys[RIGHT]&&!keys[LEFT]){

            if (pos[0]+s>width*0.6&&scroll<mapEnds[1]){

                scroll+=speed;

            } else {

                pos[0]+=speed;

            }

        } else if (keys[LEFT]&&!keys[RIGHT]){

            if (pos[0]<width*0.4&&scroll>mapEnds[0]){

                scroll-=speed;

            } else {

                pos[0]-=speed;

            }

        }

        if (keys[UP]&&!jumping){

            velY = -speed;

            jumping = true;

        } else if (jumpTimer>0){

            jumpTimer--;

            if (jumpTimer<=0){jumping = true;}

        }

    }

    pos[1]+=velY;

    velY+=grav/30;

};

var doFadeAndMove = function(){

    fade+=fadeSpeed;

    if (fade<0&&won===false){

        fadeSpeed = 10;

        scroll = 0;

        pos = [s, s];

    } else if (fade >= 255){

        moveChar();

        fade = 255;

    } else if (fade<0){

        fill(-fade);

        textSize(50);

        text('You Won!', 200, 200);

        if (fade<-250){

            fadeSpeed = 10;

            scroll = 0;

            pos = [s, s];

        } else if (fadeSpeed === 10&&fade>-20){

            won = false;

        }

    }

};

setObs(level);

var draw = function() {

    background(0, 0, 0);

    doFadeAndMove();

    doObs();

    drawChar();

};

Leave a comment

Log in with itch.io to leave a comment.