JSFiddle - React, Tailwind, and code Playground

by Ozzy_liz12

HTML

<canvas id='c'></canvas>

CSS

* {
    overflow: hidden;
    margin: 0;
    padding: 0;
}

JavaScript

var ca = document.getElementById('c'),
    c = ca.getContext('2d'),
    width = window.innerWidth,
    height = window.innerHeight,
    key = {},
    level = 0;
var borderRatio = 2 / 3;

function calcUnitVector(point1, point2) {
    var x1,
        x2,
        y1,
        y2;
    x1 = point1[0];
    y1 = point1[1];
    x2 = point2[0];
    y2 = point2[1];
    var magnitude = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
    return [(x2 - x1) / magnitude, (y2 - y1) / magnitude];
}

function bounceFix(livingObject, springblock) {
    if (springblock.loc[0] + 1 < world[level].boxes[springblock.loc[1]].length || springblock.loc[0] - 1 >= 0) { // if the spring is: not the sides,
        if ((world[level].boxes[springblock.loc[1]][springblock.loc[0] + 1].type !== 'air' && colCheck(livingObject, world[level].boxes[springblock.loc[1]][springblock.loc[0] + 1]) === 'b') || (world[level].boxes[springblock.loc[1]][springblock.loc[0] - 1].type !== 'air' && colCheck(livingObject, world[level].boxes[springblock.loc[1]][springblock.loc[0] - 1]) === 'b')) { // next to more spring, and that spring is touching the object's bottom
            return false; // object is ignored by this block, let them out
        } else {
            return true; // else object isn't ignored
        }
    }
}

function objectIsNotSafeFromLava(livingObject, lavablock) {
    if (lavablock.loc[1] + 1 < world[level].boxes.length) { // if the lava is: not the bottom,
        if ((world[level].boxes[lavablock.loc[1] + 1][lavablock.loc[0]].type === 'spring' || world[level].boxes[lavablock.loc[1] + 1][lavablock.loc[0]].type === 'brick' || world[level].boxes[lavablock.loc[1] + 1][lavablock.loc[0]].type === 'checkpoint') && colCheck(livingObject, world[level].boxes[lavablock.loc[1] + 1][lavablock.loc[0]]) !== null) { // next to not lava, and that not lava is touching the object
            return false; // object is safe here, let them out
        } else {
            // else object might be ded...